Skip to main content

APIResponseAssertions

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

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)

not_to_be_ok

Added in: v1.19 apiResponseAssertions.not_to_be_ok

The opposite of expect(response).to_be_ok().

使用方式

expect(response).not_to_be_ok()

傳回值


to_be_ok

Added in: v1.18 apiResponseAssertions.to_be_ok

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

使用方式

import re
from playwright.sync_api import expect

# ...
expect(response).to_be_ok()

傳回值