|
|
|
@ -3,17 +3,12 @@ require('geckodriver') |
|
|
|
|
const fs = require('fs-extra') |
|
|
|
|
const os = require('os') |
|
|
|
|
const path = require('path') |
|
|
|
|
const pify = require('pify') |
|
|
|
|
const prependFile = pify(require('prepend-file')) |
|
|
|
|
const webdriver = require('selenium-webdriver') |
|
|
|
|
const Command = require('selenium-webdriver/lib/command').Command |
|
|
|
|
const By = webdriver.By |
|
|
|
|
|
|
|
|
|
module.exports = { |
|
|
|
|
delay, |
|
|
|
|
createModifiedTestBuild, |
|
|
|
|
setupBrowserAndExtension, |
|
|
|
|
verboseReportOnFailure, |
|
|
|
|
buildChromeWebDriver, |
|
|
|
|
buildFirefoxWebdriver, |
|
|
|
|
installWebExt, |
|
|
|
@ -25,37 +20,6 @@ function delay (time) { |
|
|
|
|
return new Promise(resolve => setTimeout(resolve, time)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async function createModifiedTestBuild ({ browser, srcPath }) { |
|
|
|
|
// copy build to test-builds directory
|
|
|
|
|
const extPath = path.resolve(`test-builds/${browser}`) |
|
|
|
|
await fs.ensureDir(extPath) |
|
|
|
|
await fs.copy(srcPath, extPath) |
|
|
|
|
// inject METAMASK_TEST_CONFIG setting default test network
|
|
|
|
|
const config = { NetworkController: { provider: { type: 'localhost' } } } |
|
|
|
|
await prependFile(`${extPath}/background.js`, `window.METAMASK_TEST_CONFIG=${JSON.stringify(config)};\n`) |
|
|
|
|
return { extPath } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async function setupBrowserAndExtension ({ browser, extPath }) { |
|
|
|
|
let driver, extensionId, extensionUri |
|
|
|
|
|
|
|
|
|
if (browser === 'chrome') { |
|
|
|
|
driver = buildChromeWebDriver(extPath) |
|
|
|
|
extensionId = await getExtensionIdChrome(driver) |
|
|
|
|
extensionUri = `chrome-extension://${extensionId}/home.html` |
|
|
|
|
} else if (browser === 'firefox') { |
|
|
|
|
driver = buildFirefoxWebdriver() |
|
|
|
|
await installWebExt(driver, extPath) |
|
|
|
|
await delay(700) |
|
|
|
|
extensionId = await getExtensionIdFirefox(driver) |
|
|
|
|
extensionUri = `moz-extension://${extensionId}/home.html` |
|
|
|
|
} else { |
|
|
|
|
throw new Error(`Unknown Browser "${browser}"`) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return { driver, extensionId, extensionUri } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function buildChromeWebDriver (extPath, opts = {}) { |
|
|
|
|
const tmpProfile = fs.mkdtempSync(path.join(os.tmpdir(), 'mm-chrome-profile')) |
|
|
|
|
const args = [ |
|
|
|
@ -105,13 +69,3 @@ async function installWebExt (driver, extension) { |
|
|
|
|
|
|
|
|
|
return await driver.schedule(cmd, 'installWebExt(' + extension + ')') |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async function verboseReportOnFailure ({ browser, driver, title }) { |
|
|
|
|
const artifactDir = `./test-artifacts/${browser}/${title}` |
|
|
|
|
const filepathBase = `${artifactDir}/test-failure` |
|
|
|
|
await fs.ensureDir(artifactDir) |
|
|
|
|
const screenshot = await driver.takeScreenshot() |
|
|
|
|
await fs.writeFile(`${filepathBase}-screenshot.png`, screenshot, { encoding: 'base64' }) |
|
|
|
|
const htmlSource = await driver.getPageSource() |
|
|
|
|
await fs.writeFile(`${filepathBase}-dom.html`, htmlSource) |
|
|
|
|
} |
|
|
|
|