-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage of fixtures with a new browser context #566
Comments
Hi @ptbrowne, thanks for creating an issue for this. The fixtures exported from @playwright-testing-library/test/fixture ( Fortunately, the import { locatorFixtures as fixtures } from '@playwright-testing-library/test/fixture';
import { test as base } from '@playwright/test';
// --- ✂️ --- (`base.extend` setup from readme)
test('example with HAR recording', async ({ within }) => {
const context = await browser.newContext({ recordHar: { path: `record.har` } });
const page = await context.newPage();
// Pass the `Page` instance spawned from the HAR context to `within`
const screen = within(page);
const locator = screen.getByRole('button', { name: 'Hi Mom!' });
await locator.click();
// --- ✂️ ---
}); Let me know if you have any problems with the above approach. You could probably even abstract it into your own fixture if you use the recording in many tests. Some alternatives that may also be worth considering:
|
Thanks for the quick and thorough response @jrolfs !
|
Hi,
I've successfully used the
screen
andpage
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
but it seems I've missing something to make it work. And the fixtures types do not have
screen
andwithin
🤔 Am I going in the right direction for this ? Would you do any other way ?The text was updated successfully, but these errors were encountered: