Playwright-Interview is an end-to-end (E2E) testing framework built using Playwright. It includes test automation for flight booking scenarios, authentication handling, API validation, and response mocking. The project is structured with fixtures, a global setup, and a base page model to enable modular and reusable test cases.
- Parallel Execution: Tests are executed in parallel for efficiency.
- Shared Authentication Storage: Uses
auth.jsonto maintain authentication state. - E2E Flight Booking Tests: Automates booking flights between London and Barcelona.
- API Validation: Validates backend responses.
- Request Interception & Mocking: Intercepts and mocks API responses dynamically.
- Page Object Model (POM): Uses reusable page objects for better test maintainability.
- Global Setup: Handles authentication state setup before running tests.
Playwright-interview/
├── src/
│ ├── pages/
│ │ ├── base.page.ts
│ │ ├── login.page.ts
│ │ ├── flight.page.ts
│ ├── e2e/
│ │ ├── flight-booking.e2e.ts
├── app.fixture.ts
├── config.ts
├── global-setup.ts
├── README.md
npm installnpx playwright testnpx playwright test --workers=4npx playwright show-reportConfiguration is handled in config.ts, specifying settings such as parallel execution, retries, and browsers.
Before running tests, authentication is handled using global-setup.ts, which:
- Launches a browser.
- Logs in using an authentication token.
- Stores the authentication state in
auth.json.
Tests verify:
- Flight details are correctly filled and submitted.
- Booking completion is validated via UI.
- API contains expected data.
- Mocked responses are applied correctly.
- Retrieves objects from
https://api.restful-api.dev/objects. - Ensures the backend contains exactly three objects with "Air" in the name.
- Intercepts
https://jsonplaceholder.typicode.com/todos/1. - Mocks the response with a custom title.
The app.fixture.ts file extends Playwright’s test framework to include:
LoginPageFlightPage
The BasePage class provides:
- Page navigation and verification.
- Abstract
elementsproperty for extending page objects.
- Additional test cases for other booking scenarios.
- Support for mobile browsers.
- Extended API validation tests.