Reputation: 4004
I'm writing a Playwright test for the case in which a link opens an application via a new tab. The user clicks a link, and a new tab is opened with a custom application url.
The browser normally asks "Do you want to open this link," and the user must click accept or cancel.
In Playwright, the new page is blocked until after the dialog is confirmed. If I don't have access to the page, is it somehow possible to listen for the dialog event?
const context = page.context();
async function newPageOpened(): Promise<void> {
const newPage = await context.waitForEvent('page')
// I won't have access to newPage unless I manually click the Accept button 🙁
newPage.on('dialog', (dialog) => {
void dialog.accept();
});
}
async function action(): Promise<void> {
// Click the link
}
await Promise.all([newPageOpened, action()])
Upvotes: 0
Views: 893