TOPIC 19/6018 MINNOT STARTED

API testing with the request fixture

Call the Daily List server directly with Playwright's request fixture, check the answers, and use it to set up data fast.

L1–L4 are part of the Pro pass

L0 Explain simply

Analogy: phoning the kitchen instead of waiting for the waiter. The waiter carries an order to the kitchen. A phone call asks the kitchen a direct question. It is faster, and it still works when the waiter is having a bad day. It does not prove the waiter carried the plate.

Daily List is a to-do list app. The page is the waiter. The server behind it is the kitchen. Tom, the tester, wants to know the server can save a task. He does not need to click buttons for that.

What it is: Playwright is a library that drives a real browser. This slice is the , a helper that sends Hypertext Transfer Protocol (HTTP) calls with no page. The behind it remembers the base address and the headers. The nearest neighbour is the page itself, which is what you use when the bug is in the screen. Postman and curl are other neighbours: they send calls too, but they are not the test runner.

Why it matters: Some bugs never show in the browser, and some setup is painful to click. puts a task in place in a fraction of a second. A page test can then check what Lily sees, without repeating the create-task clicks.

A direct call proves the server answered. It does not prove the button works. Keep a browser test for the screen.

(SYNTHETIC / TRAINING ONLY: Daily List and every person named here are made up.)

PLAIN WORDS · 2 in this section
playwright
a free Microsoft tool that drives a browser for tests
hypertext
text that links to other pages

PICTURE IT

The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.

THE REAL JOB Testing the server directly, and setting up data fast, without going through the screens.

  1. Ask for the helper
  2. Send the call
  3. Check the status
  4. Read it back
Phone the kitchen

HOW THE PICTURE MAPS

How each part of the picture matches the software
In the pictureIn the software
The kitchenThe server
The waiterThe web page
Phoning the kitchenA direct call with the request fixture
The kitchen's answerThe status code and the body

WHERE THIS PICTURE STOPS

  • A phone call does not show whether the waiter carries the plate well. Direct calls cannot find a broken button.
  • A real kitchen has one phone line. A test can open many contexts.
  • The cooks can still burn the soup. A good status does not prove the data is right.

HOOK

Phone the kitchen.

REMEMBER IT THIS WAY

A rule of thumb: if you see this, think that.

If you only need to know the server can save a task, phone the kitchen instead of clicking through the page.

What each part of the trick stands for
In the trickWhat it stands for
Phone the kitchena direct call with the request fixture
Answerthe status code and the body

A direct call cannot show that the page itself looks right.

TELL A FRIEND

Phoning the kitchen to ask if it can make soup, instead of asking the waiter.

OFTEN MIXED UP WITH Designing API tests. application programming interface () test design says which cases to try. This lesson shows how to send them with Playwright.

Sources & standards — 5 sources
  1. Market practice

    Application programming interface (API) testing (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Shows the request fixture: a test takes request as an argument and calls post and get on it. Shows a base address and extra headers set in the config use block, and that an object passed as data is sent as JavaScript Object Notation (JSON). Says requests through the browser context share cookies with the page. Vendor documentation for one tool. Practitioner or vendor guidance, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

  2. Market practice

    APIRequestContext (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Request methods, failOnStatusCode, timeout, retries, cookie ownership and disposal. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Lists the methods get, post, put, patch, delete, head and fetch on the request context, with options such as data, params, headers and failOnStatusCode, and says a response object is returned for all status codes unless failOnStatusCode is set. Vendor documentation for one tool. Practitioner or vendor guidance, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: Request methods, failOnStatusCode, timeout, retries, cookie ownership and disposal. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

  3. Market practice

    APIResponseAssertions (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: toBeOK fixed response status. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Describes the toBeOK assertion on a response, which passes when the status code is in the 200 to 299 range, and its negated form. Vendor documentation for one tool. Practitioner or vendor guidance, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: toBeOK fixed response status. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

  4. Market practice

    Hypertext Transfer Protocol (HTTP) request methods (Mozilla developer docs) ↗ — Mozilla (MDN Web Docs) · What the request methods GET, POST, PUT, PATCH and DELETE mean (search excerpt, page not opened)

    Developer documentation. Describes GET as read only, POST as submit, PUT as replace and DELETE as remove. The search returned French and Spanish copies of this page. Search excerpt only. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  5. Market practice

    Playwright 1.65.0 response matcher implementation ↗ — Microsoft (Playwright) · Playwright v1.65.0 pinned source: toBeOK reads a captured APIResponse status once, accepts 200–299, and does not resend the request; toPass retries its callback. Inspected 6 November 2026; source contract, not an upstream execution claim.

    toBeOK reads a captured APIResponse status once, accepts 200–299, and does not resend the request; toPass retries its callback. · Checked 2026-11-06

    Actual pinned source section inspected during the completed v45 analysis. Framework source is Apache-2.0, distinct from the documentation CC BY 4.0 licence. Upstream tests were not executed.

PRACTISE AND KEEP

Sources for this topic — 6 sources
  1. Market practice

    Application programming interface (API) testing (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Shows the request fixture: a test takes request as an argument and calls post and get on it. Shows a base address and extra headers set in the config use block, and that an object passed as data is sent as JavaScript Object Notation (JSON). Says requests through the browser context share cookies with the page. Vendor documentation for one tool. Practitioner or vendor guidance, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

  2. Market practice

    APIRequestContext (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Request methods, failOnStatusCode, timeout, retries, cookie ownership and disposal. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Lists the methods get, post, put, patch, delete, head and fetch on the request context, with options such as data, params, headers and failOnStatusCode, and says a response object is returned for all status codes unless failOnStatusCode is set. Vendor documentation for one tool. Practitioner or vendor guidance, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: Request methods, failOnStatusCode, timeout, retries, cookie ownership and disposal. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

  3. Market practice

    APIResponseAssertions (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: toBeOK fixed response status. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Describes the toBeOK assertion on a response, which passes when the status code is in the 200 to 299 range, and its negated form. Vendor documentation for one tool. Practitioner or vendor guidance, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: toBeOK fixed response status. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

  4. Market practice

    Hypertext Transfer Protocol (HTTP) request methods (Mozilla developer docs) ↗ — Mozilla (MDN Web Docs) · What the request methods GET, POST, PUT, PATCH and DELETE mean (search excerpt, page not opened)

    Developer documentation. Describes GET as read only, POST as submit, PUT as replace and DELETE as remove. The search returned French and Spanish copies of this page. Search excerpt only. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  5. Market practice

    Request (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Request methods and postDataJSON. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Describes request.postDataJSON(), which returns the parsed body of a JSON or form-encoded request, and null when there is no body. Vendor documentation for one tool. Practitioner or vendor guidance, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: Request methods and postDataJSON. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

  6. Market practice

    Playwright 1.65.0 response matcher implementation ↗ — Microsoft (Playwright) · Playwright v1.65.0 pinned source: toBeOK reads a captured APIResponse status once, accepts 200–299, and does not resend the request; toPass retries its callback. Inspected 6 November 2026; source contract, not an upstream execution claim.

    toBeOK reads a captured APIResponse status once, accepts 200–299, and does not resend the request; toPass retries its callback. · Checked 2026-11-06

    Actual pinned source section inspected during the completed v45 analysis. Framework source is Apache-2.0, distinct from the documentation CC BY 4.0 licence. Upstream tests were not executed.

Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.