Sure, you can easily verify that all requests are sent when the test is finished using Playwright's auto-waiting feature and built-in assertions.
Playwright's auto-waiting feature ensures that all actions and requests are completed before moving on to the next step in the test. This means you don't have to explicitly wait for each request to finish before proceeding with your assertions.
import { test } from '@playwright/test';
test('auto-waiting example', async ({ page }) => {
await page.goto('https://ray.run/');
await page.click('button'); // Playwright waits for the click action and any resulting network requests to complete
});
Playwright also provides various assertions to verify the state of elements or data after performing an action. These assertions allow you to check if an element is visible, has specific text content, or has certain attributes.
import { test } from '@playwright/test';
test('assertion example', async ({ page }) => {
await page.goto('https://ray.run/');
const title = page.locator('title');
await expect(title).toHaveText('Ray.run');
});
Playwright supports soft assertions which allow you to continue with the test execution even if some assertions fail. Soft assertions compile and display a list of failed assertions once the test ends instead of immediately terminating the execution.
import { test } from '@playwright/test';
test('soft assertion example', async ({ page }) => {
await page.goto('https://ray.run/');
const title = page.locator('title');
await expect(title).toHaveText('Ray.run'); // If this assertion fails, the test will still continue
});
So, with Playwright's auto-waiting feature and built-in assertions, you can easily verify that all requests are sent when the test is finished without having to manually wait or check each request individually.
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].