PlaywrightAssertions
Playwright 为您提供了 Web-First Assertions(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)
Added in: v1.18为给定的 APIResponse 创建一个 APIResponseAssertions 对象。
用法
参数
-
response
APIResponse#用于断言的 APIResponse 对象。
返回值
expect(value)
Added in: v1.9为给定值创建一个 GenericAssertions 对象。
用法
expect(value);
参数
返回值
expect(locator)
Added in: v1.18为给定的 Locator 创建一个 LocatorAssertions 对象。
用法
参数
返回值
expect(page)
添加于: v1.18为给定的 Page 创建一个 PageAssertions 对象。
用法
参数
返回值