Modern QA2026API Testing with `request` Fixture — tiles
Log inJoin
100 / 139 · 13 Browser Automation with Playwright · Network Mocking and API Testing← prev⊞ allnext →☰ Read as one page

11.4API Testing with `request` Fixture

Playwright's request fixture makes direct HTTP calls without a browser — ideal for API setup, teardown, and pure API testing.

test('API: create and retrieve a product', async ({ request }) => {
  // Create
  const createResponse = await request.post('/api/products', {
    data: { name: 'Widget', price: 9.99 },
  });
  expect(createResponse.status()).toBe(201);
  const product = await createResponse.json();

  // Retrieve
  const getResponse = await request.get(`/api/products/${product.id}`);
  expect(getResponse.status()).toBe(200);
  const retrieved = await getResponse.json();
  expect(retrieved.name).toBe('Widget');
});