Drupal steps
Drupal steps only mean something on a Drupal site. They create content, users, terms and media, clear caches and run cron and queues. They also check the emails the site sends and the errors it logs. DrupalContext brings every one of them, on top of the web steps it inherits from WebContext. So on a Drupal site, your FeatureContext extends DrupalContext and has both, as Contexts explains.
The steps come grouped into traits, 1 per job, such as content, users or the State API. The table at the end of this page lists every trait and what it covers, and each name opens the trait's page.
What they need from your site
Most Drupal steps work on the site directly instead of through its pages: creating a user, for instance, doesn't fill in the registration form. They reach the site through a backend, either Drupal itself, loaded into the test run, or Drush. The drupal_root setting from the quick start is all most sites need, and Key concepts explains backends.
Traits for contrib modules, such as Webform, Search API or Redirect, cost nothing on a site without the module. A trait like that looks for its module only when one of its steps runs, and that step fails with a message naming the module.
How a trait's page reads
The page opens with the trait's class and its links: the source, the feature file that tests it and its helpers in HELPERS.md. A description of what the trait does follows. Then, where the trait has them:
- Prerequisites: what the site has to provide before the trait's steps can run, such as the core
dblogmodule that Watchdog reads. - Options: the settings the trait reads, with their defaults and the tags that change them for 1 scenario. Configure a trait shows where to set them.
- Steps: every step of the trait, each under its
Given,WhenorThenkeyword. Open a step to see what it does and an example you can copy into a scenario.
Find a step
You can find a step in 3 ways:
- Search the site with the box at the top of the page.
- Run
vendor/bin/behat --definitions=lin your project. It lists every step your suite registers, Mink's and your own included. - Open STEPS.md, which holds these steps and the web steps on 1 page. It ships with the package, so an AI coding agent in your project can read it from
vendor/.
Every Drupal trait
| Name | Trait | Description |
|---|---|---|
| Batch API | Drupal\BatchTrait | Wait for Drupal's Batch API to finish. |
| BigPipe | Drupal\BigPipeTrait | Wait for Drupal BigPipe placeholders to be replaced on JavaScript scenarios. |
| Blocks | Drupal\BlockTrait | Manage Drupal blocks. |
| Caches and cron | Drupal\CacheTrait | Invalidate Drupal caches and run cron from within a scenario. |
| Config overrides | Drupal\ConfigOverrideTrait | Disable Drupal config overrides from settings.php during a scenario. |
| Configuration | Drupal\ConfigTrait | Assert and set stored Drupal configuration values with automatic revert. |
| Content | Drupal\ContentTrait | Manage Drupal content with workflow and moderation support. |
| Content blocks | Drupal\ContentBlockTrait | Manage Drupal content blocks. |
| DraggableViews | Drupal\DraggableviewsTrait | Order items in the Drupal Draggable Views. |
| Drush | Drupal\DrushTrait | Run Drush commands and assert their output. |
| ECK entities | Drupal\EckTrait | Manage Drupal ECK entities of an existing entity type and bundle. |
Drupal\EmailTrait | Test Drupal email functionality with content verification. | |
| Entities | Drupal\EntityTrait | Create entities of a type that has no dedicated trait. |
| Files | Drupal\FileTrait | Manage Drupal file entities with upload and storage operations. |
| Languages | Drupal\LanguageTrait | Create the languages a scenario needs. |
| Media | Drupal\MediaTrait | Manage Drupal media entities with type-specific field handling. |
| Menus | Drupal\MenuTrait | Manage Drupal menus and menu links. |
| Modules | Drupal\ModuleTrait | Enable and disable Drupal modules with automatic state restoration. |
| Paragraphs | Drupal\ParagraphsTrait | Manage Drupal paragraphs entities with structured field data. |
| Queues | Drupal\QueueTrait | Manage and assert Drupal queue state. |
| Redirects | Drupal\RedirectTrait | Manage Drupal redirect entities provided by the contrib redirect module. |
| Search API | Drupal\SearchApiTrait | Run Drupal Search API indexing and cron hooks. |
| State API | Drupal\StateTrait | Manage and assert Drupal State API values with automatic revert. |
| System time | Drupal\TimeTrait | Control system time in tests using Drupal state overrides. |
| Taxonomy | Drupal\TaxonomyTrait | Manage Drupal taxonomy terms with vocabulary organization. |
| Testmode | Drupal\TestmodeTrait | Configure Drupal Testmode module for controlled testing scenarios. |
| Users | Drupal\UserTrait | Manage Drupal users with role and permission assignments. |
| Watchdog | Drupal\WatchdogTrait | Assert Drupal does not trigger PHP errors during scenarios using Watchdog. |
| Webforms | Drupal\WebformTrait | Manage Drupal webforms. |