atlassian / docker-chromium-xvfb

Docker image for running browser tests against headless Chromium
MIT License
398 stars 125 forks source link

Chromium in Docker via Xvfb

This Docker image provides a way to run a real Chromium / Chrome browser headless inside of a Docker container. If you're looking for a way to run your Karma or Python Selenium tests against Chrome using Docker, this is the project you've been looking for! Use cases include:

Images

Methodology

The key to this project and to getting Chromium / Google Chrome to work inside of a container is the wrapper script, xvfb-chromium.

The wrapper script does a number of things:

  1. Launches the X virtual frame buffer (Xvfb) which emulates an X11 display so that the GUI code in the browser has a display to interact with.
  2. Launches Chromium / Google Chrome and passes along any command line arguments to the browser process.
  3. Traps SIGTERM and relays the signal to the browser and Xvfb so that they will not continue to run once the test runner is finished. This is mostly required to deal with Karma's insistence that the browser process be terminated before it can exit. Without this relaying, Karma would hang indefinitely.

Directories

Running the sample applications

  1. cd into any of the projects in /samples
  2. docker build -t sample .
  3. docker run sample

The sample application will run the example test and output its results to the console as well as a xunit-format XML file in the test-results/ directory inside of the container.