Skip to main content

Web steps

Web steps work on any website, whatever it's built with. They visit pages, fill in and submit forms, follow links and read cookies and response headers. They also check JSON, XML and tables, all through the browser Mink drives. WebContext brings every one of them, and DrupalContext extends WebContext, so a FeatureContext built on either already has them all. Contexts explains which one to extend.

The steps come grouped into traits, 1 per job, such as cookies, form fields or JSON responses. The table at the end of this page lists every trait and what it covers, and each name opens the trait's page.

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.
  • 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.

A few steps need a real browser, because they run the page's JavaScript, press keys or resize the window. They fail under the BrowserKit session the quick start sets up, and Browsers covers the browsers that run them.

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 Drupal steps on 1 page. It ships with the package, so an AI coding agent in your project can read it from vendor/.

Every web trait​

NameTraitDescription
AccessibilityAccessibilityTraitAssess accessibility of rendered pages.
Basic authenticationBasicAuthTraitKeep HTTP basic authentication applied across session resets.
CookiesCookieTraitVerify and inspect browser cookies.
Dropzone uploadsDropzoneTraitSimulate a real multi-file drag-and-drop gesture onto a Dropzone target.
ElementsElementTraitInteract with HTML elements using CSS selectors and DOM attributes.
Failure diagnosticsDiagnosticsTraitAppend on-failure diagnostics to the failure message of any failed step.
File downloadsFileDownloadTraitTest file download functionality with content verification.
Form fieldsFieldTraitManipulate form fields and verify widget functionality.
IframesIframeTraitSwitch between iframes and the root document.
JavaScript errorsJavascriptTraitAutomatically detect JavaScript errors during test execution.
JSON responsesJsonTraitAssert JSON responses with path and schema checks.
KeyboardKeyboardTraitSimulate keyboard interactions in the browser.
LinksLinkTraitVerify link elements with attribute and content assertions.
Mapped valuesMappingTraitReplace {{ Key }} tokens in step arguments and table cells.
MessagesMessageTraitAssert status, error, warning and success messages rendered on the page.
Meta tagsMetatagTraitAssert <meta> tags and head/SEO markup in page markup.
ModalsModalTraitInteract with and assert modals.
Page regionsRegionTraitInteract with and assert against named page regions.
PathsPathTraitNavigate and verify paths with URL validation.
Random valuesRandomTraitReplace random-value tokens in step arguments and table cells.
Relative datesDateTraitConvert relative date expressions into timestamps or formatted dates.
Response headersResponseTraitVerify HTTP response headers.
Responsive layoutsResponsiveTraitTest responsive layouts with viewport control.
REST APIsRestTraitTest REST APIs with lightweight steps.
Shell commandsCommandTraitRun local shell commands and assert on their result.
TablesTableTraitInteract with HTML table elements and assert their content.
WaitsWaitTraitWait for a period of time or for AJAX to finish.
XML responsesXmlTraitAssert XML responses with element and attribute checks.