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 {
delay,
buildChromeWebDriver,
buildFirefoxWebdriver,
installWebExt,
getExtensionIdChrome,
getExtensionIdFirefox,
createModifiedTestBuild,
setupBrowserAndExtension,
verboseReportOnFailure,
} = require('../func')
const {
checkBrowserForConsoleErrors,
loadExtension,
verboseReportOnFailure,
findElement,
findElements,
} = require('./helpers')
describe('Using MetaMask with an existing account', function () {
const browser = process.env.SELENIUM_BROWSER
let extensionId
let driver
let tokenAddress
@ -34,30 +32,15 @@ describe('Using MetaMask with an existing account', function () {
this.bail(true)
before(async function () {
switch (process.env.SELENIUM_BROWSER) {
case 'chrome': {
const extensionPath = path.resolve('dist/chrome')
driver = buildChromeWebDriver(extensionPath)
extensionId = await getExtensionIdChrome(driver)
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
}
}
const srcPath = path.resolve(`dist/${browser}`)
const { extPath } = await createModifiedTestBuild({ browser, srcPath })
const installResult = await setupBrowserAndExtension({ browser, extPath })
driver = installResult.driver
extensionUri = installResult.extensionUri
})
afterEach(async function () {
if (process.env.SELENIUM_BROWSER === 'chrome') {
if (browser === 'chrome') {
const errors = await checkBrowserForConsoleErrors(driver)
if (errors.length) {
const errorReports = errors.map(err => err.message)
@ -66,7 +49,7 @@ describe('Using MetaMask with an existing account', function () {
}
}
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 mkdirp = require('mkdirp')
const pify = require('pify')
const {until} = require('selenium-webdriver')
const { until } = require('selenium-webdriver')
module.exports = {
checkBrowserForConsoleErrors,
loadExtension,
verboseReportOnFailure,
findElement,
findElements,
}
@ -42,21 +38,6 @@ async function checkBrowserForConsoleErrors (driver) {
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) {
return driver.wait(until.elementLocated(by), timeout)
}

@ -6,13 +6,13 @@ const {
delay,
createModifiedTestBuild,
setupBrowserAndExtension,
verboseReportOnFailure,
} = require('../func')
const {
findElement,
findElements,
checkBrowserForConsoleErrors,
loadExtension,
verboseReportOnFailure,
} = require('./helpers')
describe('MetaMask', function () {
@ -48,7 +48,7 @@ describe('MetaMask', function () {
}
}
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 = {
delay,
createModifiedTestBuild,
verboseReportOnFailure,
buildChromeWebDriver,
buildFirefoxWebdriver,
installWebExt,
@ -95,3 +96,13 @@ 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)
}

@ -4,7 +4,7 @@ const path = require('path')
const assert = require('assert')
const pify = require('pify')
const { By, Key } = require('selenium-webdriver')
const { delay, createModifiedTestBuild, setupBrowserAndExtension } = require('./func')
const { delay, createModifiedTestBuild, setupBrowserAndExtension, verboseReportOnFailure } = require('./func')
describe('Metamask popup page', function () {
const browser = process.env.SELENIUM_BROWSER
@ -36,7 +36,7 @@ describe('Metamask popup page', function () {
}
// gather extra data if test 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
}
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