Sign inSign up

phase2/behat

By phase2

•Updated over 10 years ago

This repository provides an easy-to-use standalone container for running behat tests manually

Image
0

467

phase2/behat repository overview

⁠phase2/behat

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

Includes:

  • 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.

⁠Install

docker pull phase2/behat

⁠Requirements

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.

⁠Configuration

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

default:
  suites:
    default:
      paths:
        features: 'features'
      contexts:
        - FeatureContext
        - Drupal\DrupalExtension\Context\DrupalContext
        - Drupal\DrupalExtension\Context\MinkContext
        - Drupal\DrupalExtension\Context\MarkupContext
        - Drupal\DrupalExtension\Context\DrushContext
  extensions:
    Behat\MinkExtension:
      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'
    Drupal\DrupalExtension:
      api_driver: 'drupal'
      blackbox: ~
      drush:
        alias: self
      drupal:
        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.

⁠Usage

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

docker run -it --rm --link DATABASE_CONTAINER:db \
  -e "TESTS=LOCATION_OF_TESTS" \
  -e "CONFIG=CONFIG_FILENAME" \
  -v $(pwd):/data:rw phase2/behat

where 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 \
  -e "TESTS=LOCATION_OF_TESTS" \
  -e "CONFIG=CONFIG_FILENAME" \
  -v $(pwd):/data:rw phase2/behat \
  behat features/TEST_NAME.feature

⁠Build

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

docker build -t phase2/behat .

This command is included in the build.sh script.

Tag summary

Content type

Image

Digest

Size

460.1 MB

Last updated

over 10 years ago

docker pull phase2/behat