Skip to content

Commit

Permalink
feat: support changeNetwork in e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
drptbl committed Oct 28, 2021
1 parent 5260b44 commit 927ea8e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions commands/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,15 @@ module.exports = {
return true;
},
changeNetwork: async network => {
let switchBackToCypressWindow;

setNetwork(network);

if (await puppeteer.isCypressWindowActive()) {
await puppeteer.switchToMetamaskWindow();
switchBackToCypressWindow = true;
}

await puppeteer.waitAndClick(mainPageElements.networkSwitcher.button);
if (network === 'main' || network === 'mainnet') {
await puppeteer.waitAndClick(
Expand Down Expand Up @@ -213,6 +221,11 @@ module.exports = {
);
}

if (switchBackToCypressWindow) {
await puppeteer.switchToCypressWindow();
switchBackToCypressWindow = false;
}

return true;
},
addNetwork: async network => {
Expand Down Expand Up @@ -426,6 +439,7 @@ module.exports = {

await puppeteer.init();
await puppeteer.assignWindows();
await puppeteer.assignActiveTabName('metamask');
await puppeteer.metamaskWindow().waitForTimeout(1000);
if (
(await puppeteer.metamaskWindow().$(unlockPageElements.unlockPage)) ===
Expand Down
2 changes: 1 addition & 1 deletion plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ module.exports = (on, config) => {
changeMetamaskNetwork: async network => {
if (process.env.NETWORK_NAME) {
network = process.env.NETWORK_NAME;
} else {
} else if (!network) {
network = 'kovan';
}
const networkChanged = await metamask.changeNetwork(network);
Expand Down

0 comments on commit 927ea8e

Please sign in to comment.