Skip to main content

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 dblog module 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, When or Then keyword. 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=l in 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​

NameTraitDescription
Batch APIDrupal\BatchTraitWait for Drupal's Batch API to finish.
BigPipeDrupal\BigPipeTraitWait for Drupal BigPipe placeholders to be replaced on JavaScript scenarios.
BlocksDrupal\BlockTraitManage Drupal blocks.
Caches and cronDrupal\CacheTraitInvalidate Drupal caches and run cron from within a scenario.
Config overridesDrupal\ConfigOverrideTraitDisable Drupal config overrides from settings.php during a scenario.
ConfigurationDrupal\ConfigTraitAssert and set stored Drupal configuration values with automatic revert.
ContentDrupal\ContentTraitManage Drupal content with workflow and moderation support.
Content blocksDrupal\ContentBlockTraitManage Drupal content blocks.
DraggableViewsDrupal\DraggableviewsTraitOrder items in the Drupal Draggable Views.
DrushDrupal\DrushTraitRun Drush commands and assert their output.
ECK entitiesDrupal\EckTraitManage Drupal ECK entities of an existing entity type and bundle.
EmailDrupal\EmailTraitTest Drupal email functionality with content verification.
EntitiesDrupal\EntityTraitCreate entities of a type that has no dedicated trait.
FilesDrupal\FileTraitManage Drupal file entities with upload and storage operations.
LanguagesDrupal\LanguageTraitCreate the languages a scenario needs.
MediaDrupal\MediaTraitManage Drupal media entities with type-specific field handling.
MenusDrupal\MenuTraitManage Drupal menus and menu links.
ModulesDrupal\ModuleTraitEnable and disable Drupal modules with automatic state restoration.
ParagraphsDrupal\ParagraphsTraitManage Drupal paragraphs entities with structured field data.
QueuesDrupal\QueueTraitManage and assert Drupal queue state.
RedirectsDrupal\RedirectTraitManage Drupal redirect entities provided by the contrib redirect module.
Search APIDrupal\SearchApiTraitRun Drupal Search API indexing and cron hooks.
State APIDrupal\StateTraitManage and assert Drupal State API values with automatic revert.
System timeDrupal\TimeTraitControl system time in tests using Drupal state overrides.
TaxonomyDrupal\TaxonomyTraitManage Drupal taxonomy terms with vocabulary organization.
TestmodeDrupal\TestmodeTraitConfigure Drupal Testmode module for controlled testing scenarios.
UsersDrupal\UserTraitManage Drupal users with role and permission assignments.
WatchdogDrupal\WatchdogTraitAssert Drupal does not trigger PHP errors during scenarios using Watchdog.
WebformsDrupal\WebformTraitManage Drupal webforms.