Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Usage of fixtures with a new browser context #566

@ptbrowne

Description

@ptbrowne

Hi,

I've successfully used the screen and page fixtures provided by playwright-testing-library, thank you !
Now I want to record an HAR from my test to be able to replay it.
From the Playwright docs, we are instructed to create a new browser context https://playwright.dev/docs/network#recording-har-with-a-script. When I create a new browser context, I think I have to create a new page / screen fixture manually otherwise the page from the fixture is not the right one.

I haven't seen an example from the docs. I am currently trying with

import { locatorFixtures as fixtures } from "@playwright-testing-library/test/fixture";

...

      const context = await browser.newContext({
        recordHar: { path: `record.har` },
      });

      const page = await context.newPage();
      const screen = await fixtures.screen({ page });
      const within = await fixtures.within({ screen, page });

but it seems I've missing something to make it work. And the fixtures types do not have screen and within 🤔 Am I going in the right direction for this ? Would you do any other way ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions