test - e2e - more factoring of test setup

feature/default_network_editable
kumavis 7 years ago
parent 907594463d
commit 8a0961b4a8
  1. 39
      test/e2e/beta/from-import-beta-ui.spec.js
  2. 21
      test/e2e/beta/helpers.js
  3. 4
      test/e2e/beta/metamask-beta-ui.spec.js
  4. 11
      test/e2e/func.js
  5. 16
      test/e2e/metamask.spec.js

@ -4,22 +4,20 @@ const webdriver = require('selenium-webdriver')
const { By, Key, until } = webdriver const { By, Key, until } = webdriver
const { const {
delay, delay,
buildChromeWebDriver, createModifiedTestBuild,
buildFirefoxWebdriver, setupBrowserAndExtension,
installWebExt, verboseReportOnFailure,
getExtensionIdChrome,
getExtensionIdFirefox,
} = require('../func') } = require('../func')
const { const {
checkBrowserForConsoleErrors, checkBrowserForConsoleErrors,
loadExtension, loadExtension,
verboseReportOnFailure,
findElement, findElement,
findElements, findElements,
} = require('./helpers') } = require('./helpers')
describe('Using MetaMask with an existing account', function () { describe('Using MetaMask with an existing account', function () {
const browser = process.env.SELENIUM_BROWSER
let extensionId let extensionId
let driver let driver
let tokenAddress let tokenAddress
@ -34,30 +32,15 @@ describe('Using MetaMask with an existing account', function () {
this.bail(true) this.bail(true)
before(async function () { before(async function () {
switch (process.env.SELENIUM_BROWSER) { const srcPath = path.resolve(`dist/${browser}`)
case 'chrome': { const { extPath } = await createModifiedTestBuild({ browser, srcPath })
const extensionPath = path.resolve('dist/chrome') const installResult = await setupBrowserAndExtension({ browser, extPath })
driver = buildChromeWebDriver(extensionPath) driver = installResult.driver
extensionId = await getExtensionIdChrome(driver) extensionUri = installResult.extensionUri
await driver.get(`chrome-extension://${extensionId}/popup.html`)
await delay(regularDelayMs)
break
}
case 'firefox': {
const extensionPath = path.resolve('dist/firefox')
driver = buildFirefoxWebdriver()
await installWebExt(driver, extensionPath)
await delay(regularDelayMs)
extensionId = await getExtensionIdFirefox(driver)
await driver.get(`moz-extension://${extensionId}/popup.html`)
await delay(regularDelayMs)
break
}
}
}) })
afterEach(async function () { afterEach(async function () {
if (process.env.SELENIUM_BROWSER === 'chrome') { if (browser === 'chrome') {
const errors = await checkBrowserForConsoleErrors(driver) const errors = await checkBrowserForConsoleErrors(driver)
if (errors.length) { if (errors.length) {
const errorReports = errors.map(err => err.message) const errorReports = errors.map(err => err.message)
@ -66,7 +49,7 @@ describe('Using MetaMask with an existing account', function () {
} }
} }
if (this.currentTest.state === 'failed') { if (this.currentTest.state === 'failed') {
await verboseReportOnFailure(driver, this.currentTest) await verboseReportOnFailure({ browser, driver, title: this.currentTest.title })
} }
}) })

@ -1,12 +1,8 @@
const fs = require('fs') const { until } = require('selenium-webdriver')
const mkdirp = require('mkdirp')
const pify = require('pify')
const {until} = require('selenium-webdriver')
module.exports = { module.exports = {
checkBrowserForConsoleErrors, checkBrowserForConsoleErrors,
loadExtension, loadExtension,
verboseReportOnFailure,
findElement, findElement,
findElements, findElements,
} }
@ -42,21 +38,6 @@ async function checkBrowserForConsoleErrors (driver) {
return errorObjects.filter(entry => !ignoredErrorMessages.some(message => entry.message.includes(message))) return errorObjects.filter(entry => !ignoredErrorMessages.some(message => entry.message.includes(message)))
} }
async function verboseReportOnFailure (driver, test) {
let artifactDir
if (process.env.SELENIUM_BROWSER === 'chrome') {
artifactDir = `./test-artifacts/chrome/${test.title}`
} else if (process.env.SELENIUM_BROWSER === 'firefox') {
artifactDir = `./test-artifacts/firefox/${test.title}`
}
const filepathBase = `${artifactDir}/test-failure`
await pify(mkdirp)(artifactDir)
const screenshot = await driver.takeScreenshot()
await pify(fs.writeFile)(`${filepathBase}-screenshot.png`, screenshot, { encoding: 'base64' })
const htmlSource = await driver.getPageSource()
await pify(fs.writeFile)(`${filepathBase}-dom.html`, htmlSource)
}
async function findElement (driver, by, timeout = 10000) { async function findElement (driver, by, timeout = 10000) {
return driver.wait(until.elementLocated(by), timeout) return driver.wait(until.elementLocated(by), timeout)
} }

@ -6,13 +6,13 @@ const {
delay, delay,
createModifiedTestBuild, createModifiedTestBuild,
setupBrowserAndExtension, setupBrowserAndExtension,
verboseReportOnFailure,
} = require('../func') } = require('../func')
const { const {
findElement, findElement,
findElements, findElements,
checkBrowserForConsoleErrors, checkBrowserForConsoleErrors,
loadExtension, loadExtension,
verboseReportOnFailure,
} = require('./helpers') } = require('./helpers')
describe('MetaMask', function () { describe('MetaMask', function () {
@ -48,7 +48,7 @@ describe('MetaMask', function () {
} }
} }
if (this.currentTest.state === 'failed') { if (this.currentTest.state === 'failed') {
await verboseReportOnFailure(this.currentTest) await verboseReportOnFailure({ browser, driver, title: this.currentTest.tile })
} }
}) })

@ -12,6 +12,7 @@ const By = webdriver.By
module.exports = { module.exports = {
delay, delay,
createModifiedTestBuild, createModifiedTestBuild,
verboseReportOnFailure,
buildChromeWebDriver, buildChromeWebDriver,
buildFirefoxWebdriver, buildFirefoxWebdriver,
installWebExt, installWebExt,
@ -95,3 +96,13 @@ async function installWebExt (driver, extension) {
return await driver.schedule(cmd, 'installWebExt(' + 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)
}

@ -4,7 +4,7 @@ const path = require('path')
const assert = require('assert') const assert = require('assert')
const pify = require('pify') const pify = require('pify')
const { By, Key } = require('selenium-webdriver') const { By, Key } = require('selenium-webdriver')
const { delay, createModifiedTestBuild, setupBrowserAndExtension } = require('./func') const { delay, createModifiedTestBuild, setupBrowserAndExtension, verboseReportOnFailure } = require('./func')
describe('Metamask popup page', function () { describe('Metamask popup page', function () {
const browser = process.env.SELENIUM_BROWSER const browser = process.env.SELENIUM_BROWSER
@ -36,7 +36,7 @@ describe('Metamask popup page', function () {
} }
// gather extra data if test failed // gather extra data if test failed
if (this.currentTest.state === 'failed') { if (this.currentTest.state === 'failed') {
await verboseReportOnFailure(this.currentTest) await verboseReportOnFailure({ browser, driver, title: this.currentTest.title })
} }
}) })
@ -319,16 +319,4 @@ describe('Metamask popup page', function () {
return matchedErrorObjects return matchedErrorObjects
} }
async function verboseReportOnFailure (test) {
const artifactDir = `./test-artifacts/${browser}/${test.title}`
const filepathBase = `${artifactDir}/test-failure`
await pify(mkdirp)(artifactDir)
// capture screenshot
const screenshot = await driver.takeScreenshot()
await pify(fs.writeFile)(`${filepathBase}-screenshot.png`, screenshot, { encoding: 'base64' })
// capture dom source
const htmlSource = await driver.getPageSource()
await pify(fs.writeFile)(`${filepathBase}-dom.html`, htmlSource)
}
}) })

Loading…
Cancel
Save