microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
67.12k stars 3.69k forks source link

feat(routeFromHAR): add `shouldSave` option to control when to save HAR files #33628

Closed mskelton closed 3 days ago

mskelton commented 6 days ago

This adds a function to allow conditionally saving HAR files. This can be combined with testInfo to save HAR files only if a test passes, etc.

Example usage

it('welcome', async ({ page }, testInfo) => {
  const harPath = testInfo.outputPath('har.har');
  await page.routeFromHAR(harPath, {
    update: true,
    shouldSave: () => testInfo.status === 'passed'
  });

  await page.goto('/welcome');
  await expect(page.getByRole('heading')).toHaveText('Welcome');
});

Fixes #33559, inspired by #28796

github-actions[bot] commented 6 days ago

Test results for "tests 1"

5375 passed, 28 skipped :heavy_check_mark::heavy_check_mark::heavy_check_mark:

Merge workflow run.

github-actions[bot] commented 6 days ago

Test results for "tests 1"

36907 passed, 650 skipped :heavy_check_mark::heavy_check_mark::heavy_check_mark:

Merge workflow run.

Skn0tt commented 3 days ago

Hi Mark! shouldSave is not the kind of API addition that makes this feature easier to use, so i'll go ahead and close the PR. I'd like to look into what we can do to make this easier to use - reaching out to you over email to learn more about your workflow.