Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle network already added case for allowToAddAndSwitchNetwork #836

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion commands/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ const metamask = {
},
async allowToAddAndSwitchNetwork() {
await module.exports.allowToAddNetwork();
await module.exports.allowToSwitchNetwork();
await allowToSwitchNetworkIfNeeded();
return true;
},
async getWalletAddress() {
Expand Down Expand Up @@ -1335,6 +1335,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 @@ -481,4 +481,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;
},
};
7 changes: 7 additions & 0 deletions tests/e2e/specs/metamask-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,5 +457,12 @@ describe('Metamask', () => {
expect(approved).to.be.true;
});
});
it(`allowToAddAndSwitchNetwork should switch network if this network was previously already added`, () => {
cy.changeMetamaskNetwork('mainnet');
cy.get('#addEthereumChain').click();
cy.allowMetamaskToAddAndSwitchNetwork().then(approved => {
expect(approved).to.be.true;
});
});
});
});