Playwright · Junior · Question 57 of 75
How do you work with a link that opens a new tab?
const pagePromise = context.waitForEvent("page");
await page.getByText("Open docs").click();
const newPage = await pagePromise;- 1New tabs can't be tested, so remove
target - 2Wait for the context's
pageevent while clicking - 3Use
page.switchTo().window(1)after the click
Show the answer
Correct answer: Wait for the context's page event while clicking
Explanation
Start waiting before the click so the event isn't missed. The new page is a normal Page you can assert on.