Rayrun
← Back to Discord Forum

routeFromHAR for the whole session

Hey, using routeFromHAR, it seems like 'preserve log' isn't enabled, meaning it doesn't actually record the HAR for the whole session, is this something that we can somehow achieve?

Thanks.

This thread is trying to answer question "Is it possible to enable 'preserve log' in routeFromHAR to record the HAR for the whole session?"

0 replies

Answer

Sure, you can enable "preserve log" in routeFromHAR(). This method in Playwright lets you serve responses from a HAR file during tests. By default, it only serves requests matching the specified URL pattern.

To record the HAR for the entire session, set the update option to true when calling page.routeFromHAR() or browserContext.routeFromHAR(). This updates the HAR file with actual network info, not just serving requests from the HAR file.

Here's an example:

// Enable "preserve log" and record HAR for whole session
await page.routeFromHAR('https://ray.run/hars/fruit.har', { url: '*/**/api/v1/fruits', update: true });

In this example, we're recording a HAR file named "fruit.har". The URL pattern matches all requests containing "/api/v1/fruits". By setting update to true, each request made during the test is recorded in the HAR file.

Remember, once you've recorded a HAR file, you can modify it by editing its JSON content. The modified mock data can then be used during test execution by turning off or removing the update option when using routeFromHAR(). This lets your tests run against the modified mock data stored in the HAR file instead of hitting an actual API.

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.