Rayrun
← Back to Discord Forum

Compare test against HAR file

Hi, I'd like to verify some requests that are sent during the test, it's around 20-30 requests some checking each of them separately sounds pretty tedious. I looked at HAR files and I see an option to mock with them, but it's not really what I'm looking for as I want to verify that some requests are being sent. Is there a good way to verify that all of these requests are sent when the test is finished without having to manually do that for each request?

Other solutions are fine too ofc. Thanks.

This thread is trying to answer question "Is there a good way to verify that all of these requests are sent when the test is finished without having to manually do that for each request?"

0 replies

Answer

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.

Auto-Waiting

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
});

Assertions

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');
});

Soft Assertions

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.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

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 luc@ray.run.