How to Migrate a Postman Collection to Playwright API Tests (2026 Guide)
Step-by-step guide to migrating a Postman collection to Playwright API tests in 2026 — folders, pm.test assertions, auth, environment variables, and CI. Includes a free in-browser converter.

Last updated: July 17, 2026 · 12 min read · By Avinash Kamble, reviewed by Priyanka G.
Postman is where most API tests start — and it's where most of them quietly die. Collections don't diff cleanly in Git, they can't run in a typed IDE, and their assertion language (pm.test) is locked to the Postman runtime. If your team has more than fifty requests you actually care about, migrating them to a real test framework is the highest-leverage refactor you can do this quarter. This guide shows exactly how to move a Postman collection to Playwright API tests — the fastest path for most teams — using our free in-browser Postman to Code Converter.
Key takeaways
- Export your collection as v2.1 — v1 is deprecated and v2.0 lacks OAuth 2.0.
- Playwright's
APIRequestContextreplaces Postman's runtime; folders becometest.describeblocks.- Every
pm.testpattern has a one-line Playwright equivalent — status, JSON path, header, response time.- Use our converter to do 80% of the mechanical work in one click; refactor the remaining 20% by hand.
- Wire the migrated suite into CI with
npx playwright test --reporter=html,junit— one command, native GitHub / GitLab integration.
1. Why leave Postman for Playwright at all?
Postman is an excellent exploration tool. It's a mediocre test framework. The reasons show up around request #100:
- Git-hostile. Collection JSON is a machine format — every reorder, rename, or header tweak produces a giant diff no reviewer will read.
- No type safety. Your assertions run in a sandboxed JS runtime with no IntelliSense, no refactoring, no dead-code detection.
- Runner lock-in. Newman works, but it's a separate binary with its own reporter format and CI integration story.
- No shared test infrastructure with UI tests. If your team already uses Playwright for end-to-end, running API tests there means one runner, one report, one set of fixtures.
Playwright's API testing mode was purpose-built for this migration. It ships an APIRequestContext that speaks HTTP natively, integrates with the same test runner as your UI tests, and produces a proper HTML + JUnit report out of the box.
2. Prepare your collection for migration
Do these three things before you convert anything — they save hours of cleanup on the other side.
- Export as v2.1. In Postman, right-click the collection → Export → Collection v2.1. v2.0 lacks first-class OAuth 2.0 support; v1 was deprecated in 2018.
- Export the environment too. Environments → three-dot menu → Export. The converter can inline
{{variables}}if it has both files. - Delete dead requests. Every request you don't want in CI is code you'll have to delete twice. Prune the collection first.
If your collection has heavy pre-request scripts (dynamic tokens, HMAC signing, cascading data setup), skim them and note the ones that will need a hand-port. Simple ones — setting headers, generating timestamps, incrementing counters — port easily. Complex ones become Playwright fixtures.
3. Run the conversion (30 seconds)
Open our free Postman → Code Converter, drop in your collection JSON, pick Playwright TypeScript, and copy the output. That's it. The tool runs 100% in your browser — your collection never leaves your machine, which matters when the collection contains real staging tokens.
What the converter produces:
- One
.spec.tsfile per top-level folder (or one big file if you prefer — toggle in settings). test.describeblocks that mirror your Postman folder structure.- Every request wrapped in a
test()with the original request name. - All
pm.testassertions translated to Playwrightexpectcalls. - Auth headers regenerated using Playwright idioms.
- Environment variables extracted to a
constantsblock at the top with TODO markers if you didn't paste an environment file.
4. The pm.test → expect translation table
These are the six patterns that cover 95% of Postman assertions. Bookmark this section — it's the reference you'll need during the manual cleanup pass.
// Status code
// Postman:
pm.test("Status is 200", () => { pm.response.to.have.status(200); });
// Playwright:
expect(response.status()).toBe(200);
// Response time
// Postman:
pm.test("Under 500ms", () => { pm.expect(pm.response.responseTime).to.be.below(500); });
// Playwright:
expect(Date.now() - startTime).toBeLessThan(500);
// JSON body field
// Postman:
pm.test("Has user id", () => {
const json = pm.response.json();
pm.expect(json.user.id).to.eql(42);
});
// Playwright:
const body = await response.json();
expect(body.user.id).toBe(42);
// Header present
// Postman:
pm.test("CT header", () => { pm.response.to.have.header("Content-Type"); });
// Playwright:
expect(response.headers()['content-type']).toContain('application/json');
// Save value for the next request
// Postman:
pm.environment.set("authToken", pm.response.json().token);
// Playwright — use a Playwright fixture instead of shared state:
const { token } = await response.json();
// pass token via test.use({ extraHTTPHeaders }) or a custom fixture
// Contains substring
// Postman:
pm.expect(pm.response.text()).to.include("success");
// Playwright:
expect(await response.text()).toContain('success');The converter handles all six of these automatically — this table is for the edge cases and for reviewing the generated code so you understand what it's doing.
5. Handling auth — Bearer, OAuth 2.0, and API keys
Auth is the biggest source of hand-cleanup after conversion. Postman handles it as collection-level or folder-level configuration; Playwright expects it to be either per-request or attached via extraHTTPHeaders. Recommended pattern:
// playwright.config.ts — one place, one time
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
baseURL: process.env.API_BASE_URL ?? 'https://api.staging.example.com',
extraHTTPHeaders: {
Authorization: `Bearer ${process.env.API_TOKEN}`,
Accept: 'application/json',
},
},
});
// Any test — no auth boilerplate
test('list users', async ({ request }) => {
const res = await request.get('/users');
expect(res.ok()).toBeTruthy();
});For OAuth 2.0 client credentials flow, wrap the token fetch in a Playwright fixture that caches the token for the test run. Never re-fetch a token per test — it's the most common performance mistake in migrated suites.
6. Environments and data-driven tests
Postman environments become .env files. The converter extracts every {{variable}} into a constants block; move those to .env.staging, .env.prod, and load them with dotenv in your Playwright config. For data-driven tests (the equivalent of Postman's Collection Runner with a CSV), use test.describe.parallel with forEach:
const testCases = [
{ input: 'valid@example.com', expected: 200 },
{ input: 'not-an-email', expected: 400 },
{ input: '', expected: 400 },
];
for (const tc of testCases) {
test(`POST /validate — ${tc.input || 'empty'}`, async ({ request }) => {
const res = await request.post('/validate', { data: { email: tc.input } });
expect(res.status()).toBe(tc.expected);
});
}This is cleaner than Postman's CSV runner because the data lives in the same file as the test, participates in code review, and gets typed by TypeScript.
7. Wire it into CI in one command
The final step is the payoff. One command, one report, native CI integration:
# .github/workflows/api-tests.yml
name: API tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 20 }
- run: npm ci
- run: npx playwright install --with-deps
- run: npx playwright test --reporter=html,junit
env:
API_TOKEN: ${{ secrets.STAGING_API_TOKEN }}
- uses: actions/upload-artifact@v4
if: always()
with: { name: playwright-report, path: playwright-report }You get the Playwright HTML report as a downloadable artifact, JUnit XML for GitHub's native test summary, and free flake retry via retries: 2 in the config. Compare that to standing up Newman + a separate reporter + a separate artifact pipeline — the migration pays for itself in the first month.
8. Real-world gotchas you'll hit
Five things every team runs into. Handle them upfront:
- Chained requests that share state. Postman's
pm.environment.setpattern doesn't survive parallelism. Refactor into fixtures or run those specific specs withtest.describe.serial. - Dynamic timestamps. Move to a helper:
const now = () => new Date().toISOString(); - File uploads. Postman's form-data files become
{ multipart: { file: fs.createReadStream('./fixtures/x.pdf') } }. - Cookies. Use
request.storageState()or set them explicitly per request. - SSL / self-signed certs.
ignoreHTTPSErrors: truein the config — but only for staging, never for prod smoke tests.
FAQ — Postman to Playwright migration
Q: How long does a real migration take?
For a 200-request collection with well-named folders and standard auth, expect ~1 day of engineering time end-to-end: 30 minutes with the converter, half a day cleaning up auth and shared state, and half a day wiring CI and getting the first green run.
Q: Should I delete the Postman collection afterwards?
No — keep it as an exploration tool. Postman is still the fastest way to poke at a new endpoint. The migrated Playwright suite is your regression pack; the collection is your scratchpad.
Q: What if my team prefers Rest Assured or k6?
The converter supports both. Rest Assured is the right pick for Java + Maven shops; k6 is the right pick if you want the same specs to double as load tests.
Q: Does this work for GraphQL?
Yes. Playwright's request.post() handles GraphQL requests the same as any other JSON POST. The converter emits them correctly.
Q: How does this compare to the Postman-provided export?
Postman's built-in "Generate code snippet" gives you a single request in isolation — no assertions, no folder structure, no auth handling. This tool operates at the collection level and preserves the whole test intent.
Next steps
Ready to ship the migration?
- Convert your collection with the free Postman → Code Converter (in-browser, no signup).
- Pair it with the cURL → Code Converter for one-off requests from Chrome DevTools.
- Deepen your Postman knowledge with the Postman interview questions hub.
- Prep for API testing rounds with the API testing interview questions.
- Level up locators for UI tests with Playwright Locator Best Practices (2026).
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 Postman Automation
Collections, environments, Newman in CI.
Keep building your QA edge
Pillar guides- Selenium PillarSelenium WebDriver guide300 Selenium WebDriver Q&A — locators, waits, frameworks.
- Postman Tutoriala complete Postman walkthroughPostman from zero to CI — collections, scripts, Newman.
- Playwright Installation Guidehow to install Playwright step by stepInstall 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 TesterSoftwareTestPilot's JSON testerDual-engine JSONPath + JMESPath tester with assertion builder and Postman/Playwright/Rest Assured export.
- Postman to Code ConverterPostman collection to code converterConvert 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
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


