Skip to content

Repository files navigation

Playwright API Testing Practice

A ready-to-use framework template for the practice assignments of the Playwright API Testing Mastery program by Bondar Academy.

Everything is already configured — you only need to add your credentials to the .env file and start working on the practice assignments.

Application Under Test

Tests run against the PetClinic REST API:

Use the Swagger page to explore the available endpoints, request/response payloads and status codes while working on the assignments.

Setup

  1. Clone this repository and open it in your editor.
  2. Install the project dependencies:
    npm install
  3. Create a .env file in the root of the project. Use .env-SAMPLE as an example.
  4. Update the .env file with your valid Bondar Academy credentials:
    USERNAME='test@test.com'
    PASSWORD='Welcome1'
    
  5. Run the sample test to make sure everything works:
    npx playwright test

Note: the .env file is listed in .gitignore, so it is never version controlled. Your credentials stay on your local machine and are not shared or exposed in the repository.

Running the Tests

# run all tests
npx playwright test

# run a single test file
npx playwright test tests/practiceTest.spec.ts

# run tests matching a title
npx playwright test -g 'Sample PetClinic Test'

# open the HTML report of the last run
npx playwright show-report

Project Structure

├── tests/                  # your practice assignment tests
│   └── practiceTest.spec.ts
├── utils/
│   ├── fixtures.ts         # custom test fixtures (api, config, authToken)
│   ├── request-handler.ts  # fluent API request builder
│   ├── custom-exptect.ts   # custom assertions with API activity logs
│   ├── schema-validator.ts # AJV based JSON schema validation
│   └── logger.ts           # request/response logger
├── helpers/
│   └── createToken.ts      # authentication token generation
├── response-schemas/       # generated JSON schemas
├── api-test.config.ts      # API URL and credentials configuration
└── playwright.config.ts    # Playwright configuration

Writing Tests

Import the test from the project fixtures and the expect from the custom expect, then use the api fixture to build requests. The auth token is created once per worker and attached to every request automatically.

import { test } from '../utils/fixtures';
import { expect } from '../utils/custom-exptect';

test('Sample PetClinic Test', async ({ api }) => {
    const ownersResponse = await api
        .path('/owners')
        .getRequest(200)
    expect(ownersResponse[0].firstName).toEqual('George')
})

Learn more about the program: Playwright API Testing Mastery

About

Bondar Academy. Project template for practice assignments at Playwright API Testing Mastery program

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages