From cd42d1820318739668774af25e9b1318cd2256dd Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 14 May 2018 17:17:36 -0700 Subject: Merge e2e tests into one --- test/e2e/func.js | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'test/e2e/func.js') diff --git a/test/e2e/func.js b/test/e2e/func.js index 4ad0ea615..8b221ce47 100644 --- a/test/e2e/func.js +++ b/test/e2e/func.js @@ -1,13 +1,24 @@ require('chromedriver') require('geckodriver') +const path = require('path') const webdriver = require('selenium-webdriver') +const Command = require('selenium-webdriver/lib/command').Command +const By = webdriver.By -exports.delay = function delay (time) { - return new Promise(resolve => setTimeout(resolve, time)) +module.exports = { + delay, + buildChromeWebDriver, + buildFirefoxWebdriver, + installWebExt, + getExtensionIdChrome, + getExtensionIdFirefox, } +function delay (time) { + return new Promise(resolve => setTimeout(resolve, time)) +} -exports.buildChromeWebDriver = function buildChromeWebDriver (extPath) { +function buildChromeWebDriver (extPath) { return new webdriver.Builder() .withCapabilities({ chromeOptions: { @@ -17,6 +28,29 @@ exports.buildChromeWebDriver = function buildChromeWebDriver (extPath) { .build() } -exports.buildFirefoxWebdriver = function buildFirefoxWebdriver (extPath) { +function buildFirefoxWebdriver () { return new webdriver.Builder().build() } + +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 + ')') +} \ No newline at end of file -- cgit v1.2.3