Skip to content

APIResponseAssertions ​

Added in: v1.18

The APIResponseAssertions class provides assertion methods that can be used to make assertions about the APIResponse in the tests.

js
import { test, expect } from '@playwright/test';

test('navigates to login', async ({ page }) => {
  // ...
  const response = await page.request.get('https://playwright.dev');
  await expect(response).toBeOK();
});

Methods ​

apiResponseAssertions.toBeOK() ​

Added in: v1.18 async

Ensures the response status code is within 200..299 range.

Usage

js
await expect(response).toBeOK();

Properties ​

apiResponseAssertions.not ​

Added in: v1.20

Makes the assertion check for the opposite condition.

Usage

For example, this code tests that the response status is not successful:

js
await expect(response).not.toBeOK();

Type

  • APIResponseAssertions

Released under the Apache 2.0 License.