Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: test/firefox.js

Issue 29860555: Issue 6717 - Part 2: run qunit in headless firefox (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/file/3270e924ba9f
Patch Set: Created Aug. 24, 2018, 3:25 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « package.json ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 const webdriver = require("selenium-webdriver");
24 const {By, until} = webdriver;
25 const firefox = require("selenium-webdriver/firefox");
26 const {Command} = require("selenium-webdriver/lib/command");
27 const {ensureFirefox} = require("../adblockpluscore/test/runners/" +
28 "firefox_download");
29
30 function reportElements(test, driver, success)
31 {
32 return driver.findElements(
33 By.css(`#qunit-tests ${success ? ".pass" : ".fail"} .test-name`)
34 ).then(elements => Promise.all(elements.map(elem =>
35 elem.getAttribute("innerHTML").then(data => test.ok(success, data))
36 )));
37 }
38
39 exports.runFirefox = function(test)
40 {
41 // https://stackoverflow.com/a/45045036
42 function installWebExt(driver, extension)
43 {
44 let cmd = new Command("moz-install-web-ext")
45 .setParameter("path", path.resolve(extension))
46 .setParameter("temporary", true);
47
48 driver.getExecutor()
49 .defineCommand(cmd.getName(), "POST",
50 "/session/:sessionId/moz/addon/install");
51
52 return driver.schedule(cmd, `installWebExt(${extension})`);
53 }
54
55 ensureFirefox(FIREFOX_VERSION).then(firefoxPath =>
56 {
57 let binary = new firefox.Binary(firefoxPath);
58
59 binary.addArguments("-headless");
60
61 let options = new firefox.Options()
62 .setBinary(binary);
63
64 let driver = new webdriver.Builder()
65 .forBrowser("firefox")
66 .setFirefoxOptions(options)
67 .build();
68
69 installWebExt(driver, "./devenv.gecko");
70
71 driver.wait(() =>
72 // Wait for the firstrun-page to be loaded
73 driver.getAllWindowHandles().then(handles =>
74 {
75 if (handles.length > 1)
76 {
77 driver.switchTo().window(handles[1]);
78 return true;
79 }
80 return false;
81 })
82 ).then(() =>
83 // Navigate to the qunit index
84 driver.executeScript("location.href = \"qunit/index.html\";")
85 ).then(() =>
86 // Wait for qunit-results to be present
87 driver.wait(until.elementLocated(By.id("qunit-testresult")))
88 ).then(() =>
89 // Wait for tests to finish
90 driver.wait(() =>
91 driver.findElement(By.id("qunit-testresult"))
92 .getAttribute("innerHTML").then(data =>
93 data.includes("Tests completed")))
94 ).then(() => Promise.all([
95 reportElements(test, driver, true),
96 reportElements(test, driver, false)
97 ])).then(() =>
98 {
99 driver.quit();
100 test.done();
101 }, err =>
102 driver.quit().then(() =>
103 {
104 throw err;
105 })
106 );
107 });
108 };
OLDNEW
« no previous file with comments | « package.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld