test:e2e - factor out prepareExtensionForTesting

feature/default_network_editable
kumavis 5 years ago
parent 3afd69b3ec
commit 95b1cfd282
  1. 38
      test/e2e/address-book.spec.js
  2. 38
      test/e2e/from-import-ui.spec.js
  3. 75
      test/e2e/helpers.js
  4. 38
      test/e2e/incremental-security.spec.js
  5. 38
      test/e2e/metamask-responsive-ui.spec.js
  6. 37
      test/e2e/metamask-ui.spec.js
  7. 38
      test/e2e/send-edit.spec.js
  8. 38
      test/e2e/web3.spec.js

@ -1,23 +1,17 @@
const path = require('path')
const assert = require('assert') const assert = require('assert')
const webdriver = require('selenium-webdriver') const webdriver = require('selenium-webdriver')
const { By, until } = webdriver const { By, until } = webdriver
const { const {
delay, delay,
buildChromeWebDriver,
buildFirefoxWebdriver,
installWebExt,
getExtensionIdChrome,
getExtensionIdFirefox,
} = require('./func') } = require('./func')
const { const {
checkBrowserForConsoleErrors, checkBrowserForConsoleErrors,
closeAllWindowHandlesExcept,
findElement, findElement,
findElements, findElements,
loadExtension, loadExtension,
verboseReportOnFailure, verboseReportOnFailure,
setupFetchMocking, setupFetchMocking,
prepareExtensionForTesting,
} = require('./helpers') } = require('./helpers')
describe('MetaMask', function () { describe('MetaMask', function () {
@ -33,33 +27,9 @@ describe('MetaMask', function () {
this.bail(true) this.bail(true)
before(async function () { before(async function () {
let extensionUrl const result = await prepareExtensionForTesting()
switch (process.env.SELENIUM_BROWSER) { driver = result.driver
case 'chrome': { extensionId = result.extensionId
const extPath = path.resolve('dist/chrome')
driver = buildChromeWebDriver(extPath)
extensionId = await getExtensionIdChrome(driver)
await delay(largeDelayMs)
extensionUrl = `chrome-extension://${extensionId}/home.html`
break
}
case 'firefox': {
const extPath = path.resolve('dist/firefox')
driver = buildFirefoxWebdriver()
await installWebExt(driver, extPath)
await delay(largeDelayMs)
extensionId = await getExtensionIdFirefox(driver)
extensionUrl = `moz-extension://${extensionId}/home.html`
break
}
}
// Depending on the state of the application built into the above directory (extPath) and the value of
// METAMASK_DEBUG we will see different post-install behaviour and possibly some extra windows. Here we
// are closing any extraneous windows to reset us to a single window before continuing.
const [tab1] = await driver.getAllWindowHandles()
await closeAllWindowHandlesExcept(driver, [tab1])
await driver.switchTo().window(tab1)
await driver.get(extensionUrl)
}) })
beforeEach(async function () { beforeEach(async function () {

@ -1,26 +1,19 @@
const path = require('path')
const assert = require('assert') const assert = require('assert')
const webdriver = require('selenium-webdriver') const webdriver = require('selenium-webdriver')
const { By, Key, until } = webdriver const { By, Key, until } = webdriver
const { const {
delay, delay,
buildChromeWebDriver,
buildFirefoxWebdriver,
installWebExt,
getExtensionIdChrome,
getExtensionIdFirefox,
} = require('./func') } = require('./func')
const { const {
checkBrowserForConsoleErrors, checkBrowserForConsoleErrors,
closeAllWindowHandlesExcept,
verboseReportOnFailure, verboseReportOnFailure,
findElement, findElement,
findElements, findElements,
setupFetchMocking, setupFetchMocking,
prepareExtensionForTesting,
} = require('./helpers') } = require('./helpers')
describe('Using MetaMask with an existing account', function () { describe('Using MetaMask with an existing account', function () {
let extensionId
let driver let driver
const testSeedPhrase = 'forum vessel pink push lonely enact gentle tail admit parrot grunt dress' const testSeedPhrase = 'forum vessel pink push lonely enact gentle tail admit parrot grunt dress'
@ -35,33 +28,8 @@ describe('Using MetaMask with an existing account', function () {
this.bail(true) this.bail(true)
before(async function () { before(async function () {
let extensionUrl const result = await prepareExtensionForTesting()
switch (process.env.SELENIUM_BROWSER) { driver = result.driver
case 'chrome': {
const extensionPath = path.resolve('dist/chrome')
driver = buildChromeWebDriver(extensionPath)
extensionId = await getExtensionIdChrome(driver)
await delay(regularDelayMs)
extensionUrl = `chrome-extension://${extensionId}/home.html`
break
}
case 'firefox': {
const extensionPath = path.resolve('dist/firefox')
driver = buildFirefoxWebdriver()
await installWebExt(driver, extensionPath)
await delay(regularDelayMs)
extensionId = await getExtensionIdFirefox(driver)
extensionUrl = `moz-extension://${extensionId}/home.html`
break
}
}
// Depending on the state of the application built into the above directory (extPath) and the value of
// METAMASK_DEBUG we will see different post-install behaviour and possibly some extra windows. Here we
// are closing any extraneous windows to reset us to a single window before continuing.
const [tab1] = await driver.getAllWindowHandles()
await closeAllWindowHandlesExcept(driver, [tab1])
await driver.switchTo().window(tab1)
await driver.get(extensionUrl)
}) })
beforeEach(async function () { beforeEach(async function () {

@ -1,11 +1,23 @@
const fs = require('fs') const fs = require('fs')
const path = require('path')
const mkdirp = require('mkdirp') const mkdirp = require('mkdirp')
const pify = require('pify') const pify = require('pify')
const assert = require('assert') const assert = require('assert')
const { delay } = require('./func')
const {
delay,
getExtensionIdChrome,
getExtensionIdFirefox,
buildChromeWebDriver,
buildFirefoxWebdriver,
installWebExt,
} = require('./func')
const { until } = require('selenium-webdriver') const { until } = require('selenium-webdriver')
const fetchMockResponses = require('./fetch-mocks.js') const fetchMockResponses = require('./fetch-mocks.js')
const tinyDelayMs = 200
const regularDelayMs = tinyDelayMs * 2
const largeDelayMs = regularDelayMs * 2
module.exports = { module.exports = {
assertElementNotPresent, assertElementNotPresent,
@ -20,26 +32,67 @@ module.exports = {
verboseReportOnFailure, verboseReportOnFailure,
waitUntilXWindowHandles, waitUntilXWindowHandles,
setupFetchMocking, setupFetchMocking,
prepareExtensionForTesting,
tinyDelayMs,
regularDelayMs,
largeDelayMs,
}
async function prepareExtensionForTesting () {
let driver, extensionId, extensionUrl
const targetBrowser = process.env.SELENIUM_BROWSER
switch (targetBrowser) {
case 'chrome': {
const extPath = path.resolve('dist/chrome')
driver = buildChromeWebDriver(extPath, { responsive: true })
await delay(largeDelayMs)
extensionId = await getExtensionIdChrome(driver)
extensionUrl = `chrome-extension://${extensionId}/home.html`
break
}
case 'firefox': {
const extPath = path.resolve('dist/firefox')
driver = buildFirefoxWebdriver({ responsive: true })
await installWebExt(driver, extPath)
await delay(largeDelayMs)
extensionId = await getExtensionIdFirefox(driver)
extensionUrl = `moz-extension://${extensionId}/home.html`
break
}
default: {
throw new Error(`prepareExtensionForTesting - unable to prepare extension for unknown browser "${targetBrowser}"`)
}
}
// Depending on the state of the application built into the above directory (extPath) and the value of
// METAMASK_DEBUG we will see different post-install behaviour and possibly some extra windows. Here we
// are closing any extraneous windows to reset us to a single window before continuing.
const [tab1] = await driver.getAllWindowHandles()
await closeAllWindowHandlesExcept(driver, [tab1])
await driver.switchTo().window(tab1)
await driver.get(extensionUrl)
return { driver, extensionId, extensionUrl }
} }
async function setupFetchMocking (driver) { async function setupFetchMocking (driver) {
// define fetchMocking script, to be evaluated in the browser // define fetchMocking script, to be evaluated in the browser
function fetchMocking() { function fetchMocking () {
window.origFetch = window.fetch.bind(window) window.origFetch = window.fetch.bind(window)
window.fetch = async (...args) => { window.fetch = async (...args) => {
const url = args[0] const url = args[0]
if (url === "https://ethgasstation.info/json/ethgasAPI.json") { if (url === 'https://ethgasstation.info/json/ethgasAPI.json') {
return { json: async () => JSON.parse( fetchMockResponses.ethGasBasic ) } return { json: async () => JSON.parse(fetchMockResponses.ethGasBasic) }
} else if (url === "https://ethgasstation.info/json/predictTable.json") { } else if (url === 'https://ethgasstation.info/json/predictTable.json') {
return { json: async () => JSON.parse( fetchMockResponses.ethGasPredictTable ) } return { json: async () => JSON.parse(fetchMockResponses.ethGasPredictTable) }
} else if (url.match(/chromeextensionmm/)) { } else if (url.match(/chromeextensionmm/)) {
return { json: async () => JSON.parse( fetchMockResponses.metametrics ) } return { json: async () => JSON.parse(fetchMockResponses.metametrics) }
} else if (url === "https://dev.blockscale.net/api/gasexpress.json") { } else if (url === 'https://dev.blockscale.net/api/gasexpress.json') {
return { json: async () => JSON.parse( fetchMockResponses.gasExpress ) } return { json: async () => JSON.parse(fetchMockResponses.gasExpress) }
} }
return window.origFetch(...args) return window.origFetch(...args)
} }
function cancelInfuraRequest(requestDetails) { function cancelInfuraRequest (requestDetails) {
console.log(`fetchMocking - Canceling request: "${requestDetails.url}"`) console.log(`fetchMocking - Canceling request: "${requestDetails.url}"`)
return { cancel: true } return { cancel: true }
} }

@ -1,25 +1,19 @@
const path = require('path')
const assert = require('assert') const assert = require('assert')
const webdriver = require('selenium-webdriver') const webdriver = require('selenium-webdriver')
const { By, until } = webdriver const { By, until } = webdriver
const { const {
delay, delay,
buildChromeWebDriver,
buildFirefoxWebdriver,
installWebExt,
getExtensionIdChrome,
getExtensionIdFirefox,
} = require('./func') } = require('./func')
const { const {
assertElementNotPresent, assertElementNotPresent,
checkBrowserForConsoleErrors, checkBrowserForConsoleErrors,
closeAllWindowHandlesExcept,
findElement, findElement,
findElements, findElements,
loadExtension, loadExtension,
openNewPage, openNewPage,
verboseReportOnFailure, verboseReportOnFailure,
setupFetchMocking, setupFetchMocking,
prepareExtensionForTesting,
} = require('./helpers') } = require('./helpers')
describe('MetaMask', function () { describe('MetaMask', function () {
@ -35,33 +29,9 @@ describe('MetaMask', function () {
this.bail(true) this.bail(true)
before(async function () { before(async function () {
let extensionUrl const result = await prepareExtensionForTesting()
switch (process.env.SELENIUM_BROWSER) { driver = result.driver
case 'chrome': { extensionId = result.extensionId
const extPath = path.resolve('dist/chrome')
driver = buildChromeWebDriver(extPath)
extensionId = await getExtensionIdChrome(driver)
await delay(largeDelayMs)
extensionUrl = `chrome-extension://${extensionId}/home.html`
break
}
case 'firefox': {
const extPath = path.resolve('dist/firefox')
driver = buildFirefoxWebdriver()
await installWebExt(driver, extPath)
await delay(largeDelayMs)
extensionId = await getExtensionIdFirefox(driver)
extensionUrl = `moz-extension://${extensionId}/home.html`
break
}
}
// Depending on the state of the application built into the above directory (extPath) and the value of
// METAMASK_DEBUG we will see different post-install behaviour and possibly some extra windows. Here we
// are closing any extraneous windows to reset us to a single window before continuing.
const [tab1] = await driver.getAllWindowHandles()
await closeAllWindowHandlesExcept(driver, [tab1])
await driver.switchTo().window(tab1)
await driver.get(extensionUrl)
}) })
beforeEach(async function () { beforeEach(async function () {

@ -1,23 +1,17 @@
const path = require('path')
const assert = require('assert') const assert = require('assert')
const webdriver = require('selenium-webdriver') const webdriver = require('selenium-webdriver')
const { By, until } = webdriver const { By, until } = webdriver
const { const {
delay, delay,
buildChromeWebDriver,
buildFirefoxWebdriver,
installWebExt,
getExtensionIdChrome,
getExtensionIdFirefox,
} = require('./func') } = require('./func')
const { const {
checkBrowserForConsoleErrors, checkBrowserForConsoleErrors,
closeAllWindowHandlesExcept,
findElement, findElement,
findElements, findElements,
loadExtension, loadExtension,
verboseReportOnFailure, verboseReportOnFailure,
setupFetchMocking, setupFetchMocking,
prepareExtensionForTesting,
} = require('./helpers') } = require('./helpers')
describe('MetaMask', function () { describe('MetaMask', function () {
@ -33,33 +27,9 @@ describe('MetaMask', function () {
this.bail(true) this.bail(true)
before(async function () { before(async function () {
let extensionUrl const result = await prepareExtensionForTesting()
switch (process.env.SELENIUM_BROWSER) { driver = result.driver
case 'chrome': { extensionId = result.extensionId
const extPath = path.resolve('dist/chrome')
driver = buildChromeWebDriver(extPath, { responsive: true })
extensionId = await getExtensionIdChrome(driver)
await delay(largeDelayMs)
extensionUrl = `chrome-extension://${extensionId}/home.html`
break
}
case 'firefox': {
const extPath = path.resolve('dist/firefox')
driver = buildFirefoxWebdriver({ responsive: true })
await installWebExt(driver, extPath)
await delay(largeDelayMs)
extensionId = await getExtensionIdFirefox(driver)
extensionUrl = `moz-extension://${extensionId}/home.html`
break
}
}
// Depending on the state of the application built into the above directory (extPath) and the value of
// METAMASK_DEBUG we will see different post-install behaviour and possibly some extra windows. Here we
// are closing any extraneous windows to reset us to a single window before continuing.
const [tab1] = await driver.getAllWindowHandles()
await closeAllWindowHandlesExcept(driver, [tab1])
await driver.switchTo().window(tab1)
await driver.get(extensionUrl)
}) })
beforeEach(async function () { beforeEach(async function () {

@ -1,14 +1,8 @@
const path = require('path')
const assert = require('assert') const assert = require('assert')
const webdriver = require('selenium-webdriver') const webdriver = require('selenium-webdriver')
const { By, Key, until } = webdriver const { By, Key, until } = webdriver
const { const {
delay, delay,
buildChromeWebDriver,
buildFirefoxWebdriver,
installWebExt,
getExtensionIdChrome,
getExtensionIdFirefox,
} = require('./func') } = require('./func')
const { const {
assertElementNotPresent, assertElementNotPresent,
@ -22,6 +16,7 @@ const {
verboseReportOnFailure, verboseReportOnFailure,
waitUntilXWindowHandles, waitUntilXWindowHandles,
setupFetchMocking, setupFetchMocking,
prepareExtensionForTesting,
} = require('./helpers') } = require('./helpers')
describe('MetaMask', function () { describe('MetaMask', function () {
@ -38,33 +33,9 @@ describe('MetaMask', function () {
this.bail(true) this.bail(true)
before(async function () { before(async function () {
let extensionUrl const result = await prepareExtensionForTesting()
switch (process.env.SELENIUM_BROWSER) { driver = result.driver
case 'chrome': { extensionId = result.extensionId
const extPath = path.resolve('dist/chrome')
driver = buildChromeWebDriver(extPath)
extensionId = await getExtensionIdChrome(driver)
await delay(largeDelayMs)
extensionUrl = `chrome-extension://${extensionId}/home.html`
break
}
case 'firefox': {
const extPath = path.resolve('dist/firefox')
driver = buildFirefoxWebdriver()
await installWebExt(driver, extPath)
await delay(largeDelayMs)
extensionId = await getExtensionIdFirefox(driver)
extensionUrl = `moz-extension://${extensionId}/home.html`
break
}
}
// Depending on the state of the application built into the above directory (extPath) and the value of
// METAMASK_DEBUG we will see different post-install behaviour and possibly some extra windows. Here we
// are closing any extraneous windows to reset us to a single window before continuing.
const [tab1] = await driver.getAllWindowHandles()
await closeAllWindowHandlesExcept(driver, [tab1])
await driver.switchTo().window(tab1)
await driver.get(extensionUrl)
}) })
beforeEach(async function () { beforeEach(async function () {

@ -1,26 +1,19 @@
const path = require('path')
const assert = require('assert') const assert = require('assert')
const webdriver = require('selenium-webdriver') const webdriver = require('selenium-webdriver')
const { By, Key, until } = webdriver const { By, Key, until } = webdriver
const { const {
delay, delay,
buildChromeWebDriver,
buildFirefoxWebdriver,
installWebExt,
getExtensionIdChrome,
getExtensionIdFirefox,
} = require('./func') } = require('./func')
const { const {
checkBrowserForConsoleErrors, checkBrowserForConsoleErrors,
closeAllWindowHandlesExcept,
verboseReportOnFailure, verboseReportOnFailure,
findElement, findElement,
findElements, findElements,
setupFetchMocking, setupFetchMocking,
prepareExtensionForTesting,
} = require('./helpers') } = require('./helpers')
describe('Using MetaMask with an existing account', function () { describe('Using MetaMask with an existing account', function () {
let extensionId
let driver let driver
const testSeedPhrase = 'forum vessel pink push lonely enact gentle tail admit parrot grunt dress' const testSeedPhrase = 'forum vessel pink push lonely enact gentle tail admit parrot grunt dress'
@ -32,33 +25,8 @@ describe('Using MetaMask with an existing account', function () {
this.bail(true) this.bail(true)
before(async function () { before(async function () {
let extensionUrl const result = await prepareExtensionForTesting()
switch (process.env.SELENIUM_BROWSER) { driver = result.driver
case 'chrome': {
const extensionPath = path.resolve('dist/chrome')
driver = buildChromeWebDriver(extensionPath)
extensionId = await getExtensionIdChrome(driver)
await delay(regularDelayMs)
extensionUrl = `chrome-extension://${extensionId}/home.html`
break
}
case 'firefox': {
const extensionPath = path.resolve('dist/firefox')
driver = buildFirefoxWebdriver()
await installWebExt(driver, extensionPath)
await delay(regularDelayMs)
extensionId = await getExtensionIdFirefox(driver)
extensionUrl = `moz-extension://${extensionId}/home.html`
break
}
}
// Depending on the state of the application built into the above directory (extPath) and the value of
// METAMASK_DEBUG we will see different post-install behaviour and possibly some extra windows. Here we
// are closing any extraneous windows to reset us to a single window before continuing.
const [tab1] = await driver.getAllWindowHandles()
await closeAllWindowHandlesExcept(driver, [tab1])
await driver.switchTo().window(tab1)
await driver.get(extensionUrl)
}) })
beforeEach(async function () { beforeEach(async function () {

@ -1,18 +1,11 @@
const path = require('path')
const assert = require('assert') const assert = require('assert')
const webdriver = require('selenium-webdriver') const webdriver = require('selenium-webdriver')
const { By } = webdriver const { By } = webdriver
const { const {
delay, delay,
buildChromeWebDriver,
buildFirefoxWebdriver,
installWebExt,
getExtensionIdChrome,
getExtensionIdFirefox,
} = require('./func') } = require('./func')
const { const {
checkBrowserForConsoleErrors, checkBrowserForConsoleErrors,
closeAllWindowHandlesExcept,
findElement, findElement,
findElements, findElements,
openNewPage, openNewPage,
@ -20,10 +13,10 @@ const {
verboseReportOnFailure, verboseReportOnFailure,
waitUntilXWindowHandles, waitUntilXWindowHandles,
setupFetchMocking, setupFetchMocking,
prepareExtensionForTesting,
} = require('./helpers') } = require('./helpers')
describe('Using MetaMask with an existing account', function () { describe('Using MetaMask with an existing account', function () {
let extensionId
let driver let driver
const testSeedPhrase = 'forum vessel pink push lonely enact gentle tail admit parrot grunt dress' const testSeedPhrase = 'forum vessel pink push lonely enact gentle tail admit parrot grunt dress'
@ -46,33 +39,8 @@ describe('Using MetaMask with an existing account', function () {
this.bail(true) this.bail(true)
before(async function () { before(async function () {
let extensionUrl const result = await prepareExtensionForTesting()
switch (process.env.SELENIUM_BROWSER) { driver = result.driver
case 'chrome': {
const extensionPath = path.resolve('dist/chrome')
driver = buildChromeWebDriver(extensionPath)
extensionId = await getExtensionIdChrome(driver)
await delay(regularDelayMs)
extensionUrl = `chrome-extension://${extensionId}/home.html`
break
}
case 'firefox': {
const extensionPath = path.resolve('dist/firefox')
driver = buildFirefoxWebdriver()
await installWebExt(driver, extensionPath)
await delay(regularDelayMs)
extensionId = await getExtensionIdFirefox(driver)
extensionUrl = `moz-extension://${extensionId}/home.html`
break
}
}
// Depending on the state of the application built into the above directory (extPath) and the value of
// METAMASK_DEBUG we will see different post-install behaviour and possibly some extra windows. Here we
// are closing any extraneous windows to reset us to a single window before continuing.
const [tab1] = await driver.getAllWindowHandles()
await closeAllWindowHandlesExcept(driver, [tab1])
await driver.switchTo().window(tab1)
await driver.get(extensionUrl)
}) })
beforeEach(async function () { beforeEach(async function () {

Loading…
Cancel
Save