This document explains how the automation framework works, how tests are generated, and the standard workflow for adding new tests.
This project uses Playwright combined with playwright-bdd to enable Behavior Driven Development (BDD). This allows us to write tests in plain English using Gherkin syntax (.feature files) while leveraging the power of Playwright for browser automation.
-
Feature Files (
features/*.feature):- These contain the test scenarios written in Gherkin syntax (Given, When, Then).
- They serve as the source of truth for what is being tested.
-
Step Definitions (
tests/steps/*.steps.ts):- These TypeScript files map the Gherkin steps to actual code execution.
- They use
createBdd()fromplaywright-bddto defineGiven,When, andThensteps.
-
Page Objects (
pages/*.ts):- Follows the Page Object Model (POM) design pattern.
- Encapsulates locators and methods for interacting with specific pages (e.g.,
LoginPage,HomePage). - Keeps step definitions clean and maintainable.
-
Test Generation (
.features-gen/):playwright-bddautomatically generates Playwright test files (.spec.js) based on your feature files and step definitions.- Note: You do not edit files in
.features-gen/manually.
-
Configuration (
playwright.config.ts):- Configures Playwright settings (browser, base URL, etc.) and BDD options.
The process follows a "Feature First" approach:
Create a new .feature file in the features/ directory (or add to an existing one). Describe your scenario using Gherkin.
Example (features/navigation.feature):
Feature: Navigation
Scenario: Verify Navigation Menu Items
Given I am on the dashboard
Then I should see the "Accounts" menu itemCreate or update a .steps.ts file in tests/steps/. Map the steps from your feature file to code.
Example (tests/steps/navigation.steps.ts):
import { createBdd } from 'playwright-bdd';
import { HomePage } from '../../pages/homepage';
import { expect } from '@playwright/test';
const { Given, Then } = createBdd();
Given('I am on the dashboard', async ({ page }) => {
// ... code to login and go to dashboard ...
});
Then('I should see the {string} menu item', async ({ page }, menuItem: string) => {
const homePage = new HomePage(page);
// ... verification logic ...
});Run the generation command to convert your feature files into Playwright executable tests.
npx bddgenThis will update the .features-gen/ directory.
Execute the generated tests using Playwright.
npx playwright testOr run a specific feature:
npx playwright test features/navigation.featureAfter execution, you can view the standard Playwright report or the Allure report (if configured).
npx playwright show-reportWe have a convenience script in package.json that does everything (clean, generate, run, and report):
npm run bdd| Command | Description |
|---|---|
npx bddgen |
Generates Playwright test files from Feature files. |
npx playwright test |
Runs all tests. |
npx playwright test --ui |
Runs tests in UI mode (great for debugging). |
npm run bdd |
Full cycle: Clean -> Generate -> Run -> Report. |