diff --git a/commands/metamask.js b/commands/metamask.js index cfbf01abf..7a4517394 100644 --- a/commands/metamask.js +++ b/commands/metamask.js @@ -745,7 +745,7 @@ module.exports = { }, allowToAddAndSwitchNetwork: async () => { await module.exports.allowToAddNetwork(); - await module.exports.allowToSwitchNetwork(); + await allowToSwitchNetworkIfNeeded(); return true; }, getWalletAddress: async () => { @@ -839,3 +839,11 @@ async function switchToCypressIfNotActive() { } return switchBackToCypressWindow; } + +async function allowToSwitchNetworkIfNeeded() { + await playwright.assignWindows().then(async () => { + if (await playwright.isNotificationOpen()) { + await module.exports.allowToSwitchNetwork(); + } + }); +} diff --git a/commands/playwright.js b/commands/playwright.js index 11e031f8e..c67ffb4ea 100644 --- a/commands/playwright.js +++ b/commands/playwright.js @@ -218,4 +218,14 @@ module.exports = { await module.exports.waitFor(selector, page); await page.locator(selector, { hasText: text }).waitFor(); }, + async isNotificationOpen() { + await sleep(200); + let pages = browser.contexts()[0].pages(); + for (const page of pages) { + if (page.url().includes('notification')) { + return true; + } + } + return false; + }, };