Skip to content

Commit

Permalink
Update test/e2e/threebox.spec.js to use new helpers added with pull #…
Browse files Browse the repository at this point in the history
  • Loading branch information
danjm committed Sep 11, 2019
1 parent ef4c74e commit 9fbf587
Showing 1 changed file with 8 additions and 94 deletions.
102 changes: 8 additions & 94 deletions test/e2e/threebox.spec.js
Original file line number Diff line number Diff line change
@@ -1,26 +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 {
checkBrowserForConsoleErrors,
closeAllWindowHandlesExcept,
findElement,
findElements,
verboseReportOnFailure,
setupFetchMocking,
prepareExtensionForTesting,
} = require('./helpers')
const fetchMockResponses = require('./fetch-mocks.js')

describe('MetaMask', function () {
let extensionId
let driver

const testSeedPhrase = 'forum vessel pink push lonely enact gentle tail admit parrot grunt dress'
Expand All @@ -32,62 +25,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)
})

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"]' +
');'
)
const result = await prepareExtensionForTesting()
driver = result.driver
await setupFetchMocking(driver)
})

afterEach(async function () {
Expand Down Expand Up @@ -204,38 +144,12 @@ describe('MetaMask', function () {
})

describe('restoration from 3box', () => {
let extensionId2
let driver2

before(async function () {
let extensionUrl2
switch (process.env.SELENIUM_BROWSER) {
case 'chrome': {
const extPath2 = path.resolve('dist/chrome')
driver2 = buildChromeWebDriver(extPath2)
extensionId2 = await getExtensionIdChrome(driver2)
await delay(largeDelayMs)
extensionUrl2 = `chrome-extension://${extensionId2}/home.html`
break
}
case 'firefox': {
const extPath2 = path.resolve('dist/firefox')
driver2 = buildFirefoxWebdriver()
await installWebExt(driver2, extPath2)
await delay(largeDelayMs)
extensionId2 = await getExtensionIdFirefox(driver2)
extensionUrl2 = `moz-extension://${extensionId2}/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 [tab2] = await driver2.getAllWindowHandles()
await closeAllWindowHandlesExcept(driver2, [tab2])
await driver2.switchTo().window(tab2)
await driver2.get(extensionUrl2)
const result = await prepareExtensionForTesting()
driver2 = result.driver
await setupFetchMocking(driver2)
})

after(async function () {
Expand Down

0 comments on commit 9fbf587

Please sign in to comment.