PlaywrightAssertions
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对象。
用法
参数
返回