diff --git a/commands/metamask.js b/commands/metamask.js index 1d93ca4e0..7a288de8f 100644 --- a/commands/metamask.js +++ b/commands/metamask.js @@ -1217,7 +1217,7 @@ const metamask = { }, async allowToAddAndSwitchNetwork() { await module.exports.allowToAddNetwork(); - await module.exports.allowToSwitchNetwork(); + await allowToSwitchNetworkIfNeeded(); return true; }, async getWalletAddress() { @@ -1320,6 +1320,14 @@ async function switchToCypressIfNotActive() { return switchBackToCypressWindow; } +async function allowToSwitchNetworkIfNeeded() { + await playwright.assignWindows().then(async () => { + if (await playwright.isNotificationOpen()) { + await module.exports.allowToSwitchNetwork(); + } + }); +} + async function activateAdvancedSetting( toggleOn, toggleOff, diff --git a/commands/playwright.js b/commands/playwright.js index a1f411558..3d1b94535 100644 --- a/commands/playwright.js +++ b/commands/playwright.js @@ -469,4 +469,14 @@ module.exports = { return extensionsData; }, + 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; + }, };