APIResponseAssertions
APIResponseAssertions 类提供了断言方法,可用于在测试中对 APIResponse 进行断言。
¥The APIResponseAssertions class provides assertion methods that can be used to make assertions about the APIResponse in the tests.
- Sync
- Async
from playwright.sync_api import Page, expect
def test_navigates_to_login_page(page: Page) -> None:
# ..
response = page.request.get('https://playwright.nodejs.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.nodejs.cn')
await expect(response).to_be_ok()
方法
¥Methods
not_to_be_ok
Added in: v1.19与 expect(response).to_be_ok() 相反。
¥The opposite of expect(response).to_be_ok().
用法
¥Usage
expect(response).not_to_be_ok()
返回
¥Returns
to_be_ok
Added in: v1.18确保响应状态代码在 200..299
范围内。
¥Ensures the response status code is within 200..299
range.
用法
¥Usage
- Sync
- Async
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()
返回
¥Returns