Skip to content

ShablaLab/playwright-api-example

Repository files navigation

Playwright REST API Tests Example

Project Description

This project contains automated tests for REST APIs using Playwright and Builder pattern. The tests are designed to ensure the reliability and correctness of the API endpoints. We have covered basic tests and assertions, and utilized fixtures to test the APIs. The project structure is designed to be easily extendable, allowing for scalable API testing.

Project Structure

The project structure is organized as follows:

playwright-api-example/
├── .github/
│   └── workflows/
│       └── playwright.yml
├── env/
│   ├── .env.dev
│   └── .env.sit
├── fixtures/
│   └── exampleFixture.js
├── tests/
│   ├── exampleTest.spec.js
│   └── anotherTest.spec.js
├── .nvmrc
├── package.json
├── playwright.config.js
└── README.md
  • .github/workflows/playwright.yml: Contains the GitHub Actions workflow configuration for CI.
  • env/: Directory for environment configuration files.
  • fixtures/: Directory for Playwright fixtures.
  • tests/: Directory for test specification files.
  • .nvmrc: Node.js version configuration file.
  • package.json: Project dependencies and scripts.
  • playwright.config.js: Playwright configuration file.

Getting Started

Prerequisites

  • Node.js (version specified in .nvmrc)
  • npm (Node Package Manager)

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/playwright-api-example.git
    cd playwright-api-example
  2. Install dependencies:

    npm install
  3. Set up the environment:

    • Create and configure your environment files in the env/ directory. For example, .env.dev and .env.sit.

Configuration

Environment Variables

Environment variables are managed using .env files located in the env/ directory. The environment file to be used is determined by the test_env environment variable. For example, to use the dev environment, set test_env=dev.

Playwright Configuration

The Playwright configuration is defined in playwright.config.js.

Running Tests

To run the tests, use the following commands:

  • npm run test: Run all tests.
  • npm run test:dev: Run tests in the DEV environment.
  • npm run report:html: Generate and open the HTML report.

Test Coverage as per Spec File

The test coverage is defined in the spec files located in the tests directory. Each spec file contains tests for specific API endpoints and scenarios.

Usage of Fixtures

Fixtures are used to set up the necessary preconditions and environment for the tests. They are defined in the fixtures directory and are automatically loaded by Playwright.

Deployment with GitHub Actions

The project is configured to run tests automatically using GitHub Actions. The workflow file .github/workflows/playwright.yml contains the configuration for the CI pipeline.

Linting

To lint the code, use the following commands:

  • npm run lint: Lint the code.
  • npm run lint:fix: Lint the code and automatically fix issues.

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue if you have any suggestions or improvements.

License

This project is licensed under the ISC License.

Keywords

  • Playwright
  • REST API Testing
  • JavaScript
  • TypeScript

This project is intended to provide a solid foundation for implementing automated API tests using Playwright and Builder pattern. By following the structure and guidelines provided, you can easily extend and customize the project to fit your specific testing needs.

About

Playwright API Tests Example

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published