Drupal Extension, Drupal Driver and Behat Steps, now a single library for Behat 4 and Drupal 12.
How we got here
New to Behat?
Behat is a PHP tool for behaviour-driven development. You describe how your site should behave, in plain English, and Behat checks that it does.
Developers, testers and clients read the same file.
Mink drives a fast HTTP client, or a real browser when the page needs JavaScript.
In CI, a broken journey fails the build before it reaches your visitors.
New to Behat?
Feature names what the site doesScenario is 1 example of itGiven sets up, When acts, Then checksAnd continues the line beforeEach line under a scenario is a step.
Feature: News articles Editors publish news for visitors. Scenario: Editor publishes an article Given I am logged in as a user with the role "editor" When I visit "/node/add/article" And I fill in "Title" with "Melbourne meetup" And I press "Save" Then I should see the success message "Saved"
New to Behat?
Behat matches each step to a PHP method by its pattern, then runs the method.
Behat Steps is that code, already written and tested.
# The step in your feature file When I visit "/" // The step definition Behat runs for it #[When('I visit :path')] public function pathVisit(string $path): void { $this->getSession()->visit($this->locatePath($path)); } // :path captures "/", and Mink opens the page
Behat Steps today
Steps, each with an example
pages, forms, APIs, Drupal
Traits: 28 for any website, 29 for Drupal
grouped by job
Public helpers for your own steps
HELPERS.md
Open source since
on GitHub
Behat Steps 4.0.0
Drupal 12 ready
Tested on both, with the contrib modules a real site uses.
Move to Behat 4 at your own pace, ahead of Drupal 12.
Drupal 12 runs on PHP 8.5 and Symfony 8.
Drupal 12 needs Symfony 8, and Behat 4 is the Behat release that accepts it.
1 package
The steps, the Behat extension and the backends that reach Drupal now live in 1 package.
1 install, 1 version, 1 test matrix.
Behat Steps 3.14 Behat Steps 4.0 drevops/behat-steps ──┐ │ drevops/behat-steps drupal/drupal-extension ─┼──► steps │ contexts drupal/drupal-driver ──┘ Behat extension backends
Architecture
Each layer depends only on the layers below it.
behat.php and sets each scenario's backend order.Architecture
So 1 step runs in-process, over Drush or on a backend of your own.
They use no Behat or Mink code, so they work outside a test run too.
A site that isn't Drupal extends WebContext and gets only the steps it can use.
A linter fails any code that depends on a layer above it.
Architecture
Clearing caches, creating content, running cron. A backend provides a job by implementing its interface.
35 capabilities: 11 any backend may provide, 24 only a Drupal backend.
// The job interface CacheCapabilityInterface { public function cacheClear(): void; public function cacheClearBin(string $bin): void; // and 3 more } // The step asks for the job #[Given('the cache has been cleared')] public function cacheClearAll(): void { $this->backendFor(CacheCapabilityInterface::class) ->cacheClear(); }
Architecture
A step asks for the job it needs done. The first backend in your list that can do it, runs it.
Architecture
@backend:drush moves Drush to the front for 1 scenario. The steps stay the same.
A backend starts only when a step first needs it, and your own backend serves the shipped steps.
// behat.php: the order to try 'backends' => ['drupal', 'drush', 'blackbox'], # features/cron.feature @backend:drush Scenario: The home page loads after cron Given the cache has been cleared When cron runs And I visit "/" Then the response status code should be 200
Architecture
Drupal Extension picked 1 driver for a whole scenario, with the @api tag. In 4.0, each step finds a backend for its own job.
Your scenarios describe the site. Your behat.php decides how to reach it.
Consistent language
All 458 steps follow the same 19 wording rules.
When I press the button "Save"When cron runsin the region "header"A linter checks 13 of the rules in CI, so every new step follows them too.
Consistent language
Drupal Extension and Behat Steps 3
I am logged in as a user with the "editor" role I should see "Welcome" in the "header" region Given I run cron
Behat Steps 4
I am logged in as a user with the role "editor" I should see the text "Welcome" in the region "header" When cron runs
Many steps keep their text, including Mink's own, such as I fill in and I press.
Your own steps
Extend DrupalContext and every step is there. Your steps call the same 337 helpers.
Every public helper is listed in HELPERS.md, which ships with the package.
use Behat\Step\Given; use DrevOps\BehatSteps\DrupalContext; class FeatureContext extends DrupalContext { #[Given('a draft news article exists')] public function newsDraftExists(): void { $this->contentCreate('article', [ 'title' => 'Melbourne meetup', 'status' => 0, ]); } }
AI coding agents
Describe a step in plain English, and your agent writes it on the public helpers.
# Ships in the package. Link it for Claude Code: mkdir -p .claude/skills ln -s ../../vendor/drevops/behat-steps/skills/create-behat-step \ .claude/skills/create-behat-step # Then describe the step you need: /create-behat-step a Then step that checks that the page with a title is authored by a user
API testing
REST, JSON and XML steps run apart from the browser's cookies and page.
A header can take its value from the last response, so a token flow runs on the shipped steps.
Scenario: Call the API with a token When I send a REST "GET" request to "/api/token" And the REST header "Authorization" has the value from the JSON path "$.access_token" with the prefix "Bearer " And I send a REST "GET" request to "/api/resource" Then the JSON path "$.items" should exist
Built-in checks
A scenario that logs a PHP error fails, read from Drupal's dblog.
A scenario can fail on a JavaScript error in the browser.
the page should pass accessibility checks, with a threshold per scenario.
After each scenario, the entities its steps created are deleted in reverse creation order.
Quality
CI jobs: Drupal 11 and 12, PHP 8.3 to 8.5, Behat 3 and 4
Selenium and headless Chrome
Line coverage, on every file
unit, kernel and Behat
Every step has a scenario of its own that tests it.
Why 1 package
Drupal 12 support went in as 1 change, 2 weeks into the 4.x branch.
1 package to install. 1 release to get a fix.
Upgrading
MIGRATION.md maps every renamed step, class, setting and tag.
The migrate-behat-steps skill applies it with your AI coding agent, then runs your suite to check.
# Replace the 2 packages with 1 composer remove --dev drupal/drupal-extension composer require --dev drevops/behat-steps:^4 # Then, in your Behat configuration # - BehatStepsExtension replaces DrupalExtension # - drop @api and @drush from your features
Upgrading
Move to Behat Steps 4.
Stay on Behat Steps 3 and Drupal Extension 6, and move with your Drupal 11 upgrade.
Drupal Extension 6 and Drupal Driver 3 get security fixes until 1 July 2027.
Get involved
Both receive security fixes until 1 July 2027. If you'd like to carry them forward, say so on the issues.
github.com/jhedstrom/drupalextension/issues/882
github.com/jhedstrom/DrupalDriver/issues/400
Try it
Quick start, every step with an example, configuration, architecture and the migration guide.
behat-steps.drevops.com
composer require --dev drevops/behat-steps:^4
Alex Skrypnyk
DrevOps · behat-steps.drevops.com