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
| 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 |
This test demonstrates a sophisticated hybrid testing approach that combines API efficiency with UI verification
Traditional UI login tests are slow and fragile. What if we could authenticate via API and then validate the session in the browser?
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();
});βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 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 β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
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
- Node.js 18+
- npm or yarn
# Clone the repository
git clone https://github.com/p0sadas/playwright-typescript-enterprise-framework.git
# Install dependencies
npm install
# Install Playwright browsers
npx playwright install# 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| 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 |
[Angel Posadas Ruano]
Built with β€οΈ and β by a QA Engineer passionate about test automation
Feel free to β this repository if you find it useful!