playwright-msw icon indicating copy to clipboard operation
playwright-msw copied to clipboard

Is msw also usable within a new page?

Open daniel-hyun-chae opened this issue 1 year ago • 1 comments

I have a test where it waits for a new window to popup and interact with the page in this new window. It seems that the mock service worker made available with the extended test is not available in the new window. It's a new page but still within the scope of the same test, I'd expect that the same service worker is available in the new window. Is this intended behavior?

test("create new entry submits a correct data", async ({ page }) => { .... await page.getByLabel("LP.general.input.password").click(); await page.getByLabel("LP.general.input.password").fill(userDataToSubmit.passwordDataForCreation.value); await page.getByLabel("LP.general.input.confirmPassword").click(); await page.getByLabel("LP.general.input.confirmPassword").fill(userDataToSubmit.passwordDataForCreation.value); await page.getByLabel("LP.views.UsersManagementView.users.passwordIsTemporary").check();

**const page2Promise = page.waitForEvent("popup");
await page.getByRole("button", { name: "LP.general.actions.submit" }).click();
const page2 = await page2Promise;
await page2.getByLabel("LP.general.input.user").click();
await page2.getByLabel("LP.general.input.user").fill("user1");**

daniel-hyun-chae avatar Sep 06 '24 12:09 daniel-hyun-chae

You do pass in the page when creating a worker, so I assume that worker is only available for that specific page.

Maybe you can try creating a new worker and pass in the popup page?

createWorker(page2, yourHandlers)

LeonGeldsch avatar Feb 06 '25 11:02 LeonGeldsch