跳至主要内容

APIResponseAssertions

APIResponseAssertions 类提供断言方法,可用于对测试中的 APIResponse 进行断言。

from playwright.sync_api import Page, expect

def test_navigates_to_login_page(page: Page) -> None:
# ..
response = page.request.get('https://playwright.net.cn')
expect(response).to_be_ok()

方法

not_to_be_ok

新增于:v1.19 apiResponseAssertions.not_to_be_ok

expect(response).to_be_ok() 相反。

用法

expect(response).not_to_be_ok()

返回值


to_be_ok

新增于:v1.18 apiResponseAssertions.to_be_ok

确保响应状态码在 200..299 范围内。

用法

import re
from playwright.sync_api import expect

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

返回值