Testing with Docker

Tests written with Cybernaut can be run on Docker. This has the advantage of being able to run them independently of the environment and under reproducible conditions.

Installation

Only Docker has to be installed. No further dependencies are required.

Docker containers

Cybernaut provides two fully configured Docker containers which can be found on Docker Hub:

Each Docker tag corresponds to the same tag or version of cybernaut on npm.

Note: Both Docker containers are built with the latest stable browser version available at the time of construction. For technical reasons, Firefox ESR is currently used.

Getting started

To get started, copy your test files into the /opt/cybernaut-tests directory within the Docker container:

COPY example.e2e.js /opt/cybernaut-tests/example.e2e.js

or mount the directory containing your test files as a data volume:

docker run -it --rm \
  -v "$(pwd)"/tests:/opt/cybernaut-tests \
  clebert/cybernaut-firefox:latest

The default configuration can be overridden in the same way:

COPY config.json /opt/cybernaut-config/config.json
docker run -it --rm \
  -v "$(pwd)"/config:/opt/cybernaut-config \
  -v "$(pwd)"/tests:/opt/cybernaut-tests \
  clebert/cybernaut-firefox:latest

The default configuration for Chrome:

{
  "capabilities": {
    "browserName": "chrome",
    "chromeOptions": {
      "args": [
        "--disable-gpu",
        "--no-sandbox"
      ]
    }
  }
}

and for Firefox:

{
  "capabilities": {
    "browserName": "firefox"
  }
}

In addition, a default CMD instruction is configured to specify the virtual screen resolution and the reporter:

CMD ["1280x720", "spec"]

Note: tap-mocha-reporter is used to format the TAP output. Here is a list of all available reporters.

You can override it with your own CMD instruction or with CLI arguments for docker run:

docker run -it --rm \
  -v "$(pwd)"/tests:/opt/cybernaut-tests \
  clebert/cybernaut-firefox:latest \
  1920x1080 dot

Note: When executing docker run for an image with chrome browser please add -v /dev/shm:/dev/shm volume mount to use the host's shared memory. Since a Docker container is not meant to preserve state and spawning a new one takes less than 3 seconds you will likely want to remove containers after each test with --rm command.

Docker Compose

You can also run Cybernaut tests by using Docker Compose.

Note: In order to use this, an additional dependency, docker-compose is required.

Run it by using docker-compose:

docker-compose up

To get started with Cybernaut and Docker Compose there is a simple docker-compose.yml as a starting point.

Troubleshooting

To enable debug output, you can set the DEBUG='cybernaut:*' environment variable:

docker run -it --rm \
  -e DEBUG='cybernaut:*' \
  -v "$(pwd)"/tests:/opt/cybernaut-tests \
  clebert/cybernaut-firefox:latest

results matching ""

    No results matching ""