Ported relevant parts of the example-addon-repo test/utils.js before deleting it (ours is more up to date)
This commit is contained in:
Родитель
68b861e869
Коммит
e8a25bfc8c
|
@ -1,116 +0,0 @@
|
|||
/* eslint-env node */
|
||||
/* eslint no-console:off */
|
||||
|
||||
"use strict";
|
||||
|
||||
// The geckodriver package downloads and installs geckodriver for us.
|
||||
// We use it by requiring it.
|
||||
require("geckodriver");
|
||||
|
||||
const firefox = require("selenium-webdriver/firefox");
|
||||
const webdriver = require("selenium-webdriver");
|
||||
const FxRunnerUtils = require("fx-runner/lib/utils");
|
||||
const Fs = require("fs-promise");
|
||||
const By = webdriver.By;
|
||||
const Context = firefox.Context;
|
||||
const until = webdriver.until;
|
||||
const path = require("path");
|
||||
|
||||
// Note: Geckodriver already has quite a good set of default preferences
|
||||
// for disabling various items.
|
||||
// https://github.com/mozilla/geckodriver/blob/master/src/marionette.rs
|
||||
const FIREFOX_PREFERENCES = {
|
||||
// Ensure e10s is turned on.
|
||||
"browser.tabs.remote.autostart": true,
|
||||
"browser.tabs.remote.autostart.1": true,
|
||||
"browser.tabs.remote.autostart.2": true,
|
||||
// These are good to have set up if you're debugging tests with the browser
|
||||
// toolbox.
|
||||
"devtools.chrome.enabled": true,
|
||||
"devtools.debugger.remote-enabled": true,
|
||||
};
|
||||
|
||||
function promiseActualBinary(binary) {
|
||||
return FxRunnerUtils.normalizeBinary(binary)
|
||||
.then(normalizedBinary =>
|
||||
Fs.stat(normalizedBinary).then(() => normalizedBinary),
|
||||
)
|
||||
.catch(ex => {
|
||||
if (ex.code === "ENOENT") {
|
||||
throw new Error("Could not find ${binary}");
|
||||
}
|
||||
throw ex;
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.promiseSetupDriver = () => {
|
||||
const profile = new firefox.Profile();
|
||||
|
||||
Object.keys(FIREFOX_PREFERENCES).forEach(key => {
|
||||
profile.setPreference(key, FIREFOX_PREFERENCES[key]);
|
||||
});
|
||||
|
||||
const options = new firefox.Options();
|
||||
options.setProfile(profile);
|
||||
|
||||
const builder = new webdriver.Builder()
|
||||
.forBrowser("firefox")
|
||||
.setFirefoxOptions(options);
|
||||
|
||||
return promiseActualBinary(process.env.FIREFOX_BINARY || "firefox")
|
||||
.then(binaryLocation =>
|
||||
options.setBinary(new firefox.Binary(binaryLocation)),
|
||||
)
|
||||
.then(() => builder.build())
|
||||
.then(driver => {
|
||||
driver.setContext(Context.CHROME);
|
||||
|
||||
const fileLocation = path.join(process.cwd(), process.env.XPI_NAME);
|
||||
|
||||
// This manually installs the add-on as a temporary add-on.
|
||||
// Hopefully selenium/geckodriver will get a way to do this soon:
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1298025
|
||||
return driver
|
||||
.executeAsyncScript(
|
||||
"let fileUtils = Components.utils.import('resource://gre/modules/FileUtils.jsm');" +
|
||||
"let FileUtils = fileUtils.FileUtils;" +
|
||||
"let callback = arguments[arguments.length - 1];" +
|
||||
"Components.utils.import('resource://gre/modules/AddonManager.jsm');" +
|
||||
"let listener = {" +
|
||||
" onInstallEnded: function(install, addon) {" +
|
||||
" callback([addon.id, 0]);" +
|
||||
" }," +
|
||||
" onInstallFailed: function(install) {" +
|
||||
" callback([null, install.error]);" +
|
||||
" }," +
|
||||
" onInstalled: function(addon) {" +
|
||||
" AddonManager.removeAddonListener(listener);" +
|
||||
" callback([addon.id, 0]);" +
|
||||
" }" +
|
||||
"};" +
|
||||
"let file = new FileUtils.File(arguments[0]);" +
|
||||
"AddonManager.addAddonListener(listener);" +
|
||||
"AddonManager.installTemporaryAddon(file).catch(error => {" +
|
||||
" Components.utils.reportError(error); callback([null, error])" +
|
||||
"});",
|
||||
fileLocation,
|
||||
)
|
||||
.then(result => {
|
||||
if (!result[0] && result[1]) {
|
||||
return driver.quit().then(() => {
|
||||
throw new Error(`Failed to install add-on: ${result[1]}`);
|
||||
});
|
||||
}
|
||||
|
||||
return driver;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.promiseAddonButton = driver => {
|
||||
driver.setContext(Context.CHROME);
|
||||
return driver.wait(
|
||||
until.elementLocated(By.id("exampleaddonrepo_mozilla_org-browser-action")),
|
||||
1000,
|
||||
);
|
||||
};
|
|
@ -6,14 +6,13 @@
|
|||
require("geckodriver");
|
||||
const cmd = require("selenium-webdriver/lib/command");
|
||||
const firefox = require("selenium-webdriver/firefox");
|
||||
const Fs = require("fs-extra");
|
||||
const FxRunnerUtils = require("fx-runner/lib/utils");
|
||||
const path = require("path");
|
||||
const webdriver = require("selenium-webdriver");
|
||||
|
||||
const FxRunnerUtils = require("fx-runner/lib/utils");
|
||||
const Fs = require("fs-extra");
|
||||
const By = webdriver.By;
|
||||
const Context = firefox.Context;
|
||||
const until = webdriver.until;
|
||||
const path = require("path");
|
||||
|
||||
// Note: Geckodriver already has quite a good set of default preferences
|
||||
// for disabling various items.
|
||||
|
@ -61,7 +60,6 @@ async function promiseActualBinary(binary) {
|
|||
|
||||
/**
|
||||
* Uses process.env.FIREFOX_BINARY
|
||||
*
|
||||
*/
|
||||
module.exports.promiseSetupDriver = async() => {
|
||||
const profile = new firefox.Profile();
|
||||
|
@ -135,6 +133,14 @@ module.exports.removeButtonFromNavbar = async(driver, buttonId) => {
|
|||
}
|
||||
};
|
||||
|
||||
module.exports.promiseAddonButton = driver => {
|
||||
driver.setContext(Context.CHROME);
|
||||
return driver.wait(
|
||||
until.elementLocated(By.id("exampleaddonrepo_mozilla_org-browser-action")),
|
||||
1000,
|
||||
);
|
||||
};
|
||||
|
||||
module.exports.installAddon = async(driver, fileLocation) => {
|
||||
// references:
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1298025
|
||||
|
|
Загрузка…
Ссылка в новой задаче