aboutsummaryrefslogtreecommitdiffstats
path: root/test/e2e/func.js
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2018-06-12 05:25:49 +0800
committerkumavis <aaron@kumavis.me>2018-06-12 05:25:49 +0800
commitebb9447593a877cd299e701ddfcb217070068fac (patch)
tree74380d5656a8ff3d36aa47ae27d4c69b225f76ff /test/e2e/func.js
parent02f5502e16fefc8d92392e614861e3f672c4f909 (diff)
downloadtangerine-wallet-browser-ebb9447593a877cd299e701ddfcb217070068fac.tar
tangerine-wallet-browser-ebb9447593a877cd299e701ddfcb217070068fac.tar.gz
tangerine-wallet-browser-ebb9447593a877cd299e701ddfcb217070068fac.tar.bz2
tangerine-wallet-browser-ebb9447593a877cd299e701ddfcb217070068fac.tar.lz
tangerine-wallet-browser-ebb9447593a877cd299e701ddfcb217070068fac.tar.xz
tangerine-wallet-browser-ebb9447593a877cd299e701ddfcb217070068fac.tar.zst
tangerine-wallet-browser-ebb9447593a877cd299e701ddfcb217070068fac.zip
test - e2e - factor out setup phase + rename METAMASK_CONFIG to METAMASK_TEST_CONFIG
Diffstat (limited to 'test/e2e/func.js')
-rw-r--r--test/e2e/func.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/e2e/func.js b/test/e2e/func.js
index 9f06e7f37..60e02a296 100644
--- a/test/e2e/func.js
+++ b/test/e2e/func.js
@@ -3,12 +3,15 @@ require('geckodriver')
const fs = require('fs')
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,
buildChromeWebDriver,
buildFirefoxWebdriver,
installWebExt,
@@ -20,6 +23,37 @@ 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 drive, extensionId, extensionUri
+
+ if (browser === 'chrome') {
+ driver = buildChromeWebDriver(extPath)
+ extensionId = await getExtensionIdChrome(driver)
+ extensionUri = `chrome-extension://${extensionId}/popup.html`
+ } else if (browser === 'firefox') {
+ driver = buildFirefoxWebdriver()
+ await installWebExt(driver, extPath)
+ await delay(700)
+ extensionId = await getExtensionIdFirefox(driver)
+ extensionUri = `moz-extension://${extensionId}/popup.html`
+ } else {
+ throw new Error(`Unknown Browser "${browser}"`)
+ }
+
+ return { driver, extensionId, extensionUri }
+}
+
function buildChromeWebDriver (extPath) {
const tmpProfile = path.join(os.tmpdir(), fs.mkdtempSync('mm-chrome-profile'));
return new webdriver.Builder()