I’m clicking a link on a webpage which opens a new page. k6 is not able to detect the new page. Though context.pages().length returns 2, it doesn’t identify any page other than the original page. So it is not able to navigate & operate on the new page.
Following code snippet can be used to experiment with this.
Can anyone guide if I’m missing something here?
const page = browser.newPage();
let baseUrl = "https://httpbin.org/"
await page.goto(baseUrl, {waitUntil: 'load'});
Logger.info("Home Page title:",page.title())
const newLinkSelector = page.locator("a[href='https://kennethreitz.org']");
Logger.info(newLinkSelector.innerText())
newLinkSelector.click()
sleep(5)
console.log("Page Count:",context.pages().length);
const pages = browser.context().pages()
for (let i in pages){
console.log(`Title${i}`, pages[i].title())
}
I am using k6 version k6.exe v0.49.0 (commit/b5328aa782, go1.21.6, windows/amd64)
Sorry for delay in getting back to you. Do you have a test script that points to a publicly accessible website that we can test against to replicate the incorrect behaviour you are seeing? Are you working with the test script that @sumitbhowmick posted initially?
I’ve amended the script to work with the latest non-experimental browser module API in k6 v0.53.0 (NOTE: the experimental API is deprecated and will be removed very soon):