| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
| 3 * Copyright (C) 2006-present eyeo GmbH | |
| 4 * | |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | |
| 6 * it under the terms of the GNU General Public License version 3 as | |
| 7 * published by the Free Software Foundation. | |
| 8 * | |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12 * GNU General Public License for more details. | |
| 13 * | |
| 14 * You should have received a copy of the GNU General Public License | |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | |
| 16 */ | |
| 17 | |
| 18 "use strict"; | |
| 19 | |
| 20 const FIREFOX_VERSION = "57.0"; | |
| 21 | |
| 22 const path = require("path"); | |
| 23 | |
|
Sebastian Noack
2018/08/23 16:38:44
Nit: Unlike in Python, we generally don't group im
tlucas
2018/08/23 18:56:02
So no grouping at all? Or an arbitrary grouping?
Sebastian Noack
2018/08/23 21:54:20
Just remove the blank line here and in line 28.
tlucas
2018/08/24 10:25:08
Done.
| |
| 24 const webdriver = require("selenium-webdriver"); | |
| 25 const {By, until} = webdriver; | |
| 26 const firefox = require("selenium-webdriver/firefox"); | |
| 27 const {Command} = require("selenium-webdriver/lib/command"); | |
| 28 | |
| 29 const {ensureFirefox} = require("../adblockpluscore/test/runners/" + | |
| 30 "firefox_download"); | |
| 31 | |
| 32 exports.runFirefox = function(test) | |
| 33 { | |
| 34 // https://stackoverflow.com/a/45045036 | |
| 35 function installWebExt(driver, extension) | |
| 36 { | |
| 37 let cmd = new Command("moz-install-web-ext") | |
| 38 .setParameter("path", path.resolve(extension)) | |
| 39 .setParameter("temporary", true); | |
| 40 | |
| 41 driver.getExecutor() | |
| 42 .defineCommand(cmd.getName(), "POST", | |
| 43 "/session/:sessionId/moz/addon/install"); | |
| 44 | |
| 45 return driver.schedule(cmd, `installWebExt(${extension})`); | |
| 46 } | |
| 47 | |
| 48 ensureFirefox(FIREFOX_VERSION).then(firefoxPath => | |
| 49 { | |
| 50 let binary = new firefox.Binary(firefoxPath); | |
| 51 | |
| 52 binary.addArguments("-headless"); | |
| 53 | |
| 54 let options = new firefox.Options() | |
| 55 .setBinary(binary); | |
|
Sebastian Noack
2018/08/23 16:38:44
Nit: The indentation seems a little weird here (an
tlucas
2018/08/23 18:56:02
Done.
| |
| 56 | |
| 57 let driver = new webdriver.Builder() | |
| 58 .forBrowser("firefox") | |
| 59 .setFirefoxOptions(options) | |
| 60 .build(); | |
| 61 | |
| 62 installWebExt(driver, "./devenv.gecko"); | |
| 63 | |
| 64 driver.wait(() => | |
| 65 // Wait for the firstrun-page to be loaded | |
| 66 driver.getAllWindowHandles().then(handles => | |
| 67 { | |
| 68 if (handles.length > 1) | |
| 69 { | |
| 70 driver.switchTo().window(handles[1]); | |
| 71 return true; | |
| 72 } | |
| 73 return false; | |
| 74 }) | |
| 75 ).then(() => | |
| 76 // Navigate to the qunit index | |
| 77 driver.executeScript("location.href = \"qunit/index.html\";") | |
| 78 ).then(() => | |
| 79 // Wait for qunit-results to be present | |
| 80 driver.wait(until.elementLocated(By.id("qunit-testresult"))) | |
| 81 ).then(() => | |
| 82 // Wait for tests to finish | |
| 83 driver.wait(() => | |
| 84 driver.findElement(By.id("qunit-testresult")) | |
| 85 .getAttribute("innerHTML").then(data => | |
| 86 data.search("Tests completed") >= 0)) | |
| 87 ).then(() => | |
| 88 { | |
| 89 // Find passed tests | |
| 90 driver.findElements(By.css("#qunit-tests .pass .test-name")) | |
| 91 .then(elements => | |
| 92 { | |
| 93 for (let elem of elements) | |
| 94 { | |
| 95 elem.getAttribute("innerHTML").then(data => | |
| 96 test.ok(true, data)); | |
| 97 } | |
| 98 }); | |
| 99 // Find failed tests | |
| 100 driver.findElements(By.css("#qunit-tests .fail .test-name")) | |
| 101 .then(elements => | |
| 102 { | |
| 103 for (let elem of elements) | |
| 104 { | |
| 105 elem.getAttribute("innerHTML").then(data => | |
| 106 test.ok(false, `Undefined error in ${data}`)); | |
| 107 } | |
| 108 }); | |
| 109 }).then(() => | |
| 110 { | |
| 111 driver.quit(); | |
| 112 test.done(); | |
| 113 }); | |
| 114 }); | |
| 115 }; | |
| OLD | NEW |