Skip to content

Writing Playwright BDD Scenarios

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

Writing Playwright BDD Scenarios

This guide is for anyone who wants to describe a user journey as a test scenario. No coding experience is required.

Gherkin and playwright-bdd

Gherkin is a plain-text format that reads like a recipe. Each scenario lives in a .feature file under e2e/features/. playwright-bdd converts those files into Playwright tests at run time. You write what should happen; developers implement how.

For background, see the free BDD Overview for Business Analysts and Product Owners course.

Gherkin is sensitive to spacing and keyword casing. Use Feature, Scenario, Given, When, Then, And, and But exactly as shown.

Submitting a test through GitHub Issues

  1. Open Issues and select New issue.
  2. Choose the User provided automated test-case template.
  3. Fill in the form with the journey, steps, and expected result.

The team converts the issue into a feature file. If a step is not implemented yet, the run fails with an undefined step. That is the signal for a developer to add it to e2e/playwright/steps/.

Creating a feature

Every file starts with a Feature line. The description sits one indent level below it.

Feature: Reporting unit details

  A user looking up a reporting unit sees its client, district, and status.

Creating scenarios

A scenario is a series of steps. Use the exact wording from the Playwright BDD Step Reference. Wrap variable values in double quotes.

Feature: Screen loading

  Scenario: Screen loads
    Given I visit "/"
    Then I can read "Waste Plus"

Steps sit one indent level below Scenario, and the scenario sits one level below Feature.

Authentication tags

Tag a scenario above its Scenario keyword when it needs a signed-in user. The Playwright setup project performs the real CSS login before any journey runs, then the scenario reuses that session. Do not write login steps into the feature.

@loginAsBCeID
Scenario: Search as a business user
  Given I visit "/search"
  Then I can read "Search"
Tag Session
@loginAsIDIR IDIR user, signed in through Entra with TOTP
@loginAsBCeID Business BCeID user
@chromeOnly Chromium-only check, including Lighthouse audits

Authenticated scenarios start on /search. Add Given I visit "/some/path" as the first step when you need another page.

Running your scenario

From the repository root:

cd e2e
npm ci
npx playwright install chromium
PW_FEATURES=features/screen-load.feature npx bddgen && npx playwright test

Omit PW_FEATURES to run the full suite. Credentials for the setup project live in the package's git-ignored .env or CI secrets; the Playwright Developer Guide lists the variable names.

Next steps

Clone this wiki locally