This example demonstrates using openqa with Playwright BDD (Behavior-Driven Development) tests written in Gherkin syntax.
Install dependencies:
npm installAuthentication:
Use Claude Code credentials (recommended):
claude loginOr set your Anthropic API key (not needed if you logged in to claude code):
cp .env.example .env
# Edit .env and add your ANTHROPIC_API_KEYnpm test # Generate and run all tests
npm run test:headed # Run with visible browser
npm run test:ui # Open Playwright UI
npm run bddgen # Only generate tests from featuresThis example shows how to:
- Write BDD scenarios in Gherkin syntax (features/*.feature)
- Use AI agent in BDD step definitions
- Share browser context between regular steps and AI-powered steps
- Generate Cucumber HTML reports from test execution
playwright-bdd/
├── features/
│ ├── playwright-home.feature # Gherkin feature files
│ └── steps/
│ ├── fixtures.ts # BDD test setup and helpers
│ └── steps.ts # Step definitions with agent
├── playwright.config.ts # BDD-specific config
└── package.json
Feature: Playwright Home Page
Scenario: Check title
Given navigate to 'https://playwright.dev/'
When click link "Get started"
Then Verify in title "Installation"The key innovation is using a single generic AI step that handles ALL steps:
import { runAgent, claudeCode } from 'openqa';
import { aistep } from './fixtures';
// Generic AI-powered step - handles ANY step with natural language
aistep(/^(.*)$/, async ({ page, context }, action: string) => {
await runAgent(claudeCode('claude-haiku-4-5'), action, page, { verbose: false });
});fixtures.ts:
import { test as base, createBdd } from 'playwright-bdd';
export const test = base.extend({});
// Export 'Step' as 'aistep' - matches any Given/When/Then
export const { Step: aistep } = createBdd(test);That's it! No need to write individual step definitions. The AI agent handles everything based on the natural language in your feature files.
- Write scenarios in Gherkin (Given/When/Then)
- Run
bddgento generate test files from features - ALL steps are handled by AI agent using natural language
- Browser context is shared between all steps
- No code required - just write scenarios and run tests!
- Zero code: Write tests in pure natural language
- One generic step: Handles ALL Given/When/Then steps automatically
- Same browser session: Shared context across all steps
- BDD syntax: Business-readable test scenarios
- AI flexibility: Adapts to any web interaction
- Cucumber reports: HTML reports with screenshots and videos
After running tests, view the report:
npx playwright show-reportThe report includes:
- Scenario pass/fail status
- Step-by-step execution
- Screenshots and videos (on failure)
- Execution time