Merge pull request #7144 from MetaMask/test-e2e-refactor

Test - small refactor of e2e
feature/default_network_editable
kumavis 5 years ago committed by GitHub
commit e8d1f16400
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 69
      test/e2e/address-book.spec.js
  2. 69
      test/e2e/ethereum-on.spec.js
  3. 6
      test/e2e/fetch-mocks.js
  4. 5930
      test/e2e/fetch-mocks.json
  5. 70
      test/e2e/from-import-ui.spec.js
  6. 96
      test/e2e/helpers.js
  7. 69
      test/e2e/incremental-security.spec.js
  8. 69
      test/e2e/metamask-responsive-ui.spec.js
  9. 68
      test/e2e/metamask-ui.spec.js
  10. 70
      test/e2e/send-edit.spec.js
  11. 70
      test/e2e/web3.spec.js
  12. 2
      test/integration/lib/confirm-sig-requests.js
  13. 2
      test/integration/lib/currency-localization.js
  14. 2
      test/integration/lib/tx-list-items.js

@ -1,24 +1,18 @@
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,
prepareExtensionForTesting,
} = require('./helpers') } = require('./helpers')
const fetchMockResponses = require('./fetch-mocks.js')
describe('MetaMask', function () { describe('MetaMask', function () {
let extensionId let extensionId
@ -33,61 +27,10 @@ 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') await setupFetchMocking(driver)
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 () {
await driver.executeScript(
'window.origFetch = window.fetch.bind(window);' +
'window.fetch = ' +
'(...args) => { ' +
'if (args[0] === "https://ethgasstation.info/json/ethgasAPI.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.ethGasBasic + '\')) }); } else if ' +
'(args[0] === "https://ethgasstation.info/json/predictTable.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.ethGasPredictTable + '\')) }); } else if ' +
'(args[0].match(/chromeextensionmm/)) { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.metametrics + '\')) }); } else if ' +
'(args[0] === "https://dev.blockscale.net/api/gasexpress.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.gasExpress + '\')) }); } ' +
'return window.origFetch(...args); };' +
'function cancelInfuraRequest(requestDetails) {' +
'console.log("Canceling: " + requestDetails.url);' +
'return {' +
'cancel: true' +
'};' +
' }' +
'window.chrome && window.chrome.webRequest && window.chrome.webRequest.onBeforeRequest.addListener(' +
'cancelInfuraRequest,' +
'{urls: ["https://*.infura.io/*"]},' +
'["blocking"]' +
');'
)
}) })
afterEach(async function () { afterEach(async function () {

@ -1,29 +1,22 @@
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,
openNewPage, openNewPage,
verboseReportOnFailure, verboseReportOnFailure,
waitUntilXWindowHandles, waitUntilXWindowHandles,
switchToWindowWithTitle, switchToWindowWithTitle,
setupFetchMocking,
prepareExtensionForTesting,
} = require('./helpers') } = require('./helpers')
const fetchMockResponses = require('./fetch-mocks.js')
describe('MetaMask', function () { describe('MetaMask', function () {
let extensionId
let driver let driver
let publicAddress let publicAddress
@ -35,61 +28,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': { await setupFetchMocking(driver)
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 () {
await driver.executeScript(
'window.origFetch = window.fetch.bind(window);' +
'window.fetch = ' +
'(...args) => { ' +
'if (args[0] === "https://ethgasstation.info/json/ethgasAPI.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.ethGasBasic + '\')) }); } else if ' +
'(args[0] === "https://ethgasstation.info/json/predictTable.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.ethGasPredictTable + '\')) }); } else if ' +
'(args[0].match(/chromeextensionmm/)) { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.metametrics + '\')) }); } else if ' +
'(args[0] === "https://dev.blockscale.net/api/gasexpress.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.gasExpress + '\')) }); } ' +
'return window.origFetch(...args); };' +
'function cancelInfuraRequest(requestDetails) {' +
'console.log("Canceling: " + requestDetails.url);' +
'return {' +
'cancel: true' +
'};' +
' }' +
'window.chrome && window.chrome.webRequest && window.chrome.webRequest.onBeforeRequest.addListener(' +
'cancelInfuraRequest,' +
'{urls: ["https://*.infura.io/*"]},' +
'["blocking"]' +
');'
)
}) })
afterEach(async function () { afterEach(async function () {

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

@ -1,27 +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,
prepareExtensionForTesting,
} = require('./helpers') } = require('./helpers')
const fetchMockResponses = require('./fetch-mocks.js')
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'
@ -36,61 +28,9 @@ 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': { await setupFetchMocking(driver)
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 () {
await driver.executeScript(
'window.origFetch = window.fetch.bind(window);' +
'window.fetch = ' +
'(...args) => { ' +
'if (args[0] === "https://ethgasstation.info/json/ethgasAPI.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.ethGasBasic + '\')) }); } else if ' +
'(args[0] === "https://ethgasstation.info/json/predictTable.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.ethGasPredictTable + '\')) }); } else if ' +
'(args[0].match(/chromeextensionmm/)) { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.metametrics + '\')) }); } else if ' +
'(args[0] === "https://dev.blockscale.net/api/gasexpress.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.gasExpress + '\')) }); } ' +
'return window.origFetch(...args); };' +
'function cancelInfuraRequest(requestDetails) {' +
'console.log("Canceling: " + requestDetails.url);' +
'return {' +
'cancel: true' +
'};' +
' }' +
'window.chrome && window.chrome.webRequest && window.chrome.webRequest.onBeforeRequest.addListener(' +
'cancelInfuraRequest,' +
'{urls: ["https://*.infura.io/*"]},' +
'["blocking"]' +
');'
)
}) })
afterEach(async function () { afterEach(async function () {

@ -1,9 +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.json')
const tinyDelayMs = 200
const regularDelayMs = tinyDelayMs * 2
const largeDelayMs = regularDelayMs * 2
module.exports = { module.exports = {
assertElementNotPresent, assertElementNotPresent,
@ -17,6 +31,86 @@ module.exports = {
switchToWindowWithUrlThatMatches, switchToWindowWithUrlThatMatches,
verboseReportOnFailure, verboseReportOnFailure,
waitUntilXWindowHandles, waitUntilXWindowHandles,
setupFetchMocking,
prepareExtensionForTesting,
tinyDelayMs,
regularDelayMs,
largeDelayMs,
}
async function prepareExtensionForTesting ({ responsive } = {}) {
let driver, extensionId, extensionUrl
const targetBrowser = process.env.SELENIUM_BROWSER
switch (targetBrowser) {
case 'chrome': {
const extPath = path.resolve('dist/chrome')
driver = buildChromeWebDriver(extPath, { responsive })
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 })
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.
// wait an extra long time so any slow popups can trigger
await delay(4 * largeDelayMs)
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 (fetchMockResponses) {
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 () => clone(fetchMockResponses.ethGasBasic) }
} else if (url === 'https://ethgasstation.info/json/predictTable.json') {
return { json: async () => clone(fetchMockResponses.ethGasPredictTable) }
} else if (url.match(/chromeextensionmm/)) {
return { json: async () => clone(fetchMockResponses.metametrics) }
} else if (url === 'https://dev.blockscale.net/api/gasexpress.json') {
return { json: async () => clone(fetchMockResponses.gasExpress) }
}
return window.origFetch(...args)
}
if (window.chrome && window.chrome.webRequest) {
window.chrome.webRequest.onBeforeRequest.addListener(cancelInfuraRequest, {urls: ['https://*.infura.io/*']}, ['blocking'])
}
function cancelInfuraRequest (requestDetails) {
console.log(`fetchMocking - Canceling request: "${requestDetails.url}"`)
return { cancel: true }
}
function clone (obj) {
return JSON.parse(JSON.stringify(obj))
}
}
// fetchMockResponses are parsed last minute to ensure that objects are uniquely instantiated
const fetchMockResponsesJson = JSON.stringify(fetchMockResponses)
// eval the fetchMocking script in the browser
await driver.executeScript(`(${fetchMocking})(${fetchMockResponsesJson})`)
} }
async function loadExtension (driver, extensionId) { async function loadExtension (driver, extensionId) {

@ -1,26 +1,20 @@
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,
prepareExtensionForTesting,
} = require('./helpers') } = require('./helpers')
const fetchMockResponses = require('./fetch-mocks.js')
describe('MetaMask', function () { describe('MetaMask', function () {
let extensionId let extensionId
@ -35,61 +29,10 @@ 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') await setupFetchMocking(driver)
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 () {
await driver.executeScript(
'window.origFetch = window.fetch.bind(window);' +
'window.fetch = ' +
'(...args) => { ' +
'if (args[0] === "https://ethgasstation.info/json/ethgasAPI.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.ethGasBasic + '\')) }); } else if ' +
'(args[0] === "https://ethgasstation.info/json/predictTable.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.ethGasPredictTable + '\')) }); } else if ' +
'(args[0].match(/chromeextensionmm/)) { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.metametrics + '\')) }); } else if ' +
'(args[0] === "https://dev.blockscale.net/api/gasexpress.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.gasExpress + '\')) }); } ' +
'return window.origFetch(...args); };' +
'function cancelInfuraRequest(requestDetails) {' +
'console.log("Canceling: " + requestDetails.url);' +
'return {' +
'cancel: true' +
'};' +
' }' +
'window.chrome && window.chrome.webRequest && window.chrome.webRequest.onBeforeRequest.addListener(' +
'cancelInfuraRequest,' +
'{urls: ["https://*.infura.io/*"]},' +
'["blocking"]' +
');'
)
}) })
afterEach(async function () { afterEach(async function () {

@ -1,24 +1,18 @@
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,
prepareExtensionForTesting,
} = require('./helpers') } = require('./helpers')
const fetchMockResponses = require('./fetch-mocks.js')
describe('MetaMask', function () { describe('MetaMask', function () {
let extensionId let extensionId
@ -33,61 +27,10 @@ describe('MetaMask', function () {
this.bail(true) this.bail(true)
before(async function () { before(async function () {
let extensionUrl const result = await prepareExtensionForTesting({ responsive: true })
switch (process.env.SELENIUM_BROWSER) { driver = result.driver
case 'chrome': { extensionId = result.extensionId
const extPath = path.resolve('dist/chrome') await setupFetchMocking(driver)
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 () {
await driver.executeScript(
'window.origFetch = window.fetch.bind(window);' +
'window.fetch = ' +
'(...args) => { ' +
'if (args[0] === "https://ethgasstation.info/json/ethgasAPI.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.ethGasBasic + '\')) }); } else if ' +
'(args[0] === "https://ethgasstation.info/json/predictTable.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.ethGasPredictTable + '\')) }); } else if ' +
'(args[0].match(/chromeextensionmm/)) { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.metametrics + '\')) }); } else if ' +
'(args[0] === "https://dev.blockscale.net/api/gasexpress.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.gasExpress + '\')) }); } ' +
'return window.origFetch(...args); };' +
'function cancelInfuraRequest(requestDetails) {' +
'console.log("Canceling: " + requestDetails.url);' +
'return {' +
'cancel: true' +
'};' +
' }' +
'window.chrome && window.chrome.webRequest && window.chrome.webRequest.onBeforeRequest.addListener(' +
'cancelInfuraRequest,' +
'{urls: ["https://*.infura.io/*"]},' +
'["blocking"]' +
');'
)
}) })
afterEach(async function () { afterEach(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,
@ -21,8 +15,9 @@ const {
switchToWindowWithTitle, switchToWindowWithTitle,
verboseReportOnFailure, verboseReportOnFailure,
waitUntilXWindowHandles, waitUntilXWindowHandles,
setupFetchMocking,
prepareExtensionForTesting,
} = require('./helpers') } = require('./helpers')
const fetchMockResponses = require('./fetch-mocks.js')
describe('MetaMask', function () { describe('MetaMask', function () {
let extensionId let extensionId
@ -38,61 +33,10 @@ 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') await setupFetchMocking(driver)
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 () {
await driver.executeScript(
'window.origFetch = window.fetch.bind(window);' +
'window.fetch = ' +
'(...args) => { ' +
'if (args[0] === "https://ethgasstation.info/json/ethgasAPI.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.ethGasBasic + '\')) }); } else if ' +
'(args[0] === "https://ethgasstation.info/json/predictTable.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.ethGasPredictTable + '\')) }); } else if ' +
'(args[0].match(/chromeextensionmm/)) { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.metametrics + '\')) }); } else if ' +
'(args[0] === "https://dev.blockscale.net/api/gasexpress.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.gasExpress + '\')) }); } ' +
'return window.origFetch(...args); };' +
'function cancelInfuraRequest(requestDetails) {' +
'console.log("Canceling: " + requestDetails.url);' +
'return {' +
'cancel: true' +
'};' +
' }' +
'window.chrome && window.chrome.webRequest && window.chrome.webRequest.onBeforeRequest.addListener(' +
'cancelInfuraRequest,' +
'{urls: ["https://*.infura.io/*"]},' +
'["blocking"]' +
');'
)
}) })
afterEach(async function () { afterEach(async function () {

@ -1,27 +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,
prepareExtensionForTesting,
} = require('./helpers') } = require('./helpers')
const fetchMockResponses = require('./fetch-mocks.js')
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'
@ -33,61 +25,9 @@ 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': { await setupFetchMocking(driver)
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 () {
await driver.executeScript(
'window.origFetch = window.fetch.bind(window);' +
'window.fetch = ' +
'(...args) => { ' +
'if (args[0] === "https://ethgasstation.info/json/ethgasAPI.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.ethGasBasic + '\')) }); } else if ' +
'(args[0] === "https://ethgasstation.info/json/predictTable.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.ethGasPredictTable + '\')) }); } else if ' +
'(args[0].match(/chromeextensionmm/)) { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.metametrics + '\')) }); } else if ' +
'(args[0] === "https://dev.blockscale.net/api/gasexpress.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.gasExpress + '\')) }); } ' +
'return window.origFetch(...args); };' +
'function cancelInfuraRequest(requestDetails) {' +
'console.log("Canceling: " + requestDetails.url);' +
'return {' +
'cancel: true' +
'};' +
' }' +
'window.chrome && window.chrome.webRequest && window.chrome.webRequest.onBeforeRequest.addListener(' +
'cancelInfuraRequest,' +
'{urls: ["https://*.infura.io/*"]},' +
'["blocking"]' +
');'
)
}) })
afterEach(async function () { afterEach(async function () {

@ -1,30 +1,22 @@
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,
switchToWindowWithTitle, switchToWindowWithTitle,
verboseReportOnFailure, verboseReportOnFailure,
waitUntilXWindowHandles, waitUntilXWindowHandles,
setupFetchMocking,
prepareExtensionForTesting,
} = require('./helpers') } = require('./helpers')
const fetchMockResponses = require('./fetch-mocks.js')
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'
@ -47,61 +39,9 @@ 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': { await setupFetchMocking(driver)
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 () {
await driver.executeScript(
'window.origFetch = window.fetch.bind(window);' +
'window.fetch = ' +
'(...args) => { ' +
'if (args[0] === "https://ethgasstation.info/json/ethgasAPI.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.ethGasBasic + '\')) }); } else if ' +
'(args[0] === "https://ethgasstation.info/json/predictTable.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.ethGasPredictTable + '\')) }); } else if ' +
'(args[0].match(/chromeextensionmm/)) { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.metametrics + '\')) }); } else if ' +
'(args[0] === "https://dev.blockscale.net/api/gasexpress.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.gasExpress + '\')) }); } ' +
'return window.origFetch(...args); };' +
'function cancelInfuraRequest(requestDetails) {' +
'console.log("Canceling: " + requestDetails.url);' +
'return {' +
'cancel: true' +
'};' +
' }' +
'window.chrome && window.chrome.webRequest && window.chrome.webRequest.onBeforeRequest.addListener(' +
'cancelInfuraRequest,' +
'{urls: ["https://*.infura.io/*"]},' +
'["blocking"]' +
');'
)
}) })
afterEach(async function () { afterEach(async function () {

@ -3,7 +3,7 @@ const {
timeout, timeout,
queryAsync, queryAsync,
} = require('../../lib/util') } = require('../../lib/util')
const fetchMockResponses = require('../../e2e/fetch-mocks.js') const fetchMockResponses = require('../../e2e/fetch-mocks.json')
QUnit.module('confirm sig requests') QUnit.module('confirm sig requests')

@ -4,7 +4,7 @@ const {
queryAsync, queryAsync,
findAsync, findAsync,
} = require('../../lib/util') } = require('../../lib/util')
const fetchMockResponses = require('../../e2e/fetch-mocks.js') const fetchMockResponses = require('../../e2e/fetch-mocks.json')
QUnit.module('currency localization') QUnit.module('currency localization')

@ -3,7 +3,7 @@ const {
queryAsync, queryAsync,
findAsync, findAsync,
} = require('../../lib/util') } = require('../../lib/util')
const fetchMockResponses = require('../../e2e/fetch-mocks.js') const fetchMockResponses = require('../../e2e/fetch-mocks.json')
QUnit.module('tx list items') QUnit.module('tx list items')

Loading…
Cancel
Save