test:e2e - factor out prepareExtensionForTesting

feature/default_network_editable
kumavis 5 years ago committed by Mark Stacey
parent 54491974ec
commit d43a78432f
  1. 38
      test/e2e/address-book.spec.js
  2. 38
      test/e2e/from-import-ui.spec.js
  3. 73
      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 webdriver = require('selenium-webdriver')
const { By, until } = webdriver
const {
delay,
buildChromeWebDriver,
buildFirefoxWebdriver,
installWebExt,
getExtensionIdChrome,
getExtensionIdFirefox,
} = require('./func')
const {
checkBrowserForConsoleErrors,
closeAllWindowHandlesExcept,
findElement,
findElements,
loadExtension,
verboseReportOnFailure,
setupFetchMocking,
prepareExtensionForTesting,
} = require('./helpers')
describe('MetaMask', function () {
@ -33,33 +27,9 @@ describe('MetaMask', function () {
this.bail(true)
before(async function () {
let extensionUrl
switch (process.env.SELENIUM_BROWSER) {
case 'chrome': {
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)
const result = await prepareExtensionForTesting()
driver = result.driver
extensionId = result.extensionId
})
beforeEach(async function () {

@ -1,26 +1,19 @@
const path = require('path')
const assert = require('assert')
const webdriver = require('selenium-webdriver')
const { By, Key, until } = webdriver
const {
delay,
buildChromeWebDriver,
buildFirefoxWebdriver,
installWebExt,
getExtensionIdChrome,
getExtensionIdFirefox,
} = require('./func')
const {
checkBrowserForConsoleErrors,
closeAllWindowHandlesExcept,
verboseReportOnFailure,
findElement,
findElements,
setupFetchMocking,
prepareExtensionForTesting,
} = require('./helpers')
describe('Using MetaMask with an existing account', function () {
let extensionId
let driver
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)
before(async function () {
let extensionUrl
switch (process.env.SELENIUM_BROWSER) {
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)
const result = await prepareExtensionForTesting()
driver = result.driver
})
beforeEach(async function () {

@ -1,11 +1,23 @@
const fs = require('fs')
const path = require('path')
const mkdirp = require('mkdirp')
const pify = require('pify')
const assert = require('assert')
const { delay } = require('./func')
const {
delay,
getExtensionIdChrome,
getExtensionIdFirefox,
buildChromeWebDriver,
buildFirefoxWebdriver,
installWebExt,
} = require('./func')
const { until } = require('selenium-webdriver')
const fetchMockResponses = require('./fetch-mocks.js')
const tinyDelayMs = 200
const regularDelayMs = tinyDelayMs * 2
const largeDelayMs = regularDelayMs * 2
module.exports = {
assertElementNotPresent,
@ -20,26 +32,67 @@ module.exports = {
verboseReportOnFailure,
waitUntilXWindowHandles,
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) {
// define fetchMocking script, to be evaluated in the browser
function fetchMocking() {
function fetchMocking () {
window.origFetch = window.fetch.bind(window)
window.fetch = async (...args) => {
const url = args[0]
if (url === "https://ethgasstation.info/json/ethgasAPI.json") {
return { json: async () => JSON.parse( fetchMockResponses.ethGasBasic ) }
} else if (url === "https://ethgasstation.info/json/predictTable.json") {
return { json: async () => JSON.parse( fetchMockResponses.ethGasPredictTable ) }
if (url === 'https://ethgasstation.info/json/ethgasAPI.json') {
return { json: async () => JSON.parse(fetchMockResponses.ethGasBasic) }
} else if (url === 'https://ethgasstation.info/json/predictTable.json') {
return { json: async () => JSON.parse(fetchMockResponses.ethGasPredictTable) }
} else if (url.match(/chromeextensionmm/)) {
return { json: async () => JSON.parse( fetchMockResponses.metametrics ) }
} else if (url === "https://dev.blockscale.net/api/gasexpress.json") {
return { json: async () => JSON.parse( fetchMockResponses.gasExpress ) }
return { json: async () => JSON.parse(fetchMockResponses.metametrics) }
} else if (url === 'https://dev.blockscale.net/api/gasexpress.json') {
return { json: async () => JSON.parse(fetchMockResponses.gasExpress) }
}
return window.origFetch(...args)
}
function cancelInfuraRequest(requestDetails) {
function cancelInfuraRequest (requestDetails) {
console.log(`fetchMocking - Canceling request: "${requestDetails.url}"`)
return { cancel: true }
}

@ -1,25 +1,19 @@
const path = require('path')
const assert = require('assert')
const webdriver = require('selenium-webdriver')
const { By, until } = webdriver
const {
delay,
buildChromeWebDriver,
buildFirefoxWebdriver,
installWebExt,
getExtensionIdChrome,
getExtensionIdFirefox,
} = require('./func')
const {
assertElementNotPresent,
checkBrowserForConsoleErrors,
closeAllWindowHandlesExcept,
findElement,
findElements,
loadExtension,
openNewPage,
verboseReportOnFailure,
setupFetchMocking,
prepareExtensionForTesting,
} = require('./helpers')
describe('MetaMask', function () {
@ -35,33 +29,9 @@ describe('MetaMask', function () {
this.bail(true)
before(async function () {
let extensionUrl
switch (process.env.SELENIUM_BROWSER) {
case 'chrome': {
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)
const result = await prepareExtensionForTesting()
driver = result.driver
extensionId = result.extensionId
})
beforeEach(async function () {

@ -1,23 +1,17 @@
const path = require('path')
const assert = require('assert')
const webdriver = require('selenium-webdriver')
const { By, until } = webdriver
const {
delay,
buildChromeWebDriver,
buildFirefoxWebdriver,
installWebExt,
getExtensionIdChrome,
getExtensionIdFirefox,
} = require('./func')
const {
checkBrowserForConsoleErrors,
closeAllWindowHandlesExcept,
findElement,
findElements,
loadExtension,
verboseReportOnFailure,
setupFetchMocking,
prepareExtensionForTesting,
} = require('./helpers')
describe('MetaMask', function () {
@ -33,33 +27,9 @@ describe('MetaMask', function () {
this.bail(true)
before(async function () {
let extensionUrl
switch (process.env.SELENIUM_BROWSER) {
case 'chrome': {
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)
const result = await prepareExtensionForTesting()
driver = result.driver
extensionId = result.extensionId
})
beforeEach(async function () {

@ -1,14 +1,8 @@
const path = require('path')
const assert = require('assert')
const webdriver = require('selenium-webdriver')
const { By, Key, until } = webdriver
const {
delay,
buildChromeWebDriver,
buildFirefoxWebdriver,
installWebExt,
getExtensionIdChrome,
getExtensionIdFirefox,
} = require('./func')
const {
assertElementNotPresent,
@ -22,6 +16,7 @@ const {
verboseReportOnFailure,
waitUntilXWindowHandles,
setupFetchMocking,
prepareExtensionForTesting,
} = require('./helpers')
describe('MetaMask', function () {
@ -38,33 +33,9 @@ describe('MetaMask', function () {
this.bail(true)
before(async function () {
let extensionUrl
switch (process.env.SELENIUM_BROWSER) {
case 'chrome': {
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)
const result = await prepareExtensionForTesting()
driver = result.driver
extensionId = result.extensionId
})
beforeEach(async function () {

@ -1,26 +1,19 @@
const path = require('path')
const assert = require('assert')
const webdriver = require('selenium-webdriver')
const { By, Key, until } = webdriver
const {
delay,
buildChromeWebDriver,
buildFirefoxWebdriver,
installWebExt,
getExtensionIdChrome,
getExtensionIdFirefox,
} = require('./func')
const {
checkBrowserForConsoleErrors,
closeAllWindowHandlesExcept,
verboseReportOnFailure,
findElement,
findElements,
setupFetchMocking,
prepareExtensionForTesting,
} = require('./helpers')
describe('Using MetaMask with an existing account', function () {
let extensionId
let driver
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)
before(async function () {
let extensionUrl
switch (process.env.SELENIUM_BROWSER) {
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)
const result = await prepareExtensionForTesting()
driver = result.driver
})
beforeEach(async function () {

@ -1,18 +1,11 @@
const path = require('path')
const assert = require('assert')
const webdriver = require('selenium-webdriver')
const { By } = webdriver
const {
delay,
buildChromeWebDriver,
buildFirefoxWebdriver,
installWebExt,
getExtensionIdChrome,
getExtensionIdFirefox,
} = require('./func')
const {
checkBrowserForConsoleErrors,
closeAllWindowHandlesExcept,
findElement,
findElements,
openNewPage,
@ -20,10 +13,10 @@ const {
verboseReportOnFailure,
waitUntilXWindowHandles,
setupFetchMocking,
prepareExtensionForTesting,
} = require('./helpers')
describe('Using MetaMask with an existing account', function () {
let extensionId
let driver
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)
before(async function () {
let extensionUrl
switch (process.env.SELENIUM_BROWSER) {
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)
const result = await prepareExtensionForTesting()
driver = result.driver
})
beforeEach(async function () {

Loading…
Cancel
Save