| Index: test/firefox.js |
| diff --git a/test/firefox.js b/test/firefox.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..51be0c946f89273d94e3efcf9523b5b2fdf0351f |
| --- /dev/null |
| +++ b/test/firefox.js |
| @@ -0,0 +1,121 @@ |
| +/* |
| + * This file is part of Adblock Plus <https://adblockplus.org/>, |
| + * Copyright (C) 2006-present eyeo GmbH |
| + * |
| + * Adblock Plus is free software: you can redistribute it and/or modify |
| + * it under the terms of the GNU General Public License version 3 as |
| + * published by the Free Software Foundation. |
| + * |
| + * Adblock Plus is distributed in the hope that it will be useful, |
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| + * GNU General Public License for more details. |
| + * |
| + * You should have received a copy of the GNU General Public License |
| + * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| + */ |
| + |
| +"use strict"; |
| + |
| +const {ensureFirefox} = require("../adblockpluscore/test/runners/" + |
| + "firefox_download"); |
| +const webdriver = require("selenium-webdriver"); |
| +const {By, until} = webdriver; |
| + |
| +const FIREFOX_VERSION = "57.0"; |
| + |
| +const Command = require("selenium-webdriver/lib/command").Command; |
|
hub
2018/08/23 12:53:59
you could use destructuring here too.
tlucas
2018/08/23 13:42:14
Could you please explain which lines / how exactly
hub
2018/08/23 14:46:33
change
const Command = require("selenium-webdrive
tlucas
2018/08/23 15:32:05
Thank you!
And no, "npm run lint" did not complai
|
| +const path = require("path"); |
| +const firefox = require("selenium-webdriver/firefox"); |
| + |
| +exports.runFirefox = function(test) |
| +{ |
| + // https://stackoverflow.com/a/45045036 |
| + function installWebExt(driver, extension) |
| + { |
| + let cmd = new Command("moz-install-web-ext") |
| + .setParameter("path", path.resolve(extension)) |
| + .setParameter("temporary", true); |
| + |
| + driver.getExecutor() |
| + .defineCommand(cmd.getName(), "POST", |
| + "/session/:sessionId/moz/addon/install"); |
| + |
| + return driver.schedule(cmd, "installWebExt(" + extension + ")"); |
|
hub
2018/08/23 12:54:00
I'd rather use template a string here:
`installWeb
tlucas
2018/08/23 13:42:15
Done.
|
| + } |
| + |
| + ensureFirefox(FIREFOX_VERSION).then(firefoxPath => |
| + { |
| + let binary = new firefox.Binary(firefoxPath); |
| + |
| + binary.addArguments("-headless"); |
| + |
| + let options = new firefox.Options() |
| + .setBinary(binary); |
| + |
| + let driver = new webdriver.Builder() |
| + .forBrowser("firefox") |
| + .setFirefoxOptions(options) |
| + .build(); |
| + |
| + installWebExt(driver, "./devenv.gecko"); |
| + |
| + driver.wait(() => |
| + // Wait for the firstrun-page to be loaded |
| + driver.getAllWindowHandles().then(handles => |
| + { |
| + if (handles.length > 1) |
| + { |
| + driver.switchTo().window(handles[1]); |
| + return true; |
| + } |
| + return false; |
| + }) |
| + ).then(() => |
| + { |
| + // Navigate to the qunit index |
| + driver.executeScript("location.href = \"qunit/index.html\";"); |
|
hub
2018/08/23 12:54:00
you could go `() => driver.executeScript(...)` (dr
tlucas
2018/08/23 13:42:14
Done.
|
| + }).then(() => |
| + { |
| + // Wait for qunit-results to be present |
| + driver.wait(until.elementLocated(By.id("qunit-testresult"))); |
|
hub
2018/08/23 12:53:59
here too.
tlucas
2018/08/23 13:42:15
Done.
|
| + }).then(() => |
| + { |
| + // Wait for tests to finish |
| + driver.wait(() => |
|
hub
2018/08/23 12:53:59
and here
tlucas
2018/08/23 13:42:14
Done.
|
| + driver.findElement(By.id("qunit-testresult")) |
| + .getAttribute("innerHTML").then(data => |
| + data.search("Tests completed") >= 0)); |
| + }).then(() => |
| + { |
| + // Find passed tests |
| + driver.findElements(By.css("#qunit-tests .pass .test-name")) |
| + .then(elements => |
| + { |
| + for (let elem of elements) |
| + { |
| + elem.getAttribute("innerHTML").then(data => |
| + { |
| + test.ok(true, data); |
| + }); |
| + } |
| + }); |
| + // Find failed tests |
| + driver.findElements(By.css("#qunit-tests .fail .test-name")) |
| + .then(elements => |
| + { |
| + for (let elem of elements) |
| + { |
| + elem.getAttribute("innerHTML").then(data => |
| + { |
| + test.ok(false, "Undefined error in " + data); |
|
hub
2018/08/23 12:54:00
And a template string here too.
tlucas
2018/08/23 13:42:15
Done.
|
| + }); |
| + } |
| + }); |
| + }).then(() => |
| + { |
| + driver.quit(); |
| + test.done(); |
| + }); |
| + }); |
| +}; |