This repository contains a suite of Playwright tests designed to validate the functionality of a GraphQL API. The tests cover various operations, including fetching posts, creating, updating, and deleting posts. The tests are written in TypeScript and use the Playwright framework.
-
Install dependencies:
npm install
npm init playwright@latest
npm install faker
npm install @estruyf/github-actions-reporter
-
Ensure you have a running instance of the GraphQL API to test against.
https://graphqlzero.almansi.me/api
To run the tests, use the following command:
npx playwright test
The tests are tagged with @slow
and @smoke
to allow for selective execution.
npx playwright test --grep @smoke
This test fetches posts by their ID and validates the response time and data structure. It ensures the response times are within acceptable limits and that the post data matches the expected structure.
This test creates a new post using the CreatePost
mutation and validates that the post is created successfully with the expected title and body.
This test updates an existing post's body using the UpdatePost
mutation and validates that the update is reflected correctly.
This test deletes a post using the DeletePost
mutation and validates that the post is deleted by attempting to fetch it afterward.
fetchTotalCount
: Fetches the total count of posts from the GraphQL API.fetchRandomSinglePost
: Fetches a random single post by its ID from the GraphQL API.
GetSinglePost
: GraphQL query for fetching a single post by ID.CreatePost
: GraphQL mutation for creating a new post.UpdatePost
: GraphQL mutation for updating an existing post.DeletePost
: GraphQL mutation for deleting a post.
tests/
: Contains the test files.graphql/schemas/queries.spec.ts
: Contains GraphQL queries.graphql/schemas/mutations.spec.ts
: Contains GraphQL mutations.graphql/helpers/
: Contains helper functions for fetching data.
During the tests, response times and failed requests are logged to the console for performance analysis.
Tests run automatically on PR
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
Custom playwright reporter by @estruyf