A comprehensive test automation framework built with Playwright and TypeScript, featuring both UI and API testing with Allure reporting.
- UI testing using Page Object Model (POM)
- API testing for REST endpoints
- TypeScript for type-safe tests
- Allure reports for detailed results
- Cross-browser support (Chromium, Firefox, WebKit)
- Parallel execution
- Node.js (v16 or higher)
- npm or yarn
- Clone the repository:
git clone <repository-url>
cd playwright-ui-api-framework- Install dependencies:
npm install- Install Playwright browsers:
npx playwright installplaywright-ui-api-framework/
|-- pages/ # Page Object Models
| |-- BasePage.ts # Base page with common methods
| |-- LoginPage.ts # Login page objects
| `-- ProductsPage.ts # Products page objects
|-- tests/ # Test specifications
| |-- ui/ # UI tests
| | |-- login.spec.ts # Login test scenarios
| | `-- products.spec.ts # Product page tests
| `-- api/ # API tests
| |-- auth.api.spec.ts # Posts API CRUD tests
| `-- users.api.spec.ts # Users API tests
|-- helpers/ # Helper functions
| |-- apiClient.ts # API client configuration
| `-- test-data.ts # Test data constants
|-- utils/ # Utility functions
| `-- logger.ts # Logging utility
|-- allure-results/ # Allure test results
|-- test-results/ # Playwright test results
|-- playwright.config.ts # Playwright configuration
|-- tsconfig.json # TypeScript configuration
`-- package.json # Project dependencies
npm testnpm run test:uinpm run test:apinpm run test:headednpx playwright test tests/ui/login.spec.tsnpx playwright test --debugnpm run typechecknpm run allure:generatenpm run allure:open- Jenkins: Nightly at 9:00 PM Africa/Johannesburg.
- GitHub Actions: Nightly at 9:00 PM Africa/Johannesburg (19:00 UTC).
- Login tests (5 scenarios)
- Products tests (7 scenarios)
- Posts API tests (8 scenarios)
- Users API tests (5 scenarios)
- Test directory: ./tests
- Timeout: 30 seconds
- Base URL: https://www.saucedemo.com
- Headless mode: enabled by default
- Screenshots: captured on failure
- Videos: recorded on failure
- Trace: retained on failure
- Reporters: list, Allure, HTML
- JSONPlaceholder: https://jsonplaceholder.typicode.com
- Override with API_BASE_URL environment variable
import { test, expect } from "@playwright/test";
import { LoginPage } from "../../pages/LoginPage";
test("Valid login", async ({ page }) => {
const login = new LoginPage(page);
await login.navigate("/");
await login.login("standard_user", "secret_sauce");
await expect(page).toHaveURL(/.*inventory.html/);
});import { test, expect } from "@playwright/test";
import { apiClient } from "../../helpers/apiClient";
test("Get users", async () => {
const api = await apiClient();
const response = await api.get("/users");
expect(response.status()).toBe(200);
await api.dispose();
});The framework uses the Page Object Model pattern for better maintainability:
export class LoginPage extends BasePage {
username = this.page.locator('#user-name');
password = this.page.locator('#password');
loginBtn = this.page.locator('#login-button');
async login(user: string, pass: string) {
await this.username.fill(user);
await this.password.fill(pass);
await this.loginBtn.click();
}
}- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License.
- Playwright Documentation: https://playwright.dev/
- TypeScript Documentation: https://www.typescriptlang.org/
- Allure Report: https://docs.qameta.io/allure/
- SauceDemo Test Site: https://www.saucedemo.com/
- JSONPlaceholder API: https://jsonplaceholder.typicode.com/
Created with care using Playwright and TypeScript.