Skip to content

Playwright BDD Step Reference

Paulo Gomes da Cruz Junior edited this page Dec 3, 2026 · 2 revisions

Playwright BDD Step Reference

This page lists the Gherkin steps registered by the e2e runner. Steps are grouped by category. Copy them exactly; only the quoted values change.

Step definitions live in e2e/playwright/steps/*.steps.ts. A definition declares its variables as {string} or {int} placeholders, which is why every text value in a feature file is wrapped in double quotes.

Steps work with Given, When, Then, And, or But. The keyword does not change the implementation.

Variables

Kind Meaning Example
Input Data to type, select, or assert "James", "/search"
Field name Visible label of a form control "First name", "Client type"

Field names must match the label on screen, including case.

Navigation and API setup

Step Variables What it does
I visit {input} Path Opens a path and waits for the app shell
the client filter for {string} should be visible Client number Asserts the client filter chip
the reporting unit API for {string} returns the {string} district average unit Reporting unit id, coast or interior grade Stubs the reporting-unit response
the block details API for {string} returns the {string} block ruId/blockId, legacy or draft state Stubs the block-details response
the reporting unit API for {string} returns no grade Reporting unit id Removes grade from a real response

I visit uses a document navigation, so the runner waits for #root to fill. The rate-limit guard inserts a gap before the load.

Text and tabs

Step Variables What it does
I can read {input} Visible text Asserts text is visible; opens /search first if the page is blank
I cannot see {input} Absent text Asserts no matching text exists
I wait for the text {input} to appear Expected text Waits for text to become visible
I wait for the text {input} to appear after {input} Text, response URL fragment Waits for a response, then asserts text
the {input} tab should be selected Tab name Asserts aria-selected="true"

The response fragment in the fourth step replaces the old Cypress intercept alias. Use part of the request URL, for example /api/search.

Buttons and controls

Step Variables What it does
I click on the {input} button Button name or label Clicks a button or link with the ordered locator probe
I click on the {input} link Link name Clicks a link
I search — Clicks Search and waits for results
I select the client {string} Client number Selects a client from the header panel
I select the district {string} District name Selects a district from the header panel
I select no client — Clears the client selection
no client should be selected — Asserts no client is selected
I close the profile panel — Closes the header profile panel
I click on the theme toggle — Switches light and dark mode
the theme toggle should offer {input} mode Target mode Asserts the toggle's accessible label
the app is in light mode — Puts the app in light mode before a check
the profile settings button should show {string} Action label Asserts the profile menu label

Button lookup tries data-testid, aria-label, visible text, submit values, and Carbon icon-only buttons before falling back to role-based locators.

Inputs

Step Variables What it does
I type {input} into the {input} input Text, field label Types with key events so debounce and Carbon comboboxes behave
I clear the {input} input Field label Clears and blurs the field
the {input} input should contain {input} Field label, value Asserts the field value
I type {input} into the {input} autocomplete Text, field label Waits for /api/search/reporting-units-users, then picks the match
I select {input} from the {input} dropdown Option, field label Opens a Carbon dropdown and selects an option
I toggle the {input} switch on Switch label Turns a switch on
I toggle the {input} switch off Switch label Turns a switch off
no switch should be visible — Asserts there are no switches on the page

Input lookup resolves labels through the associated <label>, id, name, data-testid, placeholder, aria-label, and Carbon containers.

Accessibility and keyboard navigation

These steps use axe-playwright for scans and Playwright keyboard events for focus checks.

Step Variables What it does
the page should have no accessibility violations — Scans the whole page with axe
the {input} region should have no accessibility violations Region name or selector Scans one region
I press {input} {input} times Key, count Sends repeated key presses
the {input} input should be focused Field label Asserts focus
the skip link should target an existing main landmark — Checks the skip-link target
I activate the skip link with the keyboard — Activates the skip link
focus should be on the main landmark — Asserts the main landmark has focus
the clients page controls should be keyboard focusable — Checks keyboard reachability of clients-page controls
the page should have at least one ARIA live region — Asserts a live region exists
the {input} live region should announce {input} Region, text Checks a specific live region
the screen reader announcement should include {input} Text Searches all live regions
the page should announce itself on load as {input} Text Checks title, heading, or landmark label
the {input} region should have a valid heading hierarchy Region Checks for skipped heading levels
the focus order should be {input} Comma-separated labels Checks Tab order
the {input} input should be announced as {input} Identifier, accessible name Checks an input's accessible name
the error message {input} should be announced Error text Checks role=alert and live regions

Region names main, header, footer, navigation/nav, and form map to selectors. CSS selectors, aria-label values, data-testid, and role=region labels also work.

Lighthouse and UX quality

These steps run only in the dedicated lighthouse project, in Chromium, against the authenticated page. Tag scenarios @chromeOnly when you narrow a run with PW_FEATURES.

Step Variables What it does
the lighthouse score should be at least: Two-column table of category and minimum Audits the page and asserts each category threshold
the lighthouse metric {string} should be at most {string} Metric alias, maximum value Asserts a metric against a maximum
the UX quality score should be acceptable — Applies the standard category and metric thresholds

Metric aliases include ttfb, lcp, fcp, cls, and tbt. Category names include performance, accessibility, best-practices, and seo.

@loginAsBCeID @chromeOnly
Scenario: Lighthouse category thresholds from table
  Given I visit "/search"
  Then the lighthouse score should be at least:
    | performance    | 75 |
    | accessibility  | 90 |
    | best-practices | 90 |
    | seo            | 80 |

Older Cypress-era steps such as the page should load quickly, the lighthouse {input} score should be above {input}, and the lighthouse metrics should be at most: are no longer registered. Use the three steps above.

UI/UX style and design tokens

Step Variables What it does
the {input} {input} should have {input} as {input} Text, element type, CSS property, value Asserts a computed CSS property
the {input} {input} should use the {input} class Text, element type, CSS class Asserts a CSS class
the {input} {input} should have {input} {input} Text, element type, token, property Compares a property with a design token
the design tokens {string} should be defined Comma-separated token names Checks that tokens resolve
the {input} {input} should meet {input} standard for contrast Text, element type, A/AA/AAA Checks contrast ratio

Element types include button, heading, link, input, text, section, image, and card. Results are recorded as quality events and rendered by the quality reporter.

Authentication steps

Step Variables What it does
I am presented with a sign-in challenge or an unauthorized error — Checks that an unauthenticated visitor is challenged
the profile email should match the configured {string} Credential key Checks the profile panel against the configured account

Two tags select the session seeded by the setup project: @loginAsIDIR and @loginAsBCeID. No login step belongs in a feature file. See Writing Playwright BDD Scenarios.

See also

Clone this wiki locally