From e3f06905407bc55f06899d55c57bf8a0a75ea127 Mon Sep 17 00:00:00 2001 From: duckception Date: Wed, 16 Aug 2023 22:41:41 +0200 Subject: [PATCH] Handle case when network was already added (copied from PR #536) --- commands/metamask.js | 10 +++++++++- commands/playwright.js | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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; + }, };