From d8d7ec13b856795a5cdb4cb88fc37aa09cd3fb85 Mon Sep 17 00:00:00 2001 From: kacper29 Date: Fri, 7 Oct 2022 11:26:17 +0200 Subject: [PATCH] Handled case when network is already added in allowToAddAndSwitchNetwork() --- 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 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; + }, };