drupal / drupal-extension
Drupal extension for Behat
Package info
github.com/jhedstrom/drupalextension
Type:behat-extension
pkg:composer/drupal/drupal-extension
Fund package maintenance!
Requires
- php: >=8.2
- behat/behat: ^3.22
- behat/gherkin: ^4.13
- behat/mink: ^1.12
- behat/mink-browserkit-driver: ^2.1.0
- drupal/drupal-driver: ^2.4
- friends-of-behat/mink-extension: ^2.7.1
- lullabot/mink-selenium2-driver: ^1.7
- symfony/css-selector: ^6.4.3 || ^7
- symfony/dom-crawler: ^6.4.3 || ^7
- symfony/http-client: ^6.4.3 || ^7
- webflo/drupal-finder: ^1.3.1
Requires (Dev)
- composer/installers: ^2.3
- dantleech/gherkin-lint: ^0.2.3
- drevops/behat-screenshot: ^2.2
- drevops/phpcs-standard: ^0.6.2
- drupal/coder: ^8.3.27
- drupal/core: ^11
- drupal/core-composer-scaffold: ^11
- drush/drush: ^12.5.2 || ^13.7
- ergebnis/composer-normalize: ^2.50
- grasmash/yaml-cli: ^3.2.1
- guzzlehttp/guzzle: ^7.8.2
- guzzlehttp/promises: ^2.0.3
- guzzlehttp/psr7: ^2.6.3
- justinrainbow/json-schema: ^5.3
- league/container: ^4.2
- masterminds/html5: ^2.8
- php-parallel-lint/php-parallel-lint: ^1.4
- phpspec/phpspec: ^7.0 || ^8.0
- phpstan/phpstan: ^2.1
- rector/rector: ^2.0
- symfony/browser-kit: ^6.4.3 || ^7
- symfony/config: ^6.4.3 || ^7
- symfony/console: ^6.4.3 || ^7
- symfony/dependency-injection: ^6.4.3 || ^7
- symfony/event-dispatcher: ^6.4.3 || ^7
- symfony/event-dispatcher-contracts: ^3.4.2
- symfony/filesystem: ^6.4.3 || ^7
- symfony/http-kernel: ^6.4.3 || ^7
- symfony/mime: ^6.4.3 || ^7
- symfony/routing: ^6.4.3 || ^7
- symfony/translation-contracts: ^3.4.2
- symfony/var-exporter: ^6.4.3 || ^7
- symfony/yaml: ^6.4.3 || ^7
- webmozart/assert: ^2
- dev-main
- v5.2.1
- v5.2.0
- 5.1.x-dev
- v5.1.0
- 5.0.x-dev
- v5.0.0
- v5.0.0rc1
- v5.0.0alpha1
- 4.2.x-dev
- v4.2.1
- 4.1.x-dev
- v4.1.0
- 4.0.x-dev
- v4.0.1
- v4.0.0
- v4.0.0rc1
- v4.0.0beta2
- v4.0.0beta1
- v4.0.0alpha4
- v4.0.0alpha3
- v4.0.0alpha2
- v4.0.0alpha1
- 3.4.x-dev
- v3.4.1
- v3.4.0
- 3.3.x-dev
- v3.3.1
- v3.3.0
- 3.2.x-dev
- v3.2.3
- v3.2.2
- v3.2.1
- v3.2.0
- 3.1.x-dev
- v3.1.5
- v3.1.4
- v3.1.3
- v3.1.2
- v3.1.1
- 3.1.0
- 3.0.x-dev
- v3.0.13
- v3.0.12
- v3.0.11
- v3.0.10
- v3.0.9
- v3.0.8
- v3.0.7
- v3.0.6
- v3.0.5
- 3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- 1.0.x-dev
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- dev-feature/360-error-invalid-fields
- dev-feature/658-finder-exception
- dev-feature/670-skip-role-reuse
- dev-feature/179-reset-request-time
- dev-feature/676-fix-step-def
- dev-feature/650-fix-d10-tests
- dev-feature/598-remove-flash
- dev-feature/remove-deprecations
- dev-feature/switch-coding-standards
- dev-feature/738-increase-coverage-part2
- dev-feature/add-negative-test-coverage-harness
- dev-feature/738-increase-context-coverage-part2
- dev-feature/add-tests-managers
- dev-feature/increase-coverage-mink
- dev-feature/fix-coverage-merge
- dev-feature/reconcile-static-assets
- dev-feature/increase-coverage-drupal-driver-manager
- dev-feature/reconcile-feature-contexts
- dev-feature/remove-regex-step
- dev-feature/add-step-examples
- dev-feature/ai-instructions
- dev-feature/steps-docs-generator
- dev-feature/738-post-coverage-comment
- dev-feature/738-test-coverage-part2
- dev-feature/738-test-coverage
- dev-feature/fix-callable-type
- dev-feature/fix-comments-indent
- dev-feature/update-changelog-5.2
- dev-feature/simplify-feature-context
- dev-feature/update-tests
- dev-feature/add-phpstan-rector
- dev-feature/add-behat-screenshot
- dev-feature/fix-cs-spec
- dev-feature/update-readme
- dev-feature/move-build-artifact
- dev-feature/update-config-files
- dev-488-backend-authentication
- dev-prep-4.0
- dev-string-handlers
- dev-490-simplify-testing
- dev-tmp-driver-test
- dev-259-follow-up
- dev-eliza411-patch-1
- dev-fix-drush-endpoint-tests-again
- dev-fix-drush-endpoint-tests
- dev-fix-blackbox-tests
- dev-fix-d8
This package is auto-updated.
Last update: 2026-03-16 05:08:22 UTC
README
Behat Drupal Extension
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.
Use it for testing your Drupal site.
If you're new to the Drupal Extension, we recommend starting with the Full documentation
Quick start
-
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.
Available steps
| 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. |
Writing tests with AI assistants
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
Credits
- Originally developed by Jonathan Hedstrom with great help from eliza411
- Maintainers
Additional resources
Examples and code snippets
- 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
Release notes
See CHANGELOG.
Contributing
Features and bug fixes are welcome!
See CONTRIBUTING.md for more information.