The Drupal Extension is an integration layer between Behat, Mink Extension, and Drupal. It provides step definitions for common testing scenarios specific to Drupal sites.
If you're new to the Drupal Extension, we recommend starting with the Full documentation
-
Install using Composer:
composer require --dev drupal/drupal-extension
-
Create a file called
behat.ymlwith a minimal configuration. For more information on configuration options, see Full documentationdefault: autoload: ['%paths.base%/tests/bootstrap'] suites: default: paths: ['%paths.base%/tests/features'] contexts: - Drupal\DrupalExtension\Context\DrupalContext extensions: Drupal\MinkExtension: browserkit_http: ~ base_url: http://example.org/ # Replace with your site's URL Drupal\DrupalExtension: blackbox: ~
-
Initialize Behat in your project:
vendor/bin/behat --init
-
Find pre-defined steps to work with using:
vendor/bin/behat -di
-
Optionally, define your own steps in
tests/bootstrap/FeatureContext.php -
Start adding your feature files to the
tests/featuresdirectory of your repository.
| Class | Description |
|---|---|
| BatchContext | Extensions to the Mink Extension. |
| ConfigContext | Provides pre-built step definitions for interacting with Drupal config. |
| DrupalContext | Provides pre-built step definitions for interacting with Drupal. |
| DrushContext | Provides step definitions for interacting directly with Drush commands. |
| MailContext | Provides pre-built step definitions for interacting with mail. |
| MarkupContext | Extensions to the Mink Extension. |
| MessageContext | Provides step-definitions for interacting with Drupal messages. |
| MinkContext | Extensions to the Mink Extension. |
Copy and paste below into your project's CLAUDE.md or AGENTS.md file.
## Writing Behat Tests
Available step definitions are listed in `STEPS.md`.
Read this file before writing or modifying Behat tests.
Use only step patterns from this file. Do not invent steps.
If `STEPS.md` does not exist or is outdated, regenerate it:
vendor/bin/behat -di > STEPS.md
Regenerate after adding new Context classes or updating dependencies.
For detailed step documentation, see: vendor/drupal/drupal-extension/STEPS.md
- Originally developed by Jonathan Hedstrom with great help from eliza411
- Maintainers
- Complex node creation, with field collections and entity references
- Achievements module support
- Drupal form element visibility
- Track down PHP notices
- Support for sites using basic HTTP authentication
See CHANGELOG.
Features and bug fixes are welcome!
See CONTRIBUTING.md for more information.
