@ -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 ,
@ -21,8 +15,9 @@ const {
switchToWindowWithTitle ,
verboseReportOnFailure ,
waitUntilXWindowHandles ,
setupFetchMocking ,
prepareExtensionForTesting ,
} = require ( './helpers' )
const fetchMockResponses = require ( './fetch-mocks.js' )
describe ( 'MetaMask' , function ( ) {
let extensionId
@ -38,61 +33,10 @@ 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
extensionId = result . extensionId
await setupFetchMocking ( driver )
} )
afterEach ( async function ( ) {
@ -619,19 +563,20 @@ describe('MetaMask', function () {
const dapp = windowHandles [ 1 ]
await driver . switchTo ( ) . window ( dapp )
await delay ( regu larDelayMs)
await delay ( large DelayMs )
const send3eth = await findElement ( driver , By . xpath ( ` //button[contains(text(), 'Send')] ` ) , 10000 )
await send3eth . click ( )
await delay ( regu larDelayMs)
await delay ( large DelayMs )
const contractDeployment = await findElement ( driver , By . xpath ( ` //button[contains(text(), 'Deploy Contract')] ` ) , 10000 )
await contractDeployment . click ( )
await delay ( regu larDelayMs)
await delay ( large DelayMs )
await send3eth . click ( )
await delay ( largeDelayMs )
await contractDeployment . click ( )
await delay ( regu larDelayMs)
await delay ( large DelayMs )
await driver . switchTo ( ) . window ( extension )
await delay ( regularDelayMs )