BrauzerLab
← Back to missions 44 / 50

Mock an API

Hard ~300 sec

API mocking means replacing the real API with a fixed response (a fixture). This technique makes tests deterministic: the username will be the same every time.

Pass contentType: 'application/json' and a JSON string as body into route.fulfill. For example '{"name":"Test User"}' — the UI will write that name into the #username element.

page is already available. Intercept the /api/user request and return a JSON response containing the name "Test User". Then click the «Load profile» button.

Several URL patterns and JSON structures are accepted — as long as the name key is "Test User".

TASK

Replace the API response with fixture data.

Provided for you
import { test, expect } from '@playwright/test';

test('Mock an API', async ({ page }) => {
  await page.goto('https://lab.local/mission/mock-api');
  // ↓ Your code goes below ↓
});
Editor
https://lab.local/mission/mock-api
Loading...
Results will appear here — press Run or Check.