Collection of steps for Behat

Fund package maintenance!


Behat steps logo

A collection of Behat steps for Drupal

GitHub Issues GitHub Pull Requests CircleCI codecov GitHub release (latest by date) LICENSE Renovate

Total Downloads


composer require --dev drevops/behat-steps:^2


Add required traits to your FeatureContext.php (example):


use Drupal\DrupalExtension\Context\DrupalContext;
use DrevOps\BehatSteps\ContentTrait;

 * Defines application features from the specific context.
class FeatureContext extends DrupalContext {

  use ContentTrait;


Modification of behat.yml configuration is not required.


  • \Exception is thrown for all assertions.
  • \RuntimeException is thrown for any unfulfilled requirements within a step.

Available steps

Use behat -d l to list all available step definitions.

There are also several pre- and post-scenario hooks that perform data alterations and cleanup.

Skipping before scenario hooks

Some traits provide beforeScenario hook implementations. These can be disabled by adding behat-steps-skip:METHOD_NAME tag to your test.

For example, to skip beforeScenario hook from JsTrait, add @behat-steps-skip:jsBeforeScenarioInit tag to the feature.


Local environment setup

Use ahoy --help to see the list of available commands.

Apple Silicon adjustments

cp docker-compose.override.default.yml docker-compose.override.yml

Running tests

The source code of traits is tested by running Behat tests in the same way they would be run in your project: traits are included into FeatureContext.php and then ran on the pre-configured fixture Drupal site using test features.

Run ahoy build to setup a fixture Drupal site in the build directory.

ahoy test-bdd                # Run all tests

ahoy test-bdd path/to/file   # Run all scenarios in specific feature file

ahoy test-bdd -- --tags=wip  # Run all scenarios tagged with `@wip` tag

Debugging tests

  • ahoy debug
  • Set breakpoint
  • Run tests with ahoy test-bdd - your IDE will pickup an incoming debug connection

Updating fixture site

  • Build the fixture site and make the required changes
  • ahoy drush cex -y
  • ahoy update-fixtures to copy configuration changes from build directory to the fixtures directory

Repository created using https://getscaffold.dev/ project scaffold template