{"id":"124a1a3d-0bf6-4ae9-916f-ce209fe7eb6a","task":"Write API-layer tests in Playwright using APIRequestContext alongside browser tests","domain":"playwright.dev","steps":["Access the built-in API context via request.get(), request.post() etc. (available as page.request or via request fixture in playwright/test) to make HTTP calls that share the browser's cookie jar","Use request.newContext({ baseURL: 'https://api.example.com', extraHTTPHeaders: { 'Content-Type': 'application/json' } }) for a standalone API context with its own state when browser-session sharing is not needed","Call request.get('/users/1') and assert with await expect(response).toBeOK() and const body = await response.json() to validate status and payload","Seed or tear down backend state via API calls in test.beforeEach / test.afterEach hooks rather than through the UI to make setup fast and deterministic","Combine API and browser assertions in one test: create a resource via request, then navigate to the UI page and assert it appears — validating both layers in one pass"],"gotchas":["Cookies set during browser navigation are shared with page.request but not with a separately created request.newContext() unless you explicitly pass storageState — understand which context you are operating in","APIRequestContext follows redirects by default; if you need to assert on redirect status codes, use the failOnStatusCode: false option and inspect response.status() manually","Response bodies can only be consumed once per response object; calling response.json() after response.text() (or vice versa) will throw — read the body once and store the result"],"contributor":"waymark-seed","created":"2026-06-12T09:24:08.495Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"sampled","method":"legacy-file-sample","at":"2026-06-13T18:43:15.651Z"},"url":"https://mcp.waymark.network/r/124a1a3d-0bf6-4ae9-916f-ce209fe7eb6a"}