Skip to content

Behat for Drupal

This composer plugin prepares your Drupal project for Behat tests.

Requirements

The plugin works with any composer based Drupal project and can be added to such projects with composer require lakedrops/behat4drupal. It's recommended to also use the Docker4Drupal plugin (added with composer require lakedrops/docker4drupal) which will provide all the Docker containers for your development environment as well as those for Selenium and Chrome.

If your project is based on either Drupal 8 Project Template or Drupal 9 Project Template, then everything is already included for you automatically.

Usage

You will find links to further documentation on how to write Behat tests at the end of this file. Here we simply describe on how you can run your tests once they have been defined.

Command line

The easiest way to run Behat tests is to use the prepared Ahoy commands. Just call a behat to get a list of all available commands. In the background, they call the same commands that are described in detail in the following paragraphs.

You need to execute Behat inside the PHP Docker container. From the root of your project you can launch the containers with docker-compose up -d and then enter the PHP container with docker-compose exec --user root php sh.

Inside the container you'll be located at /var/www/html and in that directory you can run the Behat test suite with the command vendor/bin/behat --no-interaction --config /var/www/html/tests/behat/behat.yml

PhpStorm

In any of the JetBrains IDEs you can call the Behat tests directly from the UI when preparing the project in 2 steps beforehand:

  • Configure the PHP CLI interpreter: Go to the project settings in Languages & Frameworks > PHP and configure the remote PHP interpreter for Docker similar to this screenshot
  • Configure the Run/Debug Configuration: Simply select Behat and of you go, see this second screenshot

For more details we recommend the following links: