Public | Automated Build

Last pushed: a year ago
Short Description
This repository provides an easy-to-use standalone container for running behat tests manually
Full Description


This repository provides an easy-to-use standalone container for running
behat tests manually within Drupal 7.


  • behat 3.0 / mink 1.5
  • selenium 2.48.2
  • firefox 31
  • x11vnc

This container is built from the phase2/devtools-build container so contains
all of the tools, such as php, available there.


docker pull phase2/behat


To run behat, we assume you already have a proper source directory containing
your Drupal docroot which contains your behat tests within some subdirectory.

Typically your behat tests directory will have one or more .yml files for
your behat configuration, and a "features" folder containing all of your
.feature test files.

You will also need a separate docker container that contains the database
instance for your Drupal site.


Set up your behat.yml configuration file to point to your Drupal root and host:

        features: 'features'
        - FeatureContext
        - Drupal\DrupalExtension\Context\DrupalContext
        - Drupal\DrupalExtension\Context\MinkContext
        - Drupal\DrupalExtension\Context\MarkupContext
        - Drupal\DrupalExtension\Context\DrushContext
      goutte: ~
      selenium2: ~
      default_session: 'selenium2'
      base_url: BASE_URL (e.g. http://www.drupal.vm)
      files_path: LOCATION_OF_TESTS (e.g. '/data/docroot/sites/all/modules/my_tests'
      api_driver: 'drupal'
      blackbox: ~
        alias: self
        drupal_root: DRUPAL_DOCROOT (e.g. "/data/docroot")

You probably already have this in your existing behat.yml file. The specific
lines to pay attention to here are "base_url", "files_path", "drupal_root".
Those lines will need to be customized for your specific project.

Note: The /data directory will come from a local mount point specified when
you run the docker container.


To actually run the docker container to execute a behat test manually, use

docker run -it --rm --link DATABASE_CONTAINER:db \
  -v $(pwd):/data:rw phase2/behat

DATABASE_CONTAINER : the name of your running DB container
LOCATION_OF_TESTS : the same as the "files_path" in your behat.yml file
CONFIG_FILENAME : the name of the behat.yml file you want to use
(relative to the LOCATION_OF_TESTS directory).

The first part of the line is running docker interactively as a shell.
The --rm option ensures the container is cleaned up when you exit it.
The --link creates a link between the behat container and your existing Drupal
database conteiner. The TESTS environment variable defines the directory that
contains the behat tests and is used as the default starting directory when you
run the container. The CONFIG environment variable is used when running behat
to specify the behat configuration yml file. The -v is used to mount your
current directory $(pwd) into the /data directory within the docker container.
Finally, phase2/behat is the name of the image you are running.

If you want to mount a local directory other than the current folder, just
replace $(pwd) with the full directory path. NOTE: This path MUST be within
your /Users path on your local Mac.

Once docker is running, you will be in the TESTS directory and can simply run
your behat test using:

behat features/TEST_NAME.feature

which will run the individual "TEST_NAME.feature" test.

A vnc server is running within the container which allows you to watch the
behat test being run via a vnc client. Mac OSX has a VNC client built into
the Screen Share system. You can easily access this using Safari by entering
the vnc://IP_ADDRESS:5900 link that is displayed on the screen when you first
run your docker container. Then you will see each step of your test so you
can debug how it might be failing.

Standalone mode

Instead of getting a shell to issue behat commands, you can also execute your
behat command directly via the docker "run" command. Just add the behat
command to the end of the run command. For example:

docker run -it --rm --link DATABASE_CONTAINER:db \
  -v $(pwd):/data:rw phase2/behat \
  behat features/TEST_NAME.feature


If you need adapt the project to your needs, clone, modify the Dockerfile
or files and from the source directory, run:

docker build -t phase2/behat .

This command is included in the script.

Docker Pull Command
Source Repository

Comments (0)