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()
from playwright.async_api import Page, expect
async def test_navigates_to_login_page(page: Page) -> None:
# ..
response = await page.request.get('https://playwright.net.cn')
await expect(response).to_be_ok()
方法
not_to_be_ok
新增于:v1.19与 expect(response).to_be_ok() 相反。
用法
expect(response).not_to_be_ok()
返回值
to_be_ok
新增于:v1.18确保响应状态码在 200..299
范围内。
用法
- 同步
- 异步
import re
from playwright.sync_api import expect
# ...
expect(response).to_be_ok()
from playwright.async_api import expect
# ...
await expect(response).to_be_ok()
返回值