← Back to library
Playwrightwaitintermediatev1.20+

Wait for a network response

Wait for a specific API call to complete before asserting.

1test('waits for API before asserting', async ({ page }) => {
2  await page.goto('/dashboard');
3
4  // Wait for the API call triggered by the page load
5  const response = await page.waitForResponse(
6    (res) => res.url().includes('/api/dashboard') && res.status() === 200
7  );
8
9  const data = await response.json();
10  expect(data.items.length).toBeGreaterThan(0);
11});
#waitForResponse#network#async