Skip to content

Latest commit

Β 

History

History
435 lines (343 loc) Β· 14.3 KB

File metadata and controls

435 lines (343 loc) Β· 14.3 KB

🎭 QA Automation Practice Playground β€” Playwright Framework

Enterprise-grade Playwright TypeScript automation framework targeting the QA Automation Practice Playground (30 sections, 600+ test cases).


πŸ“‹ Table of Contents


πŸ“ Framework Structure

playwright-framework/
β”‚
β”œβ”€β”€ tests/                          # Test specs (30 sections Γ— 20 cases each)
β”‚   β”œβ”€β”€ s01/  basic-form.spec.ts    # Section 1  β€” Basic Form Elements
β”‚   β”œβ”€β”€ s02/  buttons.spec.ts       # Section 2  β€” Button Interactions
β”‚   β”œβ”€β”€ s03/  checkboxes.spec.ts    # Section 3  β€” Checkboxes & Radio
β”‚   β”œβ”€β”€ s04/  dropdowns.spec.ts     # Section 4  β€” Dropdowns
β”‚   β”œβ”€β”€ s07/  waits.spec.ts         # Section 7  β€” Waits & Sync
β”‚   β”œβ”€β”€ s08/  table.spec.ts         # Section 8  β€” Table Automation
β”‚   β”œβ”€β”€ s09/  alerts.spec.ts        # Section 9  β€” Alerts
β”‚   β”œβ”€β”€ s10/  modals.spec.ts        # Section 10 β€” Modals
β”‚   β”œβ”€β”€ s11/  iframe.spec.ts        # Section 11 β€” iFrame
β”‚   β”œβ”€β”€ s12/  shadow-dom.spec.ts    # Section 12 β€” Shadow DOM
β”‚   β”œβ”€β”€ s13/  drag-drop.spec.ts     # Section 13 β€” Drag & Drop
β”‚   β”œβ”€β”€ s14/  hover.spec.ts         # Section 14 β€” Hover Menus
β”‚   β”œβ”€β”€ s15/  tooltip.spec.ts       # Section 15 β€” Tooltips
β”‚   β”œβ”€β”€ s16/  file-upload.spec.ts   # Section 16 β€” File Upload / Download
β”‚   β”œβ”€β”€ s21/  auth.spec.ts          # Section 21 β€” Authentication
β”‚   β”œβ”€β”€ s22/  stale-element.spec.ts # Section 22 β€” Stale Element
β”‚   β”œβ”€β”€ s23/  dynamic-list.spec.ts  # Section 23 β€” Dynamic List
β”‚   β”œβ”€β”€ s26/  keyboard.spec.ts      # Section 26 β€” Keyboard Actions
β”‚   β”œβ”€β”€ s27/  slider.spec.ts        # Section 27 β€” Range Slider
β”‚   β”œβ”€β”€ s28/  datepicker.spec.ts    # Section 28 β€” Date Picker
β”‚   └── s30/  complex-dom.spec.ts   # Section 30 β€” Complex DOM
β”‚
β”œβ”€β”€ pages/                          # Page Object Models
β”‚   β”œβ”€β”€ BasePage.ts                 # Shared utilities (nav, wait, scroll)
β”‚   β”œβ”€β”€ BasicFormPage.ts            # Section 1
β”‚   β”œβ”€β”€ ButtonsPage.ts              # Section 2
β”‚   β”œβ”€β”€ CheckboxesPage.ts           # Section 3
β”‚   β”œβ”€β”€ DropdownsPage.ts            # Section 4
β”‚   β”œβ”€β”€ DynamicContentPage.ts       # Sections 6, 7, 22, 23, 24, 25
β”‚   β”œβ”€β”€ TablePage.ts                # Section 8
β”‚   β”œβ”€β”€ AlertsModalPage.ts          # Sections 9, 10
β”‚   β”œβ”€β”€ AdvancedPage.ts             # Sections 11-15, 16-20, 26-30
β”‚   └── AuthPage.ts                 # Section 21
β”‚
β”œβ”€β”€ components/                     # Reusable UI components
β”‚   β”œβ”€β”€ TableComponent.ts           # Generic table helper
β”‚   └── FormComponent.ts            # Generic form helper
β”‚
β”œβ”€β”€ fixtures/
β”‚   └── custom-fixtures.ts          # Extended test fixtures (all POM injection)
β”‚
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ helpers.ts                  # TestHelpers, A11yHelpers
β”‚   β”œβ”€β”€ constants.ts                # TIMEOUTS, CREDENTIALS, TABLE_DATA, etc.
β”‚   └── fileReader.ts               # JSON/CSV/TXT reader utilities
β”‚
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ environment.ts              # Per-environment config (local|ci|staging)
β”‚   β”œβ”€β”€ global-setup.ts             # Runs once before all tests
β”‚   β”œβ”€β”€ global-teardown.ts          # Runs once after all tests
β”‚   β”œβ”€β”€ auth.setup.ts               # Auth state setup project
β”‚   └── .env                        # Environment variables template
β”‚
β”œβ”€β”€ test-data/
β”‚   β”œβ”€β”€ users.json                  # Valid/invalid login credentials
β”‚   └── products.json               # Form data, dropdown options, dates
β”‚
β”œβ”€β”€ reports/                        # Generated (gitignored) test outputs
β”‚
β”œβ”€β”€ docker/
β”‚   β”œβ”€β”€ Dockerfile                  # Playwright Docker image
β”‚   └── docker-compose.yml          # Multi-service compose file
β”‚
β”œβ”€β”€ .github/workflows/
β”‚   └── playwright-ci.yml           # GitHub Actions pipeline
β”‚
β”œβ”€β”€ .azure/
β”‚   └── azure-pipelines.yml         # Azure DevOps pipeline
β”‚
β”œβ”€β”€ .jenkins/
β”‚   └── Jenkinsfile                 # Jenkins declarative pipeline
β”‚
β”œβ”€β”€ scripts/
β”‚   └── run-tests.sh                # CLI convenience wrapper
β”‚
β”œβ”€β”€ playwright.config.ts            # Main Playwright configuration
β”œβ”€β”€ tsconfig.json                   # TypeScript configuration
β”œβ”€β”€ package.json                    # Dependencies & npm scripts
β”œβ”€β”€ .eslintrc.json                  # ESLint rules
β”œβ”€β”€ .prettierrc                     # Prettier formatting
└── .gitignore                      # Git ignore rules

πŸ”§ Prerequisites

Tool Minimum Version
Node.js 18.0.0
npm 9.0.0
Playwright 1.44.0
TypeScript 5.4.5

πŸš€ Quick Start

# 1. Clone / enter the framework directory
cd playwright-framework

# 2. Install all dependencies
npm ci

# 3. Install Playwright browsers
npm run setup

# 4. Place the playground HTML at the project root
cp /path/to/automation-practice-playground.html ./

# 5. Run smoke tests
npm run test:smoke

# 6. View the report
npm run test:report

βš™οΈ Configuration

Environment Variables (config/.env)

Variable Default Description
TEST_ENV local local / ci / staging
BASE_URL file://./automation-practice-playground.html Path or URL to the playground
VALID_USERNAME admin Login username for auth tests
VALID_PASSWORD password123 Login password for auth tests
CI false Enables CI-specific settings
HEADLESS false Force headless mode

Copy .env to .env.local and override values locally. Never commit real credentials.


▢️ Running Tests

npm scripts

# All tests (default browser)
npm test

# Headed mode
npm run test:headed

# Interactive UI mode
npm run test:ui

# Debug mode (step-through)
npm run test:debug

# Specific browser
npm run test:chromium
npm run test:firefox
npm run test:webkit
npm run test:all-browsers

# Tag-based
npm run test:smoke         # @smoke tag
npm run test:regression    # @regression tag

# Parallel / serial
npm run test:parallel      # 4 workers
npm run test:serial        # 1 worker

# Open last HTML report
npm run test:report

# Generate Allure report
npm run report:allure

Shell script (with options)

chmod +x scripts/run-tests.sh

# Smoke tests in headed mode
./scripts/run-tests.sh --smoke --headed

# Section 21 on Firefox
./scripts/run-tests.sh -s 21 -b firefox

# Full regression with report
./scripts/run-tests.sh --regression --report

# Run inside Docker
./scripts/run-tests.sh --docker

Run a specific section

npx playwright test --grep @s21        # Auth section
npx playwright test --grep "@s11|@s12" # iframe + Shadow DOM
npx playwright test tests/s08/         # Table folder directly

πŸ§ͺ Test Organisation

Every spec file follows this naming and tagging convention:

TC_S{section}_{P|N}{number} β€” Description @tagA @tagB

P = Positive test case
N = Negative test case

Tag taxonomy

Tag Meaning
@smoke Critical path β€” run on every commit
@regression Full coverage β€” nightly / PRs
@s1–@s30 Section-specific filter
@form Form-related tests
@auth Authentication tests
@advanced Shadow DOM, iFrame, Stale Element

πŸ—οΈ Page Objects

All Page Objects extend BasePage which provides:

  • navigateTo(url?) β€” navigate to playground
  • scrollToSection(id) β€” smooth scroll to section anchor
  • waitForElement(selector) β€” explicit wait
  • waitForElementHidden(selector) β€” wait for hidden state
  • waitForText(selector, text) β€” wait for text condition
  • takeScreenshot(name) β€” manual screenshot
  • getText / getValue / getAttribute β€” element data extraction

POM Hierarchy

BasePage
  β”œβ”€β”€ BasicFormPage     (s1)
  β”œβ”€β”€ ButtonsPage       (s2)
  β”œβ”€β”€ CheckboxesPage    (s3)
  β”œβ”€β”€ DropdownsPage     (s4)
  β”œβ”€β”€ DynamicContentPage (s6, s7, s22, s23, s24, s25)
  β”œβ”€β”€ TablePage         (s8)
  β”œβ”€β”€ AlertsModalPage   (s9, s10)
  β”œβ”€β”€ AuthPage          (s21)
  └── AdvancedPage      (s11-s20, s26-s30)

πŸ”Œ Fixtures & Components

Custom Fixtures (fixtures/custom-fixtures.ts)

All Page Objects are injected automatically β€” no manual instantiation needed:

import { test, expect } from '../fixtures/custom-fixtures';

test('my test', async ({ authPage, tablePage }) => {
  await authPage.loginAndWaitForDashboard('admin', 'password123');
  await tablePage.goto();
  // ...
});

Reusable Components

import { TableComponent } from '../components/TableComponent';
import { FormComponent }  from '../components/FormComponent';

// Generic table helper
const table = new TableComponent(page, '#my-table');
const rows  = await table.getRowCount();
const sorted = await table.isSortedAscending(1);

// Generic form helper
const form = new FormComponent(page);
await form.fillByTestId('input-email', 'test@example.com');
await form.submitByTestId('btn-submit');

πŸ”„ CI/CD Integration

GitHub Actions (.github/workflows/playwright-ci.yml)

  • Triggers: push, PR, nightly schedule, manual dispatch
  • Sharded parallel runs (3 shards Γ— chromium)
  • Cross-browser on schedule (Firefox + WebKit)
  • Merged HTML report published to GitHub Pages
  • Artifacts retained for 7–14 days

Azure DevOps (.azure/azure-pipelines.yml)

  • Parallel matrix strategy
  • JUnit results published to Azure Test Plans
  • HTML + Allure artifacts uploaded per shard
  • Parameterised environment and browser selection

Jenkins (.jenkins/Jenkinsfile)

  • Declarative pipeline with Docker agent
  • Parallel lint + type-check stage
  • Allure report via allure-jenkins-plugin
  • Slack notifications on pass/fail
  • Cross-browser stage gated to nightly triggers

🐳 Docker

# Build image
docker build -f docker/Dockerfile -t qa-playground-pw .

# Run smoke tests
docker compose -f docker/docker-compose.yml up playwright-smoke

# Run full regression
docker compose -f docker/docker-compose.yml up playwright-regression

# View Allure report at http://localhost:5050
docker compose -f docker/docker-compose.yml up allure

πŸ“Š Reporting

Reporter Output Command
HTML playwright-report/index.html npm run test:report
JSON test-results/results.json Auto-generated
JUnit test-results/results.xml Auto-generated (CI use)
Allure allure-report/ npm run report:allure
List Terminal stdout Default

Screenshots, videos, and traces are captured on failure and stored in test-results/artifacts/.


⚑ Execution Flow

npx playwright test
        β”‚
        β–Ό
 Read playwright.config.ts
 (browsers, workers, retries, reporters)
        β”‚
        β–Ό
  global-setup.ts
  (create dirs, copy HTML, log env)
        β”‚
        β–Ό
  config/auth.setup.ts  ──────────────────┐
  (login once, save auth-state.json)      β”‚
        β”‚                                 β”‚
        β–Ό                                 β”‚
  Execute tests/ **/*.spec.ts             β”‚
  (with injected fixtures from           (storageState
   custom-fixtures.ts)                    reused by
        β”‚                                 test projects)
        β”‚  Page Objects (pages/)         β”€β”˜
        β”‚  Components  (components/)
        β”‚  Helpers     (utils/)
        β”‚  Test Data   (test-data/)
        β”‚
        β–Ό
  Reports: HTML + JSON + JUnit + Allure
        β”‚
        β–Ό
  global-teardown.ts
  (log summary, cleanup)

⭐ Key Highlights

  • βœ… Page Object Model (POM) β€” clean separation between locators and test logic
  • βœ… TypeScript β€” strict typing throughout for better IDE support and safety
  • βœ… Reusable components β€” TableComponent, FormComponent usable across tests
  • βœ… Custom fixtures β€” all POMs auto-injected, zero boilerplate per test
  • βœ… Data-driven β€” test data externalised to test-data/users.json and products.json
  • βœ… Environment-aware β€” local / ci / staging configs with .env override
  • βœ… Parallelisation β€” sharded runs, configurable workers
  • βœ… Multi-browser β€” Chromium, Firefox, WebKit, Mobile Chrome, Mobile Safari
  • βœ… CI/CD ready β€” GitHub Actions, Azure DevOps, Jenkins pipelines included
  • βœ… Docker β€” fully containerised run with Allure server sidecar
  • βœ… Rich reporting β€” HTML, JSON, JUnit, Allure with screenshots, videos, traces on failure
  • βœ… 600+ test cases β€” 20 per section (10 positive + 10 negative) across all 30 sections

πŸ’‘ Pro Tip: A well-structured framework improves reusability, maintainability and helps the team deliver stable and reliable automation at scale.