Skip to content

p0sadas/playwright-typescript-enterprise-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎭 Playwright TypeScript Enterprise Framework

Playwright Tests Playwright TypeScript Node.js

A professional-grade test automation framework showcasing modern testing practices with Playwright and TypeScript

🌐 Test Target: Automation Exercise - A full-featured e-commerce demo site

Features β€’ Featured Test β€’ Project Structure β€’ Getting Started


VersiΓ³n en EspaΓ±ol


⚑ Features

Feature Description
πŸ—οΈ Page Object Model Clean, maintainable architecture with 11+ reusable page objects
πŸ”„ API + UI Hybrid Testing Seamless integration between API calls and UI validations
🌐 Multi-Browser Support Parallel testing across Chromium, Firefox, and WebKit
🏷️ Tag-Based Test Filtering Run specific suites with @smoke, @api, @regression, @critical
πŸ”§ Custom Fixtures Reusable test setup patterns for authenticated sessions
πŸš€ CI/CD Ready GitHub Actions workflow with matrix testing

🌟 Featured Test: API Login β†’ UI Validation

This test demonstrates a sophisticated hybrid testing approach that combines API efficiency with UI verification

πŸ’‘ The Challenge

Traditional UI login tests are slow and fragile. What if we could authenticate via API and then validate the session in the browser?

πŸ”§ The Solution

test("@api @regression login with api and validate in ui", async ({
  browser,
  request,
}) => {
  // 1️⃣ Extract CSRF token from login page HTML
  const loginPageHTML = await request.get(`${enviroments.dev.baseURL}/login`);
  const html = await loginPageHTML.text();
  const csrfmiddlewaretoken = html.match(
    /name="csrfmiddlewaretoken" value="(.+?)"/,
  )?.[1];

  // 2️⃣ Authenticate via API with CSRF protection
  const response = await request.post(`${enviroments.dev.baseURL}/login`, {
    headers: {
      Referer: `${enviroments.dev.baseURL}/`,
      "Content-Type": "application/x-www-form-urlencoded",
    },
    form: {
      csrfmiddlewaretoken: csrfmiddlewaretoken,
      email: users.validUser.email,
      password: users.validUser.password,
    },
  });
  expect(response.status()).toBe(200);

  // 3️⃣ Transfer authenticated session to browser context
  const context = await browser.newContext({
    storageState: await request.storageState(),
  });

  // 4️⃣ Validate login state in UI
  const pageWithLogin = await context.newPage();
  await pageWithLogin.goto(`${enviroments.dev.baseURL}`);
  await expect(pageWithLogin.getByText("Logged in as")).toBeVisible();
});

🎯 Why This Matters

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    API-UI HYBRID APPROACH                        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                  β”‚
β”‚   πŸ“‘ API Layer          πŸ”„ Session Transfer        πŸ–₯️ UI Layer   β”‚
β”‚   ────────────          ─────────────────         ──────────    β”‚
β”‚   β€’ CSRF extraction     β€’ Storage state           β€’ Logged-in   β”‚
β”‚   β€’ Fast auth           β€’ Cookie transfer           validation  β”‚
β”‚   β€’ Response checks     β€’ Context creation        β€’ Visual checkβ”‚
β”‚                                                                  β”‚
β”‚   ⚑ Speed: 10x faster than UI-only login                        β”‚
β”‚   πŸ›‘οΈ Security: Handles CSRF tokens properly                      β”‚
β”‚   βœ… Reliability: Decouples auth from UI changes                 β”‚
β”‚                                                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Project Structure

playwright-typescript-enterprise-framework/
β”œβ”€β”€ πŸ“ config/
β”‚   └── enviroments.ts          # Environment configurations
β”œβ”€β”€ πŸ“ data/
β”‚   └── users.json              # Test data
β”œβ”€β”€ πŸ“ fixtures/
β”‚   └── fixtures.ts             # Custom Playwright fixtures
β”œβ”€β”€ πŸ“ pages/                   # Page Object Model
β”‚   β”œβ”€β”€ homePage.ts
β”‚   β”œβ”€β”€ loginPage.ts
β”‚   β”œβ”€β”€ registerPage.ts
β”‚   β”œβ”€β”€ checkoutPage.ts
β”‚   β”œβ”€β”€ paymentPage.ts
β”‚   └── ... (11 page objects)
β”œβ”€β”€ πŸ“ tests/
β”‚   β”œβ”€β”€ πŸ“ api/                 # API tests
β”‚   β”‚   β”œβ”€β”€ login.api.spec.ts
β”‚   β”‚   └── products.api.spec.ts
β”‚   β”œβ”€β”€ πŸ“ auth/                # Auth UI tests
β”‚   β”‚   β”œβ”€β”€ login.spec.ts
β”‚   β”‚   └── register.spec.ts
β”‚   β”œβ”€β”€ πŸ“ e2e/                 # End-to-End integration
β”‚   β”‚   └── api-ui.spec.ts      # ⭐ Featured hybrid test
β”‚   └── πŸ“ ui/                  # UI tests
β”‚       β”œβ”€β”€ cart.spec.ts
β”‚       β”œβ”€β”€ checkout.spec.ts
β”‚       └── products.spec.ts
β”œβ”€β”€ πŸ“ .github/workflows/
β”‚   └── playwright.yml          # CI/CD pipeline
└── playwright.config.ts

πŸš€ Getting Started

Prerequisites

  • Node.js 18+
  • npm or yarn

Installation

# Clone the repository
git clone https://github.com/p0sadas/playwright-typescript-enterprise-framework.git

# Install dependencies
npm install

# Install Playwright browsers
npx playwright install

Running Tests

# Run all tests
npm test

# Run by tag
npm run test:smoke       # Quick sanity checks
npm run test:api         # API tests only
npm run test:regression  # Full regression suite
npm run test:critical    # Critical path tests

# Run by browser
npm run test:chromium
npm run test:firefox
npm run test:webkit

# Run with visible browser
npm run test:headed

# View test report
npm run report

πŸ› οΈ Tech Stack

Technology Purpose
Playwright Test Framework
TypeScript Type Safety
Node.js Runtime
GitHub Actions CI/CD

πŸ“Š Test Coverage

Suite Tests Tags
API Tests Login validation, Products API @api, @smoke, @regression
Auth Tests Login, Register, Logout @smoke, @regression
UI Tests Cart, Checkout, Products @smoke, @critical, @functional
E2E Tests API-UI Integration @api, @regression

πŸ‘¨β€πŸ’» Author

[Angel Posadas Ruano]


Built with ❀️ and β˜• by a QA Engineer passionate about test automation

Feel free to ⭐ this repository if you find it useful!

About

End-to-end QA Automation framework built with Playwright and TypeScript. Covers UI, API and hybrid tests using modern best practices: fixtures, tagging strategy (smoke/regression), cross-browser execution, GitHub Actions CI, trace & report analysis, and flakiness-resistant assertions.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors