PlaywrightAssertions
Source URL: https://playwright.dev/docs/api/class-playwrightassertions
PlaywrightAssertions | Playwright
섹션 제목: “PlaywrightAssertions | Playwright”Playwright gives you Web-First Assertions with convenience methods for creating assertions that will wait and retry until the expected condition is met.
Consider the following example:
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 will be re-testing the node with the selector .status until fetched Node has the "Submitted" text. It will be re-fetching the node and checking it over and over, until the condition is met or until the timeout is reached. You can pass this timeout as an option.
By default, the timeout for assertions is set to 5 seconds.
Methods
섹션 제목: “Methods”expect(response)
섹션 제목: “expect(response)”Added in: v1.18 playwrightAssertions.expect(response)
Creates a APIResponseAssertions object for the given APIResponse.
Usage
Arguments
responseAPIResponse#
APIResponse object to use for assertions.
Returns
expect(value)
섹션 제목: “expect(value)”Added in: v1.9 playwrightAssertions.expect(value)
Creates a GenericAssertions object for the given value.
Usage
expect(value);Arguments
Value that will be asserted.
Returns
expect(locator)
섹션 제목: “expect(locator)”Added in: v1.18 playwrightAssertions.expect(locator)
Creates a LocatorAssertions object for the given Locator.
Usage
Arguments
Locator object to use for assertions.
Returns
expect(page)
섹션 제목: “expect(page)”Added in: v1.18 playwrightAssertions.expect(page)
Creates a PageAssertions object for the given Page.
Usage
Arguments
Page object to use for assertions.
Returns