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.
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.
- Node.js (version specified in
.nvmrc) - npm (Node Package Manager)
-
Clone the repository:
git clone https://github.com/yourusername/playwright-api-example.git cd playwright-api-example -
Install dependencies:
npm install
-
Set up the environment:
- Create and configure your environment files in the
env/directory. For example,.env.devand.env.sit.
- Create and configure your environment files in the
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.
The Playwright configuration is defined in playwright.config.js.
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.
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.
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.
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.
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.
Contributions are welcome! Please feel free to submit a pull request or open an issue if you have any suggestions or improvements.
This project is licensed under the ISC License.
- 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.