Switching to new opened tab with k6-browser

It seems with K6, we can’t iterate over different browser page instances like we are trying to do here (for that browser automation tools like playwright, puppeteer etc can be useful but not k6).

The other alternative (to do what you are trying to do here) for k6 that worked for me was:

  const pages = browser.context().pages();
  const Page2 = pages[pages.length - 1];

  console.log("=========================");
  console.log('Current URL before switching: ', page.url())
  console.log(page.title());

  await Page2.bringToFront();
  console.log('Current URL after switching: ', Page2.url())
  console.log(Page2.title());
  console.log("=========================");