diff options
Diffstat (limited to 'test/e2e/func.js')
-rw-r--r-- | test/e2e/func.js | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/test/e2e/func.js b/test/e2e/func.js index 733225565..9f06e7f37 100644 --- a/test/e2e/func.js +++ b/test/e2e/func.js @@ -1,18 +1,63 @@ require('chromedriver') +require('geckodriver') +const fs = require('fs') +const os = require('os') +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.buildWebDriver = function buildWebDriver (extPath) { +function buildChromeWebDriver (extPath) { + const tmpProfile = path.join(os.tmpdir(), fs.mkdtempSync('mm-chrome-profile')); return new webdriver.Builder() .withCapabilities({ chromeOptions: { - args: [`load-extension=${extPath}`], + args: [ + `load-extension=${extPath}`, + `user-data-dir=${tmpProfile}`, + ], + binary: process.env.SELENIUM_CHROME_BINARY, }, }) - .forBrowser('chrome') .build() } + +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 + ')') +} |