Skip to content

End-to-end API test automation framework for Restful Booker built with Playwright and JavaScript. Covers full CRUD, auth, schema validation, reusable payloads, and CI integration with GitHub Actions and Allure reporting.

Notifications You must be signed in to change notification settings

anandavii/api-testing-restful-booker

Repository files navigation

API Test Automation for Restful Booker using Playwright

Playwright Node.js version Secrets Managed Build Status Last commit

Overview

This repository contains an API Test Automation Framework built using Playwright and JavaScript to test the Restful Booker API. It includes full coverage of key REST operations such as authentication, booking creation, updates, deletions, and schema validations. The project is structured for clarity and maintainability, with reusable helpers, external JSON payloads, and integration with GitHub Actions for CI.

Goals of this Framework

  • Automate complete API workflows using Playwright’s request context
  • Validate HTTP methods: GET, POST, PUT, PATCH, DELETE
  • Support token-based authentication and protected endpoint handling
  • Use .env for managing secrets and environment-specific values
  • Ensure schema, data, and type validations using expect().toMatchObject()
  • Keep test code DRY and modular using helper functions and JSON fixtures
  • Generate rich HTML and Allure reports
  • Enable GitHub Actions for continuous integration

What’s Implemented So Far

Restful Booker API Test Coverage

  • GET Requests

    • Fetch all booking IDs
    • Get booking by ID
    • Filter bookings by name
  • POST Requests

    • Create a new booking (using inline and external JSON)
    • Assert structure and values in response
  • PUT Requests

    • Update booking fully using PUT with auth token
    • Validations done using external JSON payload
  • PATCH Requests

    • Partially update a booking with selective fields
    • Assert only changed fields, leave rest untouched
  • DELETE Requests

    • Create and then delete a booking with token
    • Assert status code and empty response
  • Token Handling

    • Request and reuse authorization tokens from /auth for protected endpoints
  • Data Reuse

    • Use external .json files for payloads
    • Use utility functions to reduce duplication across tests
  • Environment Variable Support

    • Sensitive values like usernames and passwords are managed using a .env file for local runs
    • GitHub Actions uses repository secrets to inject these securely during CI runs

Usage

  1. Install dependencies
    npm install

  2. Run all tests
    npx playwright test

  3. View the HTML report
    npx playwright show-report

Project Highlights

  • Framework: Playwright (JavaScript)
  • Test Type: REST API Automation
  • APIs Tested: Restful Booker
  • Language: JavaScript (CommonJS / ESModule)
  • Config: .env for local and secrets for CI
  • Runner: Playwright Test Runner
  • Reporting: Allure Reports and Playwright HTML

Allure Reports Allure

Step 1: Use the following command to generate the Allure report:

    allure generate target/allure-results --clean -o allure-report
  • This command will create a detailed HTML report in the allure-report directory.

Step 2: To view the report in your browser, use:

    allure serve target/allure-results
  • This will start a local server and open the Allure report in your default browser.

To clear previous results:

    rm -rf target/allure-results

GitHub Actions CI

This project uses GitHub Actions for automated test execution and manual workflow triggering.

  • The GitHub Actions workflow (.github/workflows/playwright.yml) is configured with workflow_dispatch to support manual test runs.
  • Supports manual trigger of workflow from the GitHub Actions tab by clicking the “Run workflow” button.
  • Automatic triggers on push and pull_request is added for automatic workflow runs.

Next Steps

  • Add .env support for base URLs and secrets
  • Improve error handling and add edge cases
  • Add retry strategies and trace analysis for failed tests
  • Refactor all CRUD logic into reusable helper modules

About

End-to-end API test automation framework for Restful Booker built with Playwright and JavaScript. Covers full CRUD, auth, schema validation, reusable payloads, and CI integration with GitHub Actions and Allure reporting.

Topics

Resources

Stars

Watchers

Forks