Markdown
This repository houses an end-to-end test suite built with Playwright, utilizing the playwright-bdd framework to implement Behavior-Driven Development (BDD) using Gherkin feature files.
Ensure you have Node.js and npm installed.
All necessary packages, including @playwright/test, playwright-bdd, and @cucumber/cucumber, are listed in package.json.
npm install
Path,Content tests/features/, "Contains the Gherkin feature files (.feature) defining test scenarios (e.g., login.feature, products.feature)."
tests/steps/, "Contains the step definition files (.ts) that map Gherkin steps (Given/When/Then) to Playwright code (e.g., loginsteps.ts, productsteps.ts)."
/tests/pages/, "Contains the Page Object Model (POM) classes (e.g., LoginPage.ts, ProductsPage.ts)."
tests/fixtures/, "Contains fixtures.ts, which sets up the BDD test context and initializes the Page Object Model classes."
.features-gen/, "Contains Generated directory created by playwright-bdd that contains the final executable Playwright spec files (.spec.js)."
The playwright.config.ts file is configured to use playwright-bdd to map your features to step definitions and direct Playwright to the correct test files.
Key BDD Configuration: The defineBddConfig specifies all BDD files:
const testDir = defineBddConfig({ features: [ 'tests/features/login.feature', 'tests/features/products.feature', 'tests/features/cart.feature', 'tests/features/completeorder.feature' ], steps: [ 'tests/fixtures/fixtures.ts', 'tests/steps/loginsteps.ts', 'tests/steps/productsteps.ts', 'tests/steps/cartsteps.ts', 'tests/steps/completeordersteps.ts' ] });
export default defineConfig({
// Use the testDir returned from defineBddConfig so playwright-bdd can find its config
testDir,
// Ensure Playwright only picks up spec files we care about (generated JS or existing TS specs)
testMatch: [
'/.features-gen//.spec.js',
'/tests//.spec.ts',
'/*.spec.ts',
'/*.spec.js',
],
});
Use the npm scripts defined in package.json to run your test suite.
This command first generates the Playwright test files from your features (bddgen) and then executes the tests.
npm test
To compile Gherkin files into executable Playwright specs without running the tests:
npm run test:gen
After running the tests, view the comprehensive HTML report in your browser:
npx playwright show-report