Skip to content

Commit

Permalink
Handle case when network was already added (copied from PR #536)
Browse files Browse the repository at this point in the history
  • Loading branch information
duckception committed Aug 17, 2023
1 parent 6a4979f commit f5f0591
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion commands/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ const metamask = {
},
async allowToAddAndSwitchNetwork() {
await module.exports.allowToAddNetwork();
await module.exports.allowToSwitchNetwork();
await allowToSwitchNetworkIfNeeded();
return true;
},
async getWalletAddress() {
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions commands/playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
};

0 comments on commit f5f0591

Please sign in to comment.