From 740edb71626a69be2d45488269447cc35ae84399 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Dec 2020 07:03:12 +0000 Subject: [PATCH 1/4] chore(deps): bump cypress from 6.0.1 to 6.1.0 Bumps [cypress](https://github.com/cypress-io/cypress) from 6.0.1 to 6.1.0. - [Release notes](https://github.com/cypress-io/cypress/releases) - [Changelog](https://github.com/cypress-io/cypress/blob/develop/.releaserc.base.js) - [Commits](https://github.com/cypress-io/cypress/compare/v6.0.1...v6.1.0) Signed-off-by: dependabot[bot] --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 234747921..56c89329d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2015,9 +2015,9 @@ "dev": true }, "cypress": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/cypress/-/cypress-6.0.1.tgz", - "integrity": "sha512-3xtQZ0YM65soLgKQUgn2wg2IbWsM6A2yBg6L4RF31mZHr5LNKdO2/9sgiwxEVMKu2C2m6+IQ75zHP41kZP5rPg==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/cypress/-/cypress-6.1.0.tgz", + "integrity": "sha512-uQnSxRcZ6hkf9R5cr8KpRBTzN88QZwLIImbf5DWa5RIxH6o5Gpff58EcjiYhAR8/8p9SGv7O6SRygq4H+k0Qpw==", "requires": { "@cypress/listr-verbose-renderer": "^0.4.1", "@cypress/request": "^2.88.5", diff --git a/package.json b/package.json index ae23a5379..31e8e216e 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "babel-plugin-transform-react-qa-classes": "1.6.0", "babel-plugin-transform-react-styled-components-qa": "2.0.1", "commander": "6.2.0", - "cypress": "6.0.1", + "cypress": "6.1.0", "cypress-wait-until": "1.7.1", "eslint": "7.15.0", "eslint-config-prettier": "6.15.0", From b2cc8263cfcd579a9e71ff6b5b431f6968b30cb7 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Fri, 11 Dec 2020 18:33:27 +0100 Subject: [PATCH 2/4] refactor: commands refactor Signed-off-by: Jakub Mucha --- commands/metamask.js | 191 ++++++++++++++++++++++++++++++++++++++++++ commands/puppeteer.js | 106 +++++++++++++++++++++++ commands/synthetix.js | 1 + 3 files changed, 298 insertions(+) create mode 100644 commands/metamask.js create mode 100644 commands/puppeteer.js create mode 100644 commands/synthetix.js diff --git a/commands/metamask.js b/commands/metamask.js new file mode 100644 index 000000000..aec141514 --- /dev/null +++ b/commands/metamask.js @@ -0,0 +1,191 @@ +const puppeteer = require('./puppeteer'); + +const { pageElements } = require('../pages/metamask/page'); +const { + welcomePageElements, + firstTimeFlowPageElements, + metametricsPageElements, + firstTimeFlowFormPageElements, + revealSeedPageElements, +} = require('../pages/metamask/first-time-flow-page'); +const { mainPageElements } = require('../pages/metamask/main-page'); +const { unlockPageElements } = require('../pages/metamask/unlock-page'); +const { + notificationPageElements, + permissionsPageElements, + confirmPageElements, +} = require('../pages/metamask/notification-page'); + +let walletAddress; + +module.exports = { + walletAddress, + // workaround for metamask random blank page on first run + fixBlankPage: async () => { + await puppeteer.metamaskWindow.waitForTimeout(1000); + for (let times = 0; times < 5; times++) { + if ( + (await puppeteer.metamaskWindow.$(welcomePageElements.app)) === null + ) { + await puppeteer.metamaskWindow.reload(); + await puppeteer.metamaskWindow.waitForTimeout(2000); + } else { + break; + } + } + }, + confirmWelcomePage: async () => { + await this.fixBlankPage(); + await puppeteer.waitAndClick(welcomePageElements.confirmButton); + return true; + }, + unlock: async password => { + await this.fixBlankPage(); + await puppeteer.waitAndType(unlockPageElements.passwordInput, password); + await puppeteer.waitAndClick(unlockPageElements.unlockButton); + return true; + }, + importWallet: async (secretWords, password) => { + await puppeteer.waitAndClick(firstTimeFlowPageElements.importWalletButton); + await puppeteer.waitAndClick(metametricsPageElements.optOutAnalyticsButton); + await puppeteer.waitAndType( + firstTimeFlowFormPageElements.secretWordsInput, + secretWords, + ); + await puppeteer.waitAndType( + firstTimeFlowFormPageElements.passwordInput, + password, + ); + await puppeteer.waitAndType( + firstTimeFlowFormPageElements.confirmPasswordInput, + password, + ); + await puppeteer.waitAndClick(firstTimeFlowFormPageElements.termsCheckbox); + await puppeteer.waitAndClick(firstTimeFlowFormPageElements.importButton); + + // metamask hangs, reload as workaround + // await puppeteer.waitAndClick(endOfFlowPageElements.allDoneButton); + await puppeteer.waitFor(pageElements.loadingSpinner); + await puppeteer.metamaskWindow.reload(); + await puppeteer.waitAndClick(revealSeedPageElements.remindLaterButton); + await puppeteer.waitFor(mainPageElements.walletOverview); + + // close popup if present + if ( + (await puppeteer.metamaskWindow.$(mainPageElements.popup.container)) !== + null + ) { + await puppeteer.waitAndClick(mainPageElements.popup.closeButton); + } + return true; + }, + changeNetwork: async network => { + await puppeteer.waitAndClick(mainPageElements.networkSwitcher.button); + if (network === 'main') { + await puppeteer.waitAndClick( + mainPageElements.networkSwitcher.networkButton(0), + ); + } else if (network === 'ropsten') { + await puppeteer.waitAndClick( + mainPageElements.networkSwitcher.networkButton(1), + ); + } else if (network === 'kovan') { + await puppeteer.waitAndClick( + mainPageElements.networkSwitcher.networkButton(2), + ); + } else if (network === 'rinkeby') { + await puppeteer.waitAndClick( + mainPageElements.networkSwitcher.networkButton(3), + ); + } else if (network === 'goerli') { + await puppeteer.waitAndClick( + mainPageElements.networkSwitcher.networkButton(4), + ); + } else if (network === 'localhost') { + await puppeteer.waitAndClick( + mainPageElements.networkSwitcher.networkButton(5), + ); + } + await puppeteer.waitForText( + mainPageElements.networkSwitcher.networkName, + network, + ); + return true; + }, + acceptAccess: async () => { + await puppeteer.metamaskWindow.waitForTimeout(3000); + const notificationPage = await puppeteer.switchToMetamaskNotification(); + await puppeteer.waitAndClick( + notificationPageElements.nextButton, + notificationPage, + ); + await puppeteer.waitAndClick( + permissionsPageElements.connectButton, + notificationPage, + ); + await puppeteer.metamaskWindow.waitForTimeout(3000); + return true; + }, + confirmTransaction: async () => { + await puppeteer.metamaskWindow.waitForTimeout(3000); + const notificationPage = await puppeteer.switchToMetamaskNotification(); + const currentGasFee = await puppeteer.waitAndGetValue( + confirmPageElements.gasFeeInput, + notificationPage, + ); + const newGasFee = (Number(currentGasFee) + 10).toString(); + await puppeteer.waitAndSetValue( + newGasFee, + confirmPageElements.gasFeeInput, + notificationPage, + ); + await puppeteer.waitAndClick( + confirmPageElements.confirmButton, + notificationPage, + ); + await puppeteer.metamaskWindow.waitForTimeout(3000); + return true; + }, + rejectTransaction: async () => { + await puppeteer.metamaskWindow.waitForTimeout(3000); + const notificationPage = await puppeteer.switchToMetamaskNotification(); + await puppeteer.waitAndClick( + confirmPageElements.rejectButton, + notificationPage, + ); + await puppeteer.metamaskWindow.waitForTimeout(3000); + return true; + }, + getWalletAddress: async () => { + await puppeteer.waitAndClick(mainPageElements.options.button); + await puppeteer.waitAndClick(mainPageElements.options.accountDetailsButton); + walletAddress = await puppeteer.waitAndGetValue( + mainPageElements.accountModal.walletAddressInput, + ); + await puppeteer.waitAndClick(mainPageElements.accountModal.closeButton); + return walletAddress; + }, + initialSetup: async ({ secretWords, network, password }) => { + if (secretWords === undefined && process.env.SECRET_WORDS) { + secretWords = process.env.SECRET_WORDS; + } + await puppeteer.init(); + await puppeteer.assignWindows(); + await puppeteer.metamaskWindow.waitForTimeout(1000); + if ( + (await puppeteer.metamaskWindow.$(unlockPageElements.unlockPage)) === null + ) { + await this.confirmWelcomePage(); + await this.importWallet(secretWords, password); + await this.changeNetwork(network); + walletAddress = await this.getWalletAddress(); + await puppeteer.switchToCypressWindow(); + return true; + } else { + await this.unlock(password); + walletAddress = await this.getWalletAddress(); + await puppeteer.switchToCypressWindow(); + return true; + } + }, +}; diff --git a/commands/puppeteer.js b/commands/puppeteer.js new file mode 100644 index 000000000..ba23edaca --- /dev/null +++ b/commands/puppeteer.js @@ -0,0 +1,106 @@ +const puppeteer = require('puppeteer-core'); +const fetch = require('node-fetch'); + +let puppeteerBrowser; +let mainWindow; +let metamaskWindow; + +module.exports = { + puppeteerBrowser, + mainWindow, + metamaskWindow, + init: async () => { + const debuggerDetails = await fetch('http://localhost:9222/json/version'); + const debuggerDetailsConfig = await debuggerDetails.json(); + const webSocketDebuggerUrl = debuggerDetailsConfig.webSocketDebuggerUrl; + + puppeteerBrowser = await puppeteer.connect({ + browserWSEndpoint: webSocketDebuggerUrl, + ignoreHTTPSErrors: true, + // eslint-disable-next-line unicorn/no-null + defaultViewport: null, + }); + return puppeteerBrowser.isConnected(); + }, + assignWindows: async () => { + let pages = await puppeteerBrowser.pages(); + for (const page of pages) { + if (page.url().includes('integration')) { + mainWindow = page; + } else if (page.url().includes('extension')) { + metamaskWindow = page; + } + } + return true; + }, + getBrowser: async () => { + return { + puppeteerBrowser, + }; + }, + getWindows: async () => { + return { + mainWindow, + metamaskWindow, + }; + }, + switchToCypressWindow: async () => { + await mainWindow.bringToFront(); + return true; + }, + switchToMetamaskWindow: async () => { + await metamaskWindow.bringToFront(); + return true; + }, + switchToMetamaskNotification: async () => { + let pages = await puppeteerBrowser.pages(); + for (const page of pages) { + if (page.url().includes('notification')) { + await page.bringToFront(); + return page; + } + } + }, + waitFor: async (selector, page = metamaskWindow) => { + await page.waitForFunction( + `document.querySelector('${selector}') && document.querySelector('${selector}').clientHeight != 0`, + { visible: true }, + ); + // puppeteer going too fast breaks metamask in corner cases + await page.waitForTimeout(300); + }, + waitAndClick: async (selector, page = metamaskWindow) => { + await this.waitFor(selector, page); + await page.evaluate( + selector => document.querySelector(selector).click(), + selector, + ); + }, + waitAndType: async (selector, value, page = metamaskWindow) => { + await this.waitFor(selector, page); + const element = await page.$(selector); + await element.type(value); + }, + waitAndGetValue: async (selector, page = metamaskWindow) => { + await this.waitFor(selector, page); + const element = await page.$(selector); + const property = await element.getProperty('value'); + const value = await property.jsonValue(); + return value; + }, + waitAndSetValue: async (text, selector, page = metamaskWindow) => { + await this.waitFor(selector, page); + await page.evaluate( + selector => (document.querySelector(selector).value = ''), + selector, + ); + await page.focus(selector); + await page.keyboard.type(text); + }, + waitForText: async (selector, text, page = metamaskWindow) => { + await this.waitFor(selector, page); + await page.waitForFunction( + `document.querySelector('${selector}').innerText.toLowerCase().includes('${text}')`, + ); + }, +}; diff --git a/commands/synthetix.js b/commands/synthetix.js new file mode 100644 index 000000000..f053ebf79 --- /dev/null +++ b/commands/synthetix.js @@ -0,0 +1 @@ +module.exports = {}; From 45cb4e407daff82d9b93ab5c267bff63e293d48d Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Fri, 11 Dec 2020 18:33:38 +0100 Subject: [PATCH 3/4] refactor: helpers refactor Signed-off-by: Jakub Mucha --- helpers.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/helpers.js b/helpers.js index eec00cb42..f5bb2f326 100644 --- a/helpers.js +++ b/helpers.js @@ -1,6 +1,7 @@ const axios = require('axios'); const fs = require('fs'); const unzip = require('unzipper'); +const path = require('path'); module.exports = { getSynpressPath: () => { @@ -34,4 +35,16 @@ module.exports = { stream.pipe(unzip.Extract({ path: destination }).on('close', resolve)), ); }, + prepareMetamask: async () => { + const release = await this.getMetamaskReleases(); + const downloadsDirectory = path.resolve(__dirname, 'downloads'); + if (!fs.existsSync(downloadsDirectory)) { + fs.mkdirSync(downloadsDirectory); + } + const downloadDestination = path.join(downloadsDirectory, release.filename); + await this.download(release.downloadUrl, downloadDestination); + const metamaskDirectory = path.join(downloadsDirectory, 'metamask'); + await this.extract(downloadDestination, metamaskDirectory); + return metamaskDirectory; + }, }; From 3ae1ab39037e700578555017c3fc3891009652a7 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Fri, 11 Dec 2020 18:34:12 +0100 Subject: [PATCH 4/4] refactor: plugins file refactor Signed-off-by: Jakub Mucha --- plugins/index.js | 308 +++-------------------------------------------- 1 file changed, 20 insertions(+), 288 deletions(-) diff --git a/plugins/index.js b/plugins/index.js index c08a57b84..c1258060e 100644 --- a/plugins/index.js +++ b/plugins/index.js @@ -1,28 +1,6 @@ -const path = require('path'); -const fs = require('fs'); const helpers = require('../helpers'); -const puppeteer = require('puppeteer-core'); -const fetch = require('node-fetch'); -const { pageElements } = require('../pages/metamask/page'); -const { - welcomePageElements, - firstTimeFlowPageElements, - metametricsPageElements, - firstTimeFlowFormPageElements, - revealSeedPageElements, -} = require('../pages/metamask/first-time-flow-page'); -const { mainPageElements } = require('../pages/metamask/main-page'); -const { unlockPageElements } = require('../pages/metamask/unlock-page'); -const { - notificationPageElements, - permissionsPageElements, - confirmPageElements, -} = require('../pages/metamask/notification-page'); - -let puppeteerBrowser; -let mainWindow; -let metamaskWindow; -let walletAddress; +const puppeteer = require('../commands/puppeteer'); +const metamask = require('../commands/metamask'); /** * @type {Cypress.PluginConfig} @@ -53,7 +31,7 @@ module.exports = (on, config) => { } // NOTE: extensions cannot be loaded in headless Chrome - const metamaskPath = await prepareMetamask(); + const metamaskPath = await helpers.prepareMetamask(); arguments_.extensions.push(metamaskPath); return arguments_; }); @@ -66,85 +44,65 @@ module.exports = (on, config) => { console.warn('\u001B[33m', 'WARNING:', message, '\u001B[0m'); }, initPuppeteer: async () => { - const connected = await initPuppeteer(); + const connected = await puppeteer.init(); return connected; }, assignWindows: async () => { - const assigned = await assignWindows(); + const assigned = await puppeteer.assignWindows(); return assigned; }, switchToCypressWindow: async () => { - const switched = await switchToCypressWindow(); + const switched = await puppeteer.switchToCypressWindow(); return switched; }, switchToMetamaskWindow: async () => { - const switched = await switchToMetamaskWindow(); + const switched = await puppeteer.switchToMetamaskWindow(); return switched; }, switchToMetamaskNotification: async () => { - const notificationPage = await switchToMetamaskNotification(); + const notificationPage = await puppeteer.switchToMetamaskNotification(); return notificationPage; }, confirmMetamaskWelcomePage: async () => { - const confirmed = await confirmMetamaskWelcomePage(); + const confirmed = await metamask.confirmWelcomePage(); return confirmed; }, unlockMetamask: async password => { - const unlocked = await unlockMetamask(password); + const unlocked = await metamask.unlock(password); return unlocked; }, importMetamaskWallet: async ({ secretWords, password }) => { - const imported = await importMetamaskWallet(secretWords, password); + const imported = await metamask.importWallet(secretWords, password); return imported; }, changeMetamaskNetwork: async network => { - const networkChanged = await changeMetamaskNetwork(network); + const networkChanged = await metamask.changeNetwork(network); return networkChanged; }, acceptMetamaskAccess: async () => { - const accepted = await acceptMetamaskAccess(); + const accepted = await metamask.acceptAccess(); return accepted; }, confirmMetamaskTransaction: async () => { - const confirmed = await confirmMetamaskTransaction(); + const confirmed = await metamask.confirmTransaction(); return confirmed; }, rejectMetamaskTransaction: async () => { - const rejected = await rejectMetamaskTransaction(); + const rejected = await metamask.rejectTransaction(); return rejected; }, getMetamaskWalletAddress: async () => { - const walletAddress = await getMetamaskWalletAddress(); + const walletAddress = await metamask.getWalletAddress(); return walletAddress; }, - setupMetamask: async ({ secretWords, network, password }) => { - if (secretWords === undefined && process.env.SECRET_WORDS) { - secretWords = process.env.SECRET_WORDS; - } - - await initPuppeteer(); - await assignWindows(); - await metamaskWindow.waitForTimeout(1000); - if ((await metamaskWindow.$(unlockPageElements.unlockPage)) === null) { - await confirmMetamaskWelcomePage(); - await importMetamaskWallet(secretWords, password); - await changeMetamaskNetwork(network); - walletAddress = await getMetamaskWalletAddress(); - await switchToCypressWindow(); - return true; - } else { - await unlockMetamask(password); - walletAddress = await getMetamaskWalletAddress(); - await switchToCypressWindow(); - return true; - } - }, fetchMetamaskWalletAddress: async () => { - return walletAddress; + return metamask.walletAddress; + }, + setupMetamask: async ({ secretWords, network, password }) => { + return metamask.initialSetup({ secretWords, network, password }); }, }); - // setup config if (process.env.BASE_URL) { config.baseUrl = process.env.BASE_URL; } @@ -156,229 +114,3 @@ module.exports = (on, config) => { return config; }; - -async function waitFor(selector, page = metamaskWindow) { - await page.waitForFunction( - `document.querySelector('${selector}') && document.querySelector('${selector}').clientHeight != 0`, - { visible: true }, - ); - // puppeteer going too fast breaks metamask in corner cases - await page.waitForTimeout(300); -} - -async function waitAndClick(selector, page = metamaskWindow) { - await waitFor(selector, page); - await page.evaluate( - selector => document.querySelector(selector).click(), - selector, - ); -} - -async function waitAndType(selector, value, page = metamaskWindow) { - await waitFor(selector, page); - const element = await page.$(selector); - await element.type(value); -} - -async function waitAndGetValue(selector, page = metamaskWindow) { - await waitFor(selector, page); - const element = await page.$(selector); - const property = await element.getProperty('value'); - const value = await property.jsonValue(); - return value; -} - -async function waitAndSetValue(text, selector, page = metamaskWindow) { - await waitFor(selector, page); - await page.evaluate( - selector => (document.querySelector(selector).value = ''), - selector, - ); - await page.focus(selector); - await page.keyboard.type(text); -} - -async function waitForText(selector, text, page = metamaskWindow) { - await waitFor(selector, page); - await page.waitForFunction( - `document.querySelector('${selector}').innerText.toLowerCase().includes('${text}')`, - ); -} - -async function prepareMetamask() { - const release = await helpers.getMetamaskReleases(); - const downloadsDirectory = path.resolve(__dirname, 'downloads'); - if (!fs.existsSync(downloadsDirectory)) { - fs.mkdirSync(downloadsDirectory); - } - const downloadDestination = path.join(downloadsDirectory, release.filename); - await helpers.download(release.downloadUrl, downloadDestination); - const metamaskDirectory = path.join(downloadsDirectory, 'metamask'); - await helpers.extract(downloadDestination, metamaskDirectory); - return metamaskDirectory; -} - -async function initPuppeteer() { - const debuggerDetails = await fetch('http://localhost:9222/json/version'); - const debuggerDetailsConfig = await debuggerDetails.json(); - const webSocketDebuggerUrl = debuggerDetailsConfig.webSocketDebuggerUrl; - - puppeteerBrowser = await puppeteer.connect({ - browserWSEndpoint: webSocketDebuggerUrl, - ignoreHTTPSErrors: true, - // eslint-disable-next-line unicorn/no-null - defaultViewport: null, - }); - return puppeteerBrowser.isConnected(); -} - -async function assignWindows() { - let pages = await puppeteerBrowser.pages(); - for (const page of pages) { - if (page.url().includes('integration')) { - mainWindow = page; - } else if (page.url().includes('extension')) { - metamaskWindow = page; - } - } - return true; -} - -async function switchToCypressWindow() { - await mainWindow.bringToFront(); - return true; -} - -async function switchToMetamaskWindow() { - await metamaskWindow.bringToFront(); - return true; -} - -async function switchToMetamaskNotification() { - let pages = await puppeteerBrowser.pages(); - for (const page of pages) { - if (page.url().includes('notification')) { - await page.bringToFront(); - return page; - } - } -} - -async function confirmMetamaskWelcomePage() { - await fixBlankMetamask(); - await waitAndClick(welcomePageElements.confirmButton); - return true; -} - -async function unlockMetamask(password) { - await fixBlankMetamask(); - await waitAndType(unlockPageElements.passwordInput, password); - await waitAndClick(unlockPageElements.unlockButton); - return true; -} - -async function importMetamaskWallet(secretWords, password) { - await waitAndClick(firstTimeFlowPageElements.importWalletButton); - await waitAndClick(metametricsPageElements.optOutAnalyticsButton); - await waitAndType( - firstTimeFlowFormPageElements.secretWordsInput, - secretWords, - ); - await waitAndType(firstTimeFlowFormPageElements.passwordInput, password); - await waitAndType( - firstTimeFlowFormPageElements.confirmPasswordInput, - password, - ); - await waitAndClick(firstTimeFlowFormPageElements.termsCheckbox); - await waitAndClick(firstTimeFlowFormPageElements.importButton); - - // metamask hangs, reload as workaround - // await waitAndClick(endOfFlowPageElements.allDoneButton); - await waitFor(pageElements.loadingSpinner); - await metamaskWindow.reload(); - await waitAndClick(revealSeedPageElements.remindLaterButton); - await waitFor(mainPageElements.walletOverview); - - // close popup if present - if ((await metamaskWindow.$(mainPageElements.popup.container)) !== null) { - await waitAndClick(mainPageElements.popup.closeButton); - } - return true; -} - -async function changeMetamaskNetwork(network) { - await waitAndClick(mainPageElements.networkSwitcher.button); - if (network === 'main') { - await waitAndClick(mainPageElements.networkSwitcher.networkButton(0)); - } else if (network === 'ropsten') { - await waitAndClick(mainPageElements.networkSwitcher.networkButton(1)); - } else if (network === 'kovan') { - await waitAndClick(mainPageElements.networkSwitcher.networkButton(2)); - } else if (network === 'rinkeby') { - await waitAndClick(mainPageElements.networkSwitcher.networkButton(3)); - } else if (network === 'goerli') { - await waitAndClick(mainPageElements.networkSwitcher.networkButton(4)); - } else if (network === 'localhost') { - await waitAndClick(mainPageElements.networkSwitcher.networkButton(5)); - } - await waitForText(mainPageElements.networkSwitcher.networkName, network); - return true; -} - -async function acceptMetamaskAccess() { - await metamaskWindow.waitForTimeout(3000); - const notificationPage = await switchToMetamaskNotification(); - await waitAndClick(notificationPageElements.nextButton, notificationPage); - await waitAndClick(permissionsPageElements.connectButton, notificationPage); - await metamaskWindow.waitForTimeout(3000); - return true; -} - -async function confirmMetamaskTransaction() { - await metamaskWindow.waitForTimeout(3000); - const notificationPage = await switchToMetamaskNotification(); - const currentGasFee = await waitAndGetValue( - confirmPageElements.gasFeeInput, - notificationPage, - ); - const newGasFee = (Number(currentGasFee) + 10).toString(); - await waitAndSetValue( - newGasFee, - confirmPageElements.gasFeeInput, - notificationPage, - ); - await waitAndClick(confirmPageElements.confirmButton, notificationPage); - await metamaskWindow.waitForTimeout(3000); - return true; -} - -async function rejectMetamaskTransaction() { - await metamaskWindow.waitForTimeout(3000); - const notificationPage = await switchToMetamaskNotification(); - await waitAndClick(confirmPageElements.rejectButton, notificationPage); - await metamaskWindow.waitForTimeout(3000); - return true; -} - -async function getMetamaskWalletAddress() { - await waitAndClick(mainPageElements.options.button); - await waitAndClick(mainPageElements.options.accountDetailsButton); - const walletAddress = await waitAndGetValue( - mainPageElements.accountModal.walletAddressInput, - ); - await waitAndClick(mainPageElements.accountModal.closeButton); - return walletAddress; -} - -// workaround for metamask random blank page on first run -async function fixBlankMetamask() { - await metamaskWindow.waitForTimeout(1000); - for (let times = 0; times < 5; times++) { - if ((await metamaskWindow.$(welcomePageElements.app)) === null) { - await metamaskWindow.reload(); - await metamaskWindow.waitForTimeout(2000); - } else { - break; - } - } -}