This repository contains a Playwright automation framework written in TypeScript. It demonstrates QA automation best practices with UI and API tests for the Automation Testing Online website.
.
├── tests/
│ ├── api/
│ │ └── booking.spec.ts # API tests for booking endpoints
│ ├── ui/
│ │ ├── positive.spec.ts # Positive UI test (successful booking)
│ │ └── negative.spec.ts # Negative UI test (validation failure)
│ ├── pages/
│ │ └── HotelBookingPage.ts # Page Object Model for booking page
│ └── utils/
│ ├── ApiHelper.ts # API request utilities
│ └── TestDataGenerator.ts # Test data generation utilities
├── playwright.config.ts # Playwright configuration
├── tsconfig.json # TypeScript configuration
├── package.json # Project dependencies
└── README.md # This file
-
Positive Test -
[POSITIVE] Should successfully book a room with valid details- Fills out the booking form with valid data
- Submits the booking
- Verifies a success confirmation message is displayed
-
Negative Test -
[NEGATIVE] Should fail to book with missing required phone number- Attempts to submit a booking without the required phone number
- Verifies HTML5 form validation prevents submission
-
Get All Bookings -
[API] Should retrieve all bookings from the API- Fetches all bookings from the API
- Verifies response structure and data integrity
-
Get Single Booking -
[API] Should retrieve a specific booking by ID- Retrieves a booking by its ID
- Verifies booking details are accurate
-
Create Booking -
[API] Should create a new booking via API- Creates a new booking through the API
- Verifies the booking is created with correct details
- Node.js (version 16 or higher)
- npm (comes with Node.js)
-
Clone the repository (if you haven't already):
git clone https://github.com/Velir/Velir.QA.TakeHome.git cd Velir.QA.TakeHome -
Install dependencies:
npm install
-
Install Playwright browsers (done automatically during npm install):
npx playwright install
npm testnpm run test:uinpm run test:headednpm run test:debugnpm run test:reportnpx playwright test tests/ui/positive.spec.tsnpx playwright test -g "Should successfully book"After running tests, results are generated in:
- HTML Report:
playwright-report/index.html - Test Results:
test-results/directory
View the HTML report with:
npm run test:reportTests run across three browsers by default (configured in playwright.config.ts):
- Chromium
- Firefox
- WebKit (Safari)
To run tests on a single browser:
npx playwright test --project=chromium- Base URL:
https://automationintesting.online/ - Retries: 2 retries in CI environment
- Screenshots: Captured on failure only
- Videos: Retained on failure only
- Traces: Captured on first retry for debugging
- HotelBookingPage.ts - Encapsulates all page interactions and selectors
- Provides reusable methods for form filling and assertions
- Separates test logic from page element selectors
- ApiHelper.ts - Centralized API request methods
- Handles HTTP requests (GET, POST, DELETE)
- Consistent error handling and response parsing
- TestDataGenerator.ts - Utilities for generating test data
- Ensures unique data per test run
- Date calculation helpers
- Create a new
.spec.tsfile intests/ui/ - Import the
HotelBookingPageand test utilities - Write your test following the AAA pattern (Arrange, Act, Assert)
Example:
import { test, expect } from '@playwright/test';
import { HotelBookingPage } from '../pages/HotelBookingPage';
test.describe('My Test Suite', () => {
test('My new test', async ({ page }) => {
const bookingPage = new HotelBookingPage(page);
// Your test here
});
});- Add a new method to
ApiHelper.tsif needed - Create a test in
tests/api/booking.spec.ts - Use the
ApiHelpermethods to make requests
Example:
const response = await ApiHelper.getBookingById(123);
expect(response.bookingid).toBe(123);- Create a new class in
tests/pages/ - Define selectors as class properties
- Create methods for page interactions
- Import and use in your tests
npm install
npx playwright installMake sure browsers are installed:
npx playwright install --with-depsIf tests fail due to port conflicts, update the playwright.config.ts with a different port.
Verify the API endpoint is accessible:
curl -X GET https://automationintesting.online/booking/This framework is ready for CI/CD pipelines. In CI environments:
- Tests run with 2 retries
- Tests run sequentially (1 worker)
- HTML reports are generated for review
For questions about the framework or to expand the test suite, refer to the code comments and test examples included in the repository.
Happy Testing! 🚀