Skip to main content

For any website and every Drupal site

The Behat steps you need, already written.

Behat Steps is a library of 449 tested steps for pages, forms, APIs and Drupal sites. Write readable scenarios on day one, and build steps of your own on the same helpers when you need them.

Feature: Drafts  Scenario: Editor previews a draft    Given the following "page" content exists:      | title    | status |      | About us | 0      |    And I am logged in as a user with the role "editor"    When I visit the "page" content page with the title "About us"    Then I should see the heading "About us"    And the "page" content with the title "About us" should not be published

1 scenario (1 passed)5 steps (5 passed)

Drupal steps create the page and the editor, check what the editor sees, and delete both after the scenario.

Install with Composer

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

Needs PHP 8.3 or newer. Composer installs Behat and Mink with it.

Steps, each with an example
449
Traits for web and Drupal
57
Helpers for steps of your own
323
Released since
2018

Works with

  • Behat 3.33+
  • Behat 4
  • Mink
  • BrowserKit
  • Selenium
  • Chrome DevTools
  • Drupal 11
  • Drupal 12
  • Drush
  • PHP 8.3
  • PHP 8.4
  • PHP 8.5

What you get

Steps and helpers for the whole suite

Every step comes with an example, and every helper with its signature and a summary, in references generated from the code.

Web steps

28 traits for pages, forms, links, cookies, JSON, XML and REST APIs, on any website.

Drupal steps

29 traits for content, users, media, menus, email, queues, caches and config.

Backends by capability

A step names the capability it needs, so clearing caches runs in-process or through Drush.

Browser drivers

BrowserKit for plain HTTP, and Selenium or Chrome DevTools for @javascript scenarios.

How it fits together

From a line of Gherkin to your site

Each line of a scenario goes through the same 3 layers, so a step you write yourself can call the same helpers as the shipped ones.

  1. Scenario

    Your feature file, in Gherkin, written with the step text the library ships.

  2. Step

    A step trait on your context matches the line and passes its arguments to a helper.

  3. Helper

    A named method does the work, and your own steps can call it too.

  4. Backend

    The browser session, or the first backend in your list that can do the job, such as Drupal or Drush.

Built to be trusted

Why teams pick Behat Steps

Tested against itself

Every step runs in the library's own suite on a real Drupal site, and the suite tests the failures as well as the passes.

Steps that read alike

Every step follows the same wording rules, so the next trait you pick up reads like the last one.

No clashes with your code

Every method starts with the name of its trait, such as cookieGetAll(), so none collides with a method of your context.

Get going

Up and running in 3 steps

  1. Install the package

    Add it to your project's dev dependencies. A few steps need 1 more package, which Installation lists.

    composer require --dev drevops/behat-steps:^4
  2. Register a context

    Add WebContext, or DrupalContext for a Drupal site, and the extension to your behat.php. See the whole file.

  3. Run a scenario

    Write a scenario with the shipped steps, then run Behat.

    vendor/bin/behat

Write scenarios your whole team can read.

Free and open source, and tested on every change against Drupal 11 and 12 on Behat 3.33+ and 4.

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