From 30d92b8d3f4c38dcd83bab97576775c0096adc1a Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Thu, 26 Jul 2018 10:54:38 -0230 Subject: Fix e2e tests to accomodate new ui suggestion screen changes. --- test/e2e/beta/from-import-beta-ui.spec.js | 61 +++++++++++++++++++---------- test/e2e/beta/metamask-beta-ui.spec.js | 64 +++++++++++++++---------------- test/e2e/metamask.spec.js | 15 ++++++-- 3 files changed, 83 insertions(+), 57 deletions(-) (limited to 'test/e2e') diff --git a/test/e2e/beta/from-import-beta-ui.spec.js b/test/e2e/beta/from-import-beta-ui.spec.js index 32f57b157..c271461d3 100644 --- a/test/e2e/beta/from-import-beta-ui.spec.js +++ b/test/e2e/beta/from-import-beta-ui.spec.js @@ -12,9 +12,11 @@ const { } = require('../func') const { checkBrowserForConsoleErrors, + closeAllWindowHandlesExcept, verboseReportOnFailure, findElement, findElements, + loadExtension, } = require('./helpers') @@ -25,6 +27,7 @@ describe('Using MetaMask with an existing account', function () { const testSeedPhrase = 'phrase upgrade clock rough situate wedding elder clever doctor stamp excess tent' const testAddress = '0xE18035BF8712672935FDB4e5e431b1a0183d2DFC' const testPrivateKey2 = '14abe6f4aab7f9f626fe981c864d0adeb5685f289ac9270c27b8fd790b4235d6' + const tinyDelayMs = 500 const regularDelayMs = 1000 const largeDelayMs = regularDelayMs * 2 @@ -74,37 +77,55 @@ describe('Using MetaMask with an existing account', function () { describe('New UI setup', async function () { it('switches to first tab', async function () { + await delay(tinyDelayMs) const [firstTab] = await driver.getAllWindowHandles() await driver.switchTo().window(firstTab) await delay(regularDelayMs) }) - it('use the local network', async function () { - const networkSelector = await findElement(driver, By.css('#network_component')) - await networkSelector.click() - await delay(regularDelayMs) - - const [localhost] = await findElements(driver, By.xpath(`//li[contains(text(), 'Localhost')]`)) - await localhost.click() - await delay(regularDelayMs) - }) - it('selects the new UI option', async () => { - const button = await findElement(driver, By.xpath("//p[contains(text(), 'Try Beta Version')]")) + try { + const overlay = await findElement(driver, By.css('.full-flex-height')) + await driver.wait(until.stalenessOf(overlay)) + } catch (e) {} + + const button = await findElement(driver, By.xpath("//button[contains(text(), 'Try it now')]")) await button.click() await delay(regularDelayMs) // Close all other tabs - const [oldUi, infoPage, newUi] = await driver.getAllWindowHandles() - - const newUiOrInfoPage = newUi || infoPage - await driver.switchTo().window(oldUi) - await driver.close() - if (infoPage !== newUiOrInfoPage) { - await driver.switchTo().window(infoPage) - await driver.close() + const [tab0, tab1, tab2] = await driver.getAllWindowHandles() + await driver.switchTo().window(tab0) + await delay(tinyDelayMs) + + let selectedUrl = await driver.getCurrentUrl() + await delay(tinyDelayMs) + if (tab0 && selectedUrl.match(/popup.html/)) { + await closeAllWindowHandlesExcept(driver, tab0) + } else if (tab1) { + await driver.switchTo().window(tab1) + selectedUrl = await driver.getCurrentUrl() + await delay(tinyDelayMs) + if (selectedUrl.match(/popup.html/)) { + await closeAllWindowHandlesExcept(driver, tab1) + } else if (tab2) { + await driver.switchTo().window(tab2) + selectedUrl = await driver.getCurrentUrl() + selectedUrl.match(/popup.html/) && await closeAllWindowHandlesExcept(driver, tab2) + } + } else { + throw new Error('popup.html not found') } - await driver.switchTo().window(newUiOrInfoPage) + await delay(regularDelayMs) + const [appTab] = await driver.getAllWindowHandles() + await driver.switchTo().window(appTab) + await delay(tinyDelayMs) + + const okayBtn = await findElement(driver, By.xpath("//button[contains(text(), 'Ok')]")) + await okayBtn.click() + await delay(regularDelayMs) + + await loadExtension(driver, extensionId) await delay(regularDelayMs) const continueBtn = await findElement(driver, By.css('.welcome-screen__button')) diff --git a/test/e2e/beta/metamask-beta-ui.spec.js b/test/e2e/beta/metamask-beta-ui.spec.js index ca1977c5a..1590e6d35 100644 --- a/test/e2e/beta/metamask-beta-ui.spec.js +++ b/test/e2e/beta/metamask-beta-ui.spec.js @@ -75,30 +75,11 @@ describe('MetaMask', function () { }) describe('New UI setup', async function () { - let networkSelector it('switches to first tab', async function () { + await delay(tinyDelayMs) const [firstTab] = await driver.getAllWindowHandles() await driver.switchTo().window(firstTab) await delay(regularDelayMs) - try { - networkSelector = await findElement(driver, By.css('#network_component')) - } catch (e) { - await loadExtension(driver, extensionId) - await delay(largeDelayMs * 2) - networkSelector = await findElement(driver, By.css('#network_component')) - } - await delay(regularDelayMs) - }) - - it('uses the local network', async function () { - await networkSelector.click() - await delay(regularDelayMs) - - const networks = await findElements(driver, By.css('.dropdown-menu-item')) - const localhost = networks[4] - await driver.wait(until.elementTextMatches(localhost, /Localhost/)) - await localhost.click() - await delay(regularDelayMs) }) it('selects the new UI option', async () => { @@ -107,27 +88,44 @@ describe('MetaMask', function () { await driver.wait(until.stalenessOf(overlay)) } catch (e) {} - const button = await findElement(driver, By.xpath("//p[contains(text(), 'Try Beta Version')]")) + const button = await findElement(driver, By.xpath("//button[contains(text(), 'Try it now')]")) await button.click() await delay(regularDelayMs) // Close all other tabs - const [oldUi, tab1, tab2] = await driver.getAllWindowHandles() - await driver.switchTo().window(oldUi) - await driver.close() + const [tab0, tab1, tab2] = await driver.getAllWindowHandles() + await driver.switchTo().window(tab0) + await delay(tinyDelayMs) - await driver.switchTo().window(tab1) - const tab1Url = await driver.getCurrentUrl() - if (tab1Url.match(/metamask.io/)) { - await driver.switchTo().window(tab1) - await driver.close() - await driver.switchTo().window(tab2) - } else if (tab2) { - await driver.switchTo().window(tab2) - await driver.close() + let selectedUrl = await driver.getCurrentUrl() + await delay(tinyDelayMs) + if (tab0 && selectedUrl.match(/popup.html/)) { + await closeAllWindowHandlesExcept(driver, tab0) + } else if (tab1) { await driver.switchTo().window(tab1) + selectedUrl = await driver.getCurrentUrl() + await delay(tinyDelayMs) + if (selectedUrl.match(/popup.html/)) { + await closeAllWindowHandlesExcept(driver, tab1) + } else if (tab2) { + await driver.switchTo().window(tab2) + selectedUrl = await driver.getCurrentUrl() + selectedUrl.match(/popup.html/) && await closeAllWindowHandlesExcept(driver, tab2) + } + } else { + throw new Error('popup.html not found') } await delay(regularDelayMs) + const [appTab] = await driver.getAllWindowHandles() + await driver.switchTo().window(appTab) + await delay(tinyDelayMs) + + const okayBtn = await findElement(driver, By.xpath("//button[contains(text(), 'Ok')]")) + await okayBtn.click() + await delay(regularDelayMs) + + await loadExtension(driver, extensionId) + await delay(regularDelayMs) const continueBtn = await findElement(driver, By.css('.welcome-screen__button')) await continueBtn.click() diff --git a/test/e2e/metamask.spec.js b/test/e2e/metamask.spec.js index b6efae5b3..ac7600f09 100644 --- a/test/e2e/metamask.spec.js +++ b/test/e2e/metamask.spec.js @@ -59,6 +59,13 @@ describe('Metamask popup page', function () { await driver.switchTo().window(windowHandles[0]) }) + it('does not select the new UI option', async () => { + await delay(300) + const button = await driver.findElement(By.xpath("//button[contains(text(), 'No thanks, maybe later')]")) + await button.click() + await delay(1000) + }) + it('sets provider type to localhost', async function () { await delay(300) await setProviderType('localhost') @@ -133,9 +140,9 @@ describe('Metamask popup page', function () { }) it('adds a second account', async function () { - await driver.findElement(By.css('#app-content > div > div.full-width > div > div:nth-child(2) > span > div')).click() + await driver.findElement(By.css('div.full-width > div > div:nth-child(2) > span > div')).click() await delay(300) - await driver.findElement(By.css('#app-content > div > div.full-width > div > div:nth-child(2) > span > div > div > span > div > li:nth-child(3) > span')).click() + await driver.findElement(By.css('div.full-width > div > div:nth-child(2) > span > div > div > span > div > li:nth-child(3) > span')).click() }) it('shows account address', async function () { @@ -146,7 +153,7 @@ describe('Metamask popup page', function () { it('logs out of the vault', async () => { await driver.findElement(By.css('.sandwich-expando')).click() await delay(500) - const logoutButton = await driver.findElement(By.css('#app-content > div > div:nth-child(3) > span > div > li:nth-child(3)')) + const logoutButton = await driver.findElement(By.css('.menu-droppo > li:nth-child(3)')) assert.equal(await logoutButton.getText(), 'Log Out') await logoutButton.click() }) @@ -178,7 +185,7 @@ describe('Metamask popup page', function () { it('logs out', async function () { await driver.findElement(By.css('.sandwich-expando')).click() await delay(200) - const logOut = await driver.findElement(By.css('#app-content > div > div:nth-child(3) > span > div > li:nth-child(3)')) + const logOut = await driver.findElement(By.css('.menu-droppo > li:nth-child(3)')) assert.equal(await logOut.getText(), 'Log Out') await logOut.click() await delay(300) -- cgit v1.2.3