Playwright断言
Playwright 为您提供“Web优先”断言,并附带方便的方法来创建断言,这些断言将等待并重试直到满足预期条件。
考虑以下示例
import { test, expect } from '@playwright/test';
test('status becomes submitted', async ({ page }) => {
// ...
await page.locator('#submit-button').click();
await expect(page.locator('.status')).toHaveText('Submitted');
});
Playwright 将使用选择器 .status
重新测试节点,直到获取到的节点具有 "Submitted"
文本。它将一遍又一遍地重新获取节点并检查它,直到满足条件或达到超时。您可以将此超时作为选项传递。
默认情况下,断言的超时设置为 5 秒。
方法
expect(response)
新增于:v1.18为给定的 APIResponse 创建一个 APIResponseAssertions 对象。
用法
参数
-
response
APIResponse#用于断言的 APIResponse 对象。
返回值
expect(value)
新增于:v1.9为给定的值创建一个 GenericAssertions 对象。
用法
expect(value);
参数
返回值
expect(locator)
新增于:v1.18为给定的 Locator 创建一个 LocatorAssertions 对象。
用法
参数
返回值
expect(page)
新增于:v1.18为给定的 Page 创建一个 PageAssertions 对象。
用法
参数
返回值