1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-24 02:58:09 +01:00
metamask-extension/test/e2e/func.js

56 lines
1.7 KiB
JavaScript
Raw Normal View History

require('chromedriver')
2018-05-01 21:18:22 +02:00
require('geckodriver')
2018-05-15 02:17:36 +02:00
const path = require('path')
2017-09-12 23:14:24 +02:00
const webdriver = require('selenium-webdriver')
2018-05-15 02:17:36 +02:00
const Command = require('selenium-webdriver/lib/command').Command
const By = webdriver.By
2017-09-12 23:14:24 +02:00
2018-05-15 02:17:36 +02:00
module.exports = {
delay,
buildChromeWebDriver,
buildFirefoxWebdriver,
installWebExt,
getExtensionIdChrome,
getExtensionIdFirefox,
2017-09-12 23:14:24 +02:00
}
2018-05-15 02:17:36 +02:00
function delay (time) {
return new Promise(resolve => setTimeout(resolve, time))
}
2017-09-12 23:14:24 +02:00
2018-05-15 02:17:36 +02:00
function buildChromeWebDriver (extPath) {
2017-09-12 23:14:24 +02:00
return new webdriver.Builder()
.withCapabilities({
chromeOptions: {
args: [`load-extension=${extPath}`],
},
})
.build()
}
2018-05-01 21:18:22 +02:00
2018-05-15 02:17:36 +02:00
function buildFirefoxWebdriver () {
2018-05-01 21:18:22 +02:00
return new webdriver.Builder().build()
}
2018-05-15 02:17:36 +02:00
async function getExtensionIdChrome (driver) {
await driver.get('chrome://extensions')
const extensionId = await driver.executeScript('return document.querySelector("extensions-manager").shadowRoot.querySelector("extensions-view-manager extensions-item-list").shadowRoot.querySelector("extensions-item:nth-child(2)").getAttribute("id")')
return extensionId
}
async function getExtensionIdFirefox (driver) {
await driver.get('about:debugging#addons')
const extensionId = await driver.findElement(By.css('dd.addon-target-info-content:nth-child(6) > span:nth-child(1)')).getText()
return extensionId
}
async function installWebExt (driver, extension) {
const cmd = await new Command('moz-install-web-ext')
.setParameter('path', path.resolve(extension))
.setParameter('temporary', true)
await driver.getExecutor()
.defineCommand(cmd.getName(), 'POST', '/session/:sessionId/moz/addon/install')
return await driver.schedule(cmd, 'installWebExt(' + extension + ')')
}