Status: ✅ Hardened & Production-Ready
- Design Pattern: Page Object Model — Clean separation of test logic and UI interactions
- Resilient Selectors — Prefer role-based and attribute-based locators over brittle XPath
- Reporting: Allure — Rich HTML/Allure reports with traces and screenshots
- Cloud Integration: SauceLabs — Multi-browser cloud execution support
- CI/CD-Optimized — Headless by default, artifact capture only on failure
- State-Based Waits — No hard
waitForTimeoutcalls; all delays are deterministic
- Node.js 18+ and npm 8+
- Git (recommended)
- Visual Studio Code with GitLens and Playwright Test for VSCode
# Clone and install git clone <repo-url> cd playwright-javascript npm install # Verify environment npm run sauce:check # Run tests npm test # Headless, all reporters npm run test:ci # For CI pipelines npm run e2e # E2E config variant HEADED=true npm test # Interactive (headed) mode # Run by environment npm run test:dev npm run test:qa npm run test:uat npm run e2e:dev npm run e2e:qa npm run e2e:uat
- Add new spec under
e2e-tests/folder as<feature>.spec.js - Create or reuse a page object module in
e2e-tests/page-objects/<Feature>Page.js - Use robust selectors:
getByRole(),getByLabel(),getByPlaceholder(), or stable CSS/attribute selectors - Avoid brittle selectors: XPath with text content, CSS module class names, DOM structure dependencies
- Use state-based waits:
expect(locator).toBeVisible/Enabled/Disabled(),page.waitForFunction(), never rawwaitForTimeout()
const { test, expect } = require("@playwright/test"); const { HomePage } = require("./page-objects/HomePage"); test.describe("Home Page", () => { test.beforeEach(async ({ page }) => { const home = new HomePage(page); await home.navigate(); }); test("should display home page title", async ({ page }) => { const home = new HomePage(page); await expect(page).toHaveTitle("Acme Store"); }); });
npm test # Run all tests headless HEADED=true npm test # Headed mode (watch UI) npm run headedTest # Alias for headed mode npx playwright test --debug # Debug mode with inspector
npm run test:ci # Optimized for CI: headless=true, artifacts=on-failure CI=true npm test # Sets CI env var for config conditions
npx playwright test e2e-tests/home.spec.js npx playwright test e2e-tests/cart.spec.js
npm run test-list-reporter # Minimal output npm run test-line-reporter # Single-line per test npm run test-html-reporter # Full HTML report npm run e2e-commandline-reporter # Multiple reporters + Allure
npx playwright show-report # Open latest HTML report # Or navigate to: ./playwright-report/index.html
npm run allure-report # Generate and open Allure report npx allure generate ./allure-results && allure open # Manual
- Captured in
./test-results/on test failure - Traces can be viewed with:
npx playwright show-trace <trace-file>.zip
CI=true— Triggers CI-specific config (headless, single worker, retries=2)HEADED=true— Forces headed mode even in CI (for debugging)DEBUG=pw:api— Enable Playwright debug loggingENV_FILE=.env.dev|.env.qa|.env.uat— Selects environment file for base URL and env-specific values
.env.devfor development testing.env.qafor QA validation.env.uatfor UAT validation.env.exampleas template for creating environment files
- name: Run tests run: npm run test:ci env: CI: true - name: Upload test results if: failure() uses: actions/upload-artifact@v3 with: name: test-results path: test-results/
-
Obtain SauceLabs credentials from https://saucelabs.com/
-
Set environment variables:
- Windows PowerShell:
$env:SAUCE_USERNAME="YOUR_USERNAME"and$env:SAUCE_ACCESS_KEY="YOUR_KEY" - macOS/Linux:
export SAUCE_USERNAME="YOUR_USERNAME"andexport SAUCE_ACCESS_KEY="YOUR_KEY"
- Windows PowerShell:
-
Validate config:
npm run sauce:check
saucectl run -c saucelabs.config.js
See SauceLabs Playwright Docs for advanced setup.
- Selectors First: Always prefer accessibility locators (
getByRole) over implementation details - No Magic Waits: Remove
waitForTimeout(); useexpect()assertions which include waits - POM Cleanliness: Keep page objects focused on UI interactions, not test logic
- Parallel Testing: Leverage
workers: autoin config; ensure tests are isolated - CI-First Config: Default settings support CI; developers opt-in to headed mode
playwright-javascript/
├── e2e-tests/
│ ├── home.spec.js # Home page test suite
│ ├── search.spec.js # Search/navigation test suite
│ ├── cart.spec.js # Cart/add-to-cart test suite
│ └── page-objects/
│ ├── HomePage.js
│ ├── SearchPage.js
│ └── CartPage.js
├── playwright.config.js # Main Playwright config
├── e2e.config.js # E2E-specific config variant
├── saucelabs.config.js # Cloud execution config
├── my-awesome-reporter.js # Custom test reporter
├── package.json
├── README.md
└── test-results/ # Test artifacts (gitignored)
For issues, feature requests, or improvements, please:
- Check existing test logs in
./test-results/ - Run
npm run sauce:checkto validate external config - Review recent changes in git history
- Submit an issue or PR with test logs and environment details
Last Updated: May 2026 | Framework Version: 1.0.0 (Hardened)