To create a basic test assertion with @playwright/test, use the expect
function and choose a suitable matcher. For instance, if you want to check if a variable success
is truthy, write:
expect(success).toBeTruthy();
This assertion throws an error if success
is falsy.
For web-specific async matchers, use await
with expect
. To check if an element with test id 'status' has text 'Submitted', write:
await expect(page.getByTestId('status')).toHaveText('Submitted');
Playwright re-tests the element until the condition is met or a timeout occurs. The default timeout is 5 seconds, but you can configure it in your test configuration file or pass it directly when making assertions.
If you still have questions, please ask a question and I will try to answer it.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].