From bdf9cd8e3ad0ba126f452f0ff2d7f52f25eb249e Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 21 Jun 2018 09:49:27 -0230 Subject: [PATCH] Speed up page opening and fix timeout errors on remix page opening in beta e2e tests. --- test/e2e/beta/helpers.js | 14 ++++++++++++++ test/e2e/beta/metamask-beta-ui.spec.js | 25 ++++++++++++------------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/test/e2e/beta/helpers.js b/test/e2e/beta/helpers.js index 949fece96..c1080e8db 100644 --- a/test/e2e/beta/helpers.js +++ b/test/e2e/beta/helpers.js @@ -2,6 +2,7 @@ const fs = require('fs') const mkdirp = require('mkdirp') const pify = require('pify') const {until} = require('selenium-webdriver') +const { delay } = require('../func') const testContract = ` pragma solidity ^0.4.0; @@ -37,6 +38,7 @@ module.exports = { verboseReportOnFailure, findElement, findElements, + openNewPage, testContract, } @@ -93,3 +95,15 @@ async function findElement (driver, by, timeout = 10000) { async function findElements (driver, by, timeout = 10000) { return driver.wait(until.elementsLocated(by), timeout) } + +async function openNewPage (driver, url) { + await driver.executeScript('window.open()') + await delay(1000) + + const handles = await driver.getAllWindowHandles() + const lastHandle = handles.pop() + await driver.switchTo().window(lastHandle) + + await driver.get(url) + await delay(1000) +} diff --git a/test/e2e/beta/metamask-beta-ui.spec.js b/test/e2e/beta/metamask-beta-ui.spec.js index b0ed23691..6391e686e 100644 --- a/test/e2e/beta/metamask-beta-ui.spec.js +++ b/test/e2e/beta/metamask-beta-ui.spec.js @@ -17,6 +17,7 @@ const { loadExtension, verboseReportOnFailure, testContract, + openNewPage, } = require('./helpers') describe('MetaMask', function () { @@ -385,11 +386,13 @@ describe('MetaMask', function () { describe('Send ETH from Faucet', () => { it('starts a send transaction inside Faucet', async () => { - await driver.executeScript('window.open("https://faucet.metamask.io")') - await delay(waitingNewPageDelayMs) + await openNewPage(driver, 'https://faucet.metamask.io') const [extension, faucet] = await driver.getAllWindowHandles() await driver.switchTo().window(faucet) + + const faucetPageTitle = await findElement(driver, By.css('.container-fluid')) + await driver.wait(until.elementTextMatches(faucetPageTitle, /MetaMask/)) await delay(regularDelayMs) const send1eth = await findElement(driver, By.xpath(`//button[contains(text(), '10 ether')]`), 14000) @@ -417,11 +420,10 @@ describe('MetaMask', function () { describe('Deploy contract and call contract method from Remix', () => { it('writes a contract to remix', async () => { - await driver.executeScript('window.open("https://remix.ethereum.org/")') - await delay(waitingNewPageDelayMs) + await openNewPage(driver, 'https://remix.ethereum.org/') - const [extension, remix] = await driver.getAllWindowHandles() - await driver.switchTo().window(remix) + const byFilePanel = By.css('#filepanel') + await driver.wait(until.elementLocated(byFilePanel)) const newContractButton = await findElement(driver, By.css('.fa-plus-circle')) await newContractButton.click() @@ -521,11 +523,9 @@ describe('MetaMask', function () { describe('Add a custom token from TokenFactory', () => { it('creates a new token', async () => { - await driver.executeScript('window.open("https://tokenfactory.surge.sh/#/factory")') - await delay(waitingNewPageDelayMs) - + openNewPage(driver, 'https://tokenfactory.surge.sh/#/factory') const [extension, tokenFactory] = await driver.getAllWindowHandles() - await driver.switchTo().window(tokenFactory) + const [ totalSupply, tokenName, @@ -651,11 +651,10 @@ describe('MetaMask', function () { describe('Send a custom token from TokenFactory', () => { let gasModal it('sends an already created token', async () => { - await driver.executeScript(`window.open("https://tokenfactory.surge.sh/#/token/${tokenAddress}")`) - await delay(waitingNewPageDelayMs) + openNewPage(driver, `https://tokenfactory.surge.sh/#/token/${tokenAddress}`) const [extension, tokenFactory] = await driver.getAllWindowHandles() - await driver.switchTo().window(tokenFactory) + const [ transferToAddress, transferToAmount,