APIResponseAssertions
Added in: v1.18The APIResponseAssertions class provides assertion methods that can be used to make assertions about the APIResponse in the tests.
python
from playwright.async_api import Page, expect
async def test_navigates_to_login_page(page: Page) -> None:
# ..
response = await page.request.get('https://playwright.dev')
await expect(response).to_be_ok()python
from playwright.sync_api import Page, expect
def test_navigates_to_login_page(page: Page) -> None:
# ..
response = page.request.get('https://playwright.dev')
expect(response).to_be_ok()Methods
api_response_assertions.not_to_be_ok()
Added in: v1.19The opposite of api_response_assertions.to_be_ok().
api_response_assertions.to_be_ok()
Added in: v1.18Ensures the response status code is within 200..299 range.
Usage
python
from playwright.async_api import expect
# ...
await expect(response).to_be_ok()python
import re
from playwright.sync_api import expect
# ...
expect(response).to_be_ok()