Running Canopy in Docker container

In this article you will see how to write and run Canopy tests inside of Docker Container.

January 27, 2020 - 3 minute read -
F# Automated Tests TDD Tests Docker


I struggle a little bit with running Canopy inside a docker container. So I thought it would be great to document how to achieve it in a separate post. I have following code which is responsible for downloading a whole page by going to it.

let fetchHtml (city) =
    startChrome ()

    url ""
    waitFor search
    ".city" << city
    click "#Type"
    click "Nieruchomość"
    click ".button_next_active"

    let page = browser.PageSource
    quit ()


The startChrome method looks as follows:

let private search () =
    (elements ".city").Length > 0

let private startChrome () =
    let chromeOptions = ChromeOptions()
    let chromeNoSandbox = ChromeWithOptions(chromeOptions)
    start chromeNoSandbox

As you may see I don’t use HeadlessChrome instead of it I use standard chrome and pass arguments to it to use a headless mode and no-sandbox. Which are needed.

module Auctions =
    let get =
        configuration.chromeDir <- AppDomain.CurrentDomain.BaseDirectory


That’s all from a code perspective, but I need to do some adjustments so the canopy would be run inside of a docker. To make it happen I have to do the following things:

  • copy chrome driver in a server.fsproj to output folder;
<Content Include="chromedriver.exe">
<Content Include="chromedriver">
  • install chrome in a docker image.

RUN apt-get update && apt-get install -y gnupg2 && apt-get install -y wget

RUN wget -q -O - | apt-key add - \
      && sh -c 'echo "deb [arch=amd64] stable main" >> /etc/apt/sources.list.d/google.list' \
      && apt-get update \
      && apt-get install xvfb unzip google-chrome-stable -y \
      && wget$CHROME_DRIVER_VERSION/ \
      && unzip -d /usr/local/bin

This article in short illustrates how to run canopy inside of docker container. You could check-out my repository the get the fully working example of above.