Playwright-BDD operates by converting BDD scenarios into native Playwright tests. This ensures that you get the full power of the Playwright runner (fixtures, reporting, parallelization) while maintaining a BDD workflow.
Phase 1: Generate tests
The npx bddgen command reads your .feature files and generates corresponding .js or .ts files.
Example Input (Gherkin):
Feature: Playwright Home Page
Scenario: Check title
Given I am on Playwright home page
When I click link "Get started"
Then I see in title "Installation"
Example Output (Generated Playwright Test):
import { test } from 'playwright-bdd';
test.describe('Playwright Home Page', () => {
test('Check title', async ({ Given, When, Then }) => {
await Given('I am on Playwright home page');
await When('I click link "Get started"');
await Then('I see in title "Installation"');
});
});
Phase 2: Run tests
You run the generated files using the standard Playwright command: npx playwright test.
Step definitions have full access to Playwright APIs and fixtures (like page).
Example Step Definitions:
Given('I am on Playwright home page', async ({ page }) => {
await page.goto('https://playwright.dev');
});
When('I click link {string}', async ({ page }, name) => {
await page.getByRole('link', { name }).click();
});
Then('I see in title {string}', async ({ page }, text) => {
await expect(page).toHaveTitle(new RegExp(text));
});
npx bddgen && npx playwright test