This repository contains examples and configurations for using the Playwright tool with Behavior-Driven Development (BDD) using playwright-bdd. Playwright is a powerful framework for testing web applications across multiple browsers with ease, and playwright-bdd
allows you to write tests in a Gherkin-style syntax.
- Cross-Browser Testing: Run tests on Chromium, Firefox, and WebKit.
- BDD Support: Write tests in Gherkin syntax using
playwright-bdd
. - Parallel Execution: Speed up your test runs with parallel execution.
- Trace Viewer: Debug failed tests with detailed traces.
- CI Integration: Pre-configured GitHub Actions workflow for automated testing.
- TypeScript Support: Write tests with TypeScript for better type safety.
.
├── .github/workflows/ # CI/CD workflows for GitHub Actions
├── playwright.config.ts # Playwright configuration file
├── src/
│ ├── features/ # Gherkin feature files
│ ├── steps/ # Step definitions for BDD
│ ├── pages/ # Page Object Model (POM) classes
├── tests/ # Directory for additional test files
├── tests-examples/ # Example test cases
├── playwright-report/ # HTML reports generated after test runs
├── test-results/ # Test artifacts (e.g., traces, screenshots)
├── package.json # Project dependencies and scripts
└── README.md # Project documentation
-
Clone the repository:
git clone https://github.com/your-username/e2e-testing-with-playwright.git cd e2e-testing-with-playwright
-
Install dependencies:
npm install
-
Install Playwright browsers:
npx playwright install --with-deps
npx playwright test
npx playwright test src/features/example.feature
npx playwright test --debug
Write your test scenarios in Gherkin syntax under the src/features/
directory. For example:
# filepath: src/features/homepage.feature
Feature: Homepage
Scenario: Open the homepage
Given I am on home page
Then I should see the title "Wikipedia"
Define the steps in the src/steps/
directory. For example:
// filepath: src/steps/homepage.steps.ts
import { Given, Then } from '@cucumber/cucumber';
import { expect } from '@playwright/test';
Given('I am on home page', async function () {
await this.page.goto('https://www.wikipedia.org/');
});
Then('I should see the title {string}', async function (title: string) {
const pageTitle = await this.page.title();
expect(pageTitle).toBe(title);
});
After running tests, an HTML report will be generated in the playwright-report/
directory. Open it in your browser to view detailed results:
npx playwright show-report
This project includes a pre-configured GitHub Actions workflow (.github/workflows/playwright.yml
) to automatically run tests on every push or pull request to the main
or master
branch.
This repository contains examples and configurations for using the Playwright tool with Behavior-Driven Development (BDD) using playwright-bdd. Playwright is a powerful framework for testing web applications across multiple browsers with ease, and playwright-bdd
allows you to write tests in a Gherkin-style syntax.