New tabs and pages

Learn how to capture new tabs and pages.

If you want to capture new pages that could be opened via JavaScript or target=_blank links, you can use the context fixture to catch these.

const popupPromise = page.waitForEvent("popup");
await page.getByText("open the popup").click();
const popup = await popupPromise;
Note

To iterate through elements that match a locator, .all() might come in handy. 😉


Exercise

Create a new test case that logs the user in.

  1. Navigate to /new-tabs/.
  2. Evaluate all the target=_blank links and click them.
  3. Capture every new opened tab and take a screenshot once it loaded.
Todo

Solution

💡 If you're stuck, find a working example on GitHub.