arrow-left Back to topicQuizAPI testingCheck yourself1.Why use API calls to seed test data instead of driving the UI?API calls are more readable than UI interactionsAPI calls are 10-50x faster and don't need a visible browserAPI calls automatically clean up test data after the test2.What does the request fixture in Playwright Test provide?An object to intercept browser network requests via page.route()An APIRequestContext that can make HTTP requests (GET, POST, PUT, DELETE) directly from Node.jsA mock server that replaces the real backend automaticallyA reference to the browser's fetch() function3.Where do you configure the base URL so that request.get('/api/orders') resolves to the correct host?Pass it as the first argument to every request call: request.get('https://app.example.com/api/orders')Set baseURL in playwright.config.ts under the use keySet process.env.BASE_URL in the test filerequest fixture always requires absolute URLs4.What does request.post('/api/orders', { data: { item: 'Laptop' } }) return?The parsed JSON body of the response directlyAn APIResponse object — you need to call response.json() or response.text() to read the bodyA Promise<boolean> indicating success or failureThe HTTP status code as a number5.What is the difference between the request fixture and request.newContext() (also imported as playwright.request.newContext())?They are identical — newContext() is just an aliasThe request fixture shares cookies with the browser context; newContext() creates an isolated context with its own cookie jar and headersnewContext() supports POST requests; the fixture only supports GETThe request fixture requires a browser; newContext() does not6.How do you check that an API response returned HTTP 201 Created?expect(response).toBe(201)expect(response.status()).toBe(201)expect(response.ok()).toBe(201)expect(await response.json().status).toBe(201)7.You need to authenticate with a token and make API calls without a browser in a global setup file. What do you use?The request fixture — it works in globalSetup tooimport { request } from '@playwright/test'; const apiCtx = await request.newContext({ extraHTTPHeaders: { Authorization: 'Bearer token' } })Use Node.js fetch() — Playwright API testing only works inside test() blocksLaunch a browser with request.newBrowser() and use page.goto() for API calls8.After your UI test deletes an order, how do you verify on the server side that the record is actually gone?Check that the row is not visible on the page with expect(page.getByText(orderId)).not.toBeVisible()Make a GET request to /api/orders/:id using the request fixture and assert response.status() is 404Reload the page and check localStorageTrust the UI — if the row disappears, the server must have deleted itSubmit answersarrow-left PreviousMock APIsAuthenticationNext arrow-right