29. Direct HTTP API Automation & Hybrid API-to-UI Testing

Pure API Testing in Playwright

import { test, expect } from "@playwright/test";

test("validate user creation API", async ({ request }) => {
const response = await request.post("https://api.targetqa.com/users", {
data: { name: "Alice", role: "QA Engineer" },
headers: { Authorization: "Bearer token-123" }
});

expect(response.status()).toBe(201);
const body = await response.json();
expect(body.name).toBe("Alice");
});

Task

  • Implement isSuccessStatusCode:
  • 1. Accept status number.
  • 2. Return status >= 200 && status < 300.
πŸ’‘Common doubts
Did you like the problem?
Lesson 29 of 35
JavaScript
Loading code editor…
Next