A robust, easy-to-use API testing framework built with Playwright and TypeScript. Designed for QA engineers and developers.
- Minimal code required for API tests
- Built-in authentication helpers
- Comprehensive assertion helpers
- Faker integration for test data
- Positive & negative testing support
- TypeScript support
- Parallel execution and reporting
src/
  |- helpers/         # Assertion and utility helpers
  |- tests/           # Test files
    |- orders	      # Order Test cases
    |- products	      # Product Test cases
    |- users	      # User Test cases
playwright.config.ts
package.json
tsconfig.json
- Download and install Node v18+ for your device
- Install pnpm
npm i -g pnpm- Clone the repo
git clone <repository-url>
cd playwright-api-testing- Install dependencies
pnpm i- Install Playwright browsers
pnpm exec playwright install --with-deps- Copy .env.exampleand create.env
cp .env.example .envExample test:
import { test } from "@playwright/test";
import { post } from "../helpers/requestHelper";
import {
  expectStatus,
  expectSuccess,
  expectBodyContains,
  expectBodyDoesNotContain,
} from "../helpers/assertions";
test("should create a new user", async ({ request }) => {
  const userData = { name: "John Doe" };
  const response = await post(request, "/users", userData);
  await expectStatus(response, 201);
  await expectSuccess(response);
  await expectBodyContains(response, { name: "John Doe" });
  await expectBodyDoesNotContain(response, { error: "message" });
});await expectStatus(response, 200);
await expectStatusIn(response, [200, 201]);
await expectSuccess(response);
await expectFailure(response);
await expectBodyContains(response, { key: "value" });
await expectBodyDoesNotContain(response, { key: "unexpected" });
await expectApiSuccess(response);
await expectApiFailure(response);
await expectApiMessage(response, "Operation Successful.");
await expectBodyContains(response, {
  message: "Operation Successful.",
});
await expectBodyDoesNotContain(getProductResponse, { stock: 210 });
await expectHeader(response, "Content-Type", "application/json");
await expectHeaderContains(response, "X-Custom", "value");
await expectHeaderExists(response, "X-Header");
await expectHeaderDoesNotContain(response, "X-Header", "unexpected");
await expectContentType(response, "application/json");
await expectJsonContentType(response);pnpm exec playwright test
pnpm exec playwright show-reportAdd console logs in your tests as needed:
console.log("Response body:", await response.text());Run in debug mode:
pnpm exec playwright test --debug- Clone the repository
- Create a feature branch
- Commit and push your changes
- Open a Pull Request
// GET request
const response = await get(request, "/users/123");
// POST request
const response = await post(request, "/users", userData);
// PUT request
const response = await put(request, "/users/123", updatedData);
// PATCH request
const response = await patch(request, "/users/123", patchData);
// DELETE request
const response = await del(request, "/users/123");
// Custom headers
const response = await post(request, "/users", userData, {
  "X-Custom-Header": "value",
});After test execution, open the HTML report:
pnpm exec playwright show-reportThe request URL, headers, method and response body are logged by default in the console for easier debugging.
pnpm exec playwright test --debugtest("debug test", async ({ request }) => {
  const response = await makePostRequest(request, "/users", userData);
  console.log("Response status:", response.status());
  console.log("Response body:", await response.text());
});The sample tests in this project are based on my another project called sample-api. Feel free to try out.