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
66.15k stars 3.61k forks source link

[Bug]: Unable to switch from iFrame to Parent browser when executing test case of Lambdatest #29364

Closed vipinphogat91 closed 8 months ago

vipinphogat91 commented 8 months ago

Version

1.41.2

Steps to reproduce

I am currently running my test case on LambdaTest platform with below configuration: Browser = Chrome Version = 121 OS = Windows 11

The test case which I am executing involves switching from parent page to iFrame and then back to parent page. In order to launch browser on lambdatest I am using below command:

const context= await chromium.connect({
    wsEndpoint: 'wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(             JSON.stringify(capabilities)
)}',
})

During the execution I am able to switch to iFrame but I am not able to switch back to parent browser page.

Below is the command i am using:

let allPages = context.pages()
for (let page of allPages) {

const pageTitle = await page.title()
if (await pageTitle.includes("homePage")) {
await page.bringToFront()
}
}

Please note that I am able to successfully execute the code on my local machine the only difference is that on my local instead of chromium.connect() I am launching a persistent context.

Expected behavior

I should be able to switch back to the parent page or browser from an iFrame

Actual behavior

Currently I am getting below error:

TypeError: context.pages is not a function

Additional context

No response

Environment

**Browser = Chrome
Version = 121
OS = Windows 11**
dgozman commented 8 months ago

chromium.connect() returns a Browser, not BrowserContext. Therefore, it does not have a page() method so you cannot call context.pages() on it.

If you believe there is a bug in Playwright, please file a new issue using by filling in the "Bug Report" template, and provide a self-contained repro.

vipinphogat91 commented 8 months ago

How can a user switch between pages when using chromium.connect()?