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.
- Navigate to
/new-tabs/. - Evaluate all the
target=_blanklinks and click them. - Capture every new opened tab and take a screenshot once it loaded.
Todo
Solution
💡 If you're stuck, find a working example on GitHub.