PlaywrightAssertions
Added in: v1.17Playwright 为您提供 Web 优先断言,它具有便捷的方法来创建将等待并重试直到满足预期条件的断言。
考虑以下示例:
js
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 秒。
方法
playwrightAssertions.expect()
Added in: v1.18为给定的 APIResponse 创建 APIResponseAssertions 对象。
用法
参数
用于断言的 APIResponse 对象。
返回值
APIResponseAssertions
playwrightAssertions.expect()
Added in: v1.9为给定值创建 GenericAssertions 对象。
参数
返回值
GenericAssertions
playwrightAssertions.expect()
Added in: v1.18为给定的 Locator 创建 LocatorAssertions 对象。
用法
参数
用于断言的 Locator 对象。
返回值
LocatorAssertions
playwrightAssertions.expect()
Added in: v1.18为给定的 Page 创建 PageAssertions 对象。
用法
参数
用于断言的 Page 对象。
返回值
PageAssertions