Playwright API Testing — The Complete Guide (2026)
Skip Postman for automated checks — Playwright's request context runs API + UI tests in one runner, one report, and one CI job. Full setup, auth patterns, contract snapshots, and a worked login-to-checkout suite.

Last updated 2026-07-20 · 12 min read · By Avinash Kamble, reviewed by Priyanka G.
Playwright's request context is the most under-used API testing feature in QA. It gives you HTTP calls, shared auth state, and trace-viewer debugging inside the same runner as your UI tests — which means one report, one CI job, and no more "Postman collection last updated 2023" tickets.
Key takeaways
- Set up
request.newContext()in 5 lines.- Reuse the browser's auth cookies for API calls (no double login).
- Snapshot response contracts to catch breaking changes.
- A full login → create order → assert API + UI worked example.
1. Basic setup
import { test, expect } from '@playwright/test';
test('GET /api/health returns 200', async ({ request }) => {
const res = await request.get('/api/health');
expect(res.status()).toBe(200);
expect(await res.json()).toMatchObject({ status: 'ok' });
});The request fixture is built into every test — no plugin, no extra package.
2. Sharing auth with the browser
// global-setup.ts
import { request } from '@playwright/test';
export default async () => {
const ctx = await request.newContext();
const res = await ctx.post('/api/login', { data: { email, password } });
await ctx.storageState({ path: 'auth.json' });
};
// playwright.config.ts
use: { storageState: 'auth.json' }Now every UI test and every API test reuses the same session — no duplicate login, no flaky token expiry.
3. Contract snapshots
test('order response contract', async ({ request }) => {
const res = await request.post('/api/orders', { data: { sku: 'ABC', qty: 1 } });
expect(await res.json()).toMatchSnapshot('order.json');
});The first run writes the snapshot; every subsequent run fails on shape drift. Cheaper than a full Pact setup for internal APIs.
4. Login → API → UI worked example
test('checkout via API, verify in UI', async ({ page, request }) => {
const order = await request.post('/api/orders', {
data: { sku: 'ABC', qty: 2 },
});
const { id } = await order.json();
await page.goto(`/orders/${id}`);
await expect(page.getByRole('heading', { name: /order confirmed/i })).toBeVisible();
});See Playwright fixtures deep dive for how to wrap this in a fixture, and the locators guide for the UI half. Full docs: playwright.dev/docs/api-testing.
Frequently asked questions
1.Does this replace Postman entirely?
2.Can I use Playwright API testing without a browser?
3.How do I handle bearer tokens?
4.What about GraphQL?
Practice these questions
Drill 200+ Playwright questions with senior-SDET sample answers — locators, auto-wait, fixtures, parallelism and trace viewer.
Was this article helpful?
More from REST API Testing
REST fundamentals — verbs, status codes, contracts.
- Experience-Level QA InterviewsAPI Testing Interview Questions for 1 Year Experience (2026 Complete Guide)
- Experience-Level QA InterviewsAPI Testing Interview Questions for 3 Years Experience (2026 Complete Guide)
- Experience-Level QA InterviewsAPI Testing Interview Questions for Senior Level (2026 Complete Guide)
Keep building your QA edge
Pillar guides- Selenium PillarSelenium interview questions300 Selenium WebDriver Q&A — locators, waits, frameworks.
- Postman TutorialPostman tutorial for testersPostman from zero to CI — collections, scripts, Newman.
- Playwright Installation GuidePlaywright installation guide for beginnersInstall Playwright the right way — Node, browsers, VS Code, first test.
- cURL to Code Converterconvert cURL to Postman, Playwright, or Rest AssuredConvert any cURL command to Postman, Playwright, Rest Assured, k6, Cypress, Python, and more — free, in-browser.
- JSON / JSONPath / JMESPath Testertest JSONPath and JMESPath side by sideDual-engine JSONPath + JMESPath tester with assertion builder and Postman/Playwright/Rest Assured export.
- Postman to Code Converterconvert Postman collection to PlaywrightConvert any Postman collection into a full Playwright, Rest Assured, k6, Cypress, Supertest, Python, or Karate test suite — folders, pm.test assertions, and environments preserved.
Practice these questions live
Rehearse with an AI QA interviewer that scores your answers in real time.
Continue reading

Playwright Locator Best Practices (2026) — The Only Guide You Need
11 min read
How to Migrate a Postman Collection to Playwright API Tests (2026 Guide)
12 min read
Why Every QA Engineer Must Master CI/CD Pipelines in 2026 (Or Risk Obsolescence)
12 min readRelated concepts, tools & standards around Automation Testing
A quick reference of the people, companies, frameworks and technologies most often mentioned alongside Automation Testing in real QA teams — useful when you're mapping a learning path, preparing for interviews, or scoping a new project.
Join the QA Community
Connect with fellow testers, share job leads, and get career advice.
Stop Reinventing the Wheel. Upgrade Your QA Arsenal.
Take your testing skills from beginner to Lead Engineer. Supercharge your daily workflow with our premium digital resources.
- Ready-to-use testing strategy templates
- Advanced API & UI automation guides
- ⏱️ Save 10+ hours a week on test planning
Discussion
Ask a question, share your experience, or correct us. Be kind — real people are reading.