Closed davidhprotective closed 2 years ago
In Playwright there is not something called "switching to a window", you can just use a specific page or frame and it works.
Instead of using Thread.Sleep(1000);
I would recommend using await Page.WaitForTimeout(1000)
otherwise the events are not coming in.
What you probably want is BrowserContext.WaitForPage see here: https://playwright.dev/dotnet/docs/next/api/class-browsercontext#browser-context-wait-for-page
I tried using BrowserContext.WaitForPage but it times out waiting for the page when indeed a new page has automatically opened/popped out already. Does it try to create a new Page itself? In my case, navigating to home page already creates a new pop up window/page.
My question is how can I switch the control of Page object to the newly popped up sign in window so that I can fill in the username/password input fields there?
Can you provide us a repro? We have a plenty of tests for it and its working for us. For example here:
In my case, there is no click or any action happening for the pop-up window to open. Navigating to home page automatically pops up a new login window. In this case, how do I get control (or point Page instance to) the newly popped up page? Your code seems to say wait for the page to make a click and get the instance of the new page.
You can also listen for new Pages on the context with the Page event: context.Page += (_, page) => ...
Its not possible to re-point to a different page instance, you most likely just want to get the new page instance.
I am using PW with .Net - xUnit. I am currently working on a Login test where the homepage I navigate to automatically pops-up Okta sign-in window. I need to switch to that window and enter username/password and then switch back to the main window. (Okta window closes automatically after sign in).
After navigating to the homepage, I am trying to add the new pop-up window to Context and switch to it with the below code:
I pass BrowserContext instance from the Test class that calls this method.
And here is the TestFixture that runs before All Tests:
When I run tests with this setup, I intermittently get below error for
VerifyLogin()
test:The source of the
context was destroyed
error is pointing to theforeach
loop above.Any suggestions what I might be doing wrong here?