Playwright E2E Testing Standards
Purpose
Progressive disclosure of Playwright end-to-end testing standards for agents writing E2E tests.
Authoritative Source: docs/explanation/software-engineering/automation-testing/tools/playwright/README.md
Usage: Auto-loaded for agents when writing Playwright E2E tests. Provides quick reference to test organization, selectors, assertions, page objects, and debugging patterns.
Quick Standards Reference
- Test Organization, Selectors, Assertions — file structure, naming, accessibility-first selector priority, web-first assertions
- Page Object Model and Configuration — class-based POM pattern, playwright.config.ts standards
- Best Practices, Anti-Patterns, Debugging — test isolation, API+UI combination, common anti-patterns, trace viewer/inspector
OSE Platform Context
Islamic Finance Testing
Zakat Calculator Tests:
test("calculates zakat correctly", async ({ page }) => {
await page.goto("/zakat-calculator");
await page.getByLabel("Wealth Amount").fill("100000");
await page.getByRole("button", { name: "Calculate" }).click();
// Verify 2.5% calculation
await expect(page.getByTestId("zakat-amount")).toHaveText("RM 2,500.00");
});
Murabaha Contract Tests:
test("murabaha contract workflow", async ({ page }) => {
const murabaha = new MurabahaPage(page);
await murabaha.goto();
await murabaha.createContract({
asset: "Vehicle",
cost: 50000,
profitRate: 5,
});
await expect(page.getByText("Contract Created")).toBeVisible();
await expect(page.getByTestId("total-payment")).toContainText("52,500");
});
Test-Driven Development for E2E
TDD applies to E2E test authoring: write the failing Playwright spec — or a failing Playwright-MCP
manual verification script — before the feature implementation exists. Both forms follow
Red→Green→Refactor:
- Red: Author the
.spec.ts or manual verification script and run it. It must fail because the
feature does not yet exist, not because of a misconfigured test environment.
- Green: The feature implementation makes every Playwright assertion or manual observation pass.
- Refactor: Improve locators, page objects, and fixture composition while keeping all assertions
green.
Manual verification scripts are TDD-compliant when they are written, dated, repeatable, and contain
discrete expected observations (e.g., "Navigate to /products → snapshot shows product list with 3
items"). Informal "tested manually" notes are not TDD-compliant. Promote manual scripts to
automated Playwright specs whenever the behaviour recurs.
Canonical references:
Related Standards
See Authoritative Documentation:
1---2name: swe-developing-e2e-test-with-playwright3description: Playwright E2E testing standards from authoritative docs/explanation/software-engineering/automation-testing/tools/playwright/ documentation4---56# Playwright E2E Testing Standards78## Purpose910Progressive disclosure of Playwright end-to-end testing standards for agents writing E2E tests.1112**Authoritative Source**: [docs/explanation/software-engineering/automation-testing/tools/playwright/README.md](../../../docs/explanation/software-engineering/automation-testing/tools/playwright/README.md)1314**Usage**: Auto-loaded for agents when writing Playwright E2E tests. Provides quick reference to test organization, selectors, assertions, page objects, and debugging patterns.1516## Quick Standards Reference1718- [Test Organization, Selectors, Assertions](./reference/test-org-selectors-assertions.md) — file structure, naming, accessibility-first selector priority, web-first assertions19- [Page Object Model and Configuration](./reference/page-objects-config.md) — class-based POM pattern, playwright.config.ts standards20- [Best Practices, Anti-Patterns, Debugging](./reference/best-practices-antipatterns-debugging.md) — test isolation, API+UI combination, common anti-patterns, trace viewer/inspector2122## OSE Platform Context2324### Islamic Finance Testing2526**Zakat Calculator Tests**:2728```typescript29test("calculates zakat correctly", async ({ page }) => {30 await page.goto("/zakat-calculator");31 await page.getByLabel("Wealth Amount").fill("100000");32 await page.getByRole("button", { name: "Calculate" }).click();3334 // Verify 2.5% calculation35 await expect(page.getByTestId("zakat-amount")).toHaveText("RM 2,500.00");36});37```3839**Murabaha Contract Tests**:4041```typescript42test("murabaha contract workflow", async ({ page }) => {43 const murabaha = new MurabahaPage(page);44 await murabaha.goto();45 await murabaha.createContract({46 asset: "Vehicle",47 cost: 50000,48 profitRate: 5,49 });5051 await expect(page.getByText("Contract Created")).toBeVisible();52 await expect(page.getByTestId("total-payment")).toContainText("52,500");53});54```5556## Test-Driven Development for E2E5758TDD applies to E2E test authoring: write the failing Playwright spec — or a failing Playwright-MCP59manual verification script — **before** the feature implementation exists. Both forms follow60Red→Green→Refactor:6162- **Red**: Author the `.spec.ts` or manual verification script and run it. It must fail because the63 feature does not yet exist, not because of a misconfigured test environment.64- **Green**: The feature implementation makes every Playwright assertion or manual observation pass.65- **Refactor**: Improve locators, page objects, and fixture composition while keeping all assertions66 green.6768Manual verification scripts are TDD-compliant when they are written, dated, repeatable, and contain69discrete expected observations (e.g., "Navigate to /products → snapshot shows product list with 370items"). Informal "tested manually" notes are not TDD-compliant. Promote manual scripts to71automated Playwright specs whenever the behaviour recurs.7273**Canonical references**:7475- [Test-Driven Development Convention](../../../repo-governance/development/workflow/test-driven-development.md)76 — full Red→Green→Refactor rules, "Manual verification is part of TDD" subsection, and all test77 levels covered.78- [Manual Behavioural Verification](../../../repo-governance/development/quality/manual-behavioural-verification.md)79 — Playwright MCP tool list, verification checklists, and `curl` for API verification.8081## Related Standards8283**See Authoritative Documentation**:8485- [Test Organization](../../../docs/explanation/software-engineering/automation-testing/tools/playwright/test-organization.md) - Test structure, fixtures, grouping86- [Selectors](../../../docs/explanation/software-engineering/automation-testing/tools/playwright/selectors.md) - Accessibility-first selector strategies87- [Assertions](../../../docs/explanation/software-engineering/automation-testing/tools/playwright/assertions.md) - Web-first assertions88- [Page Objects](../../../docs/explanation/software-engineering/automation-testing/tools/playwright/page-objects.md) - Page Object Model patterns89- [Configuration](../../../docs/explanation/software-engineering/automation-testing/tools/playwright/configuration.md) - playwright.config.ts setup90- [Best Practices](../../../docs/explanation/software-engineering/automation-testing/tools/playwright/best-practices.md) - Production testing standards91- [Anti-Patterns](../../../docs/explanation/software-engineering/automation-testing/tools/playwright/anti-patterns.md) - Common mistakes92- [Idioms](../../../docs/explanation/software-engineering/automation-testing/tools/playwright/idioms.md) - Playwright-specific patterns93- [Debugging](../../../docs/explanation/software-engineering/automation-testing/tools/playwright/debugging.md) - Trace viewer, inspector