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, 9:55 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« README.md ('K') | « 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
31 function reportElements(test, driver, css, success)
32 {
33 return driver.findElements(By.css(css)).
34 then(elements => Promise.all(elements.map(elem =>
35 elem.getAttribute("innerHTML").then(data => test.ok(success, data)))));
36 }
37
38 exports.runFirefox = function(test)
39 {
40 // https://stackoverflow.com/a/45045036
41 function installWebExt(driver, extension)
42 {
43 let cmd = new Command("moz-install-web-ext")
44 .setParameter("path", path.resolve(extension))
45 .setParameter("temporary", true);
46
47 driver.getExecutor()
48 .defineCommand(cmd.getName(), "POST",
49 "/session/:sessionId/moz/addon/install");
50
51 return driver.schedule(cmd, `installWebExt(${extension})`);
52 }
53
54 ensureFirefox(FIREFOX_VERSION).then(firefoxPath =>
55 {
56 let binary = new firefox.Binary(firefoxPath);
57
58 binary.addArguments("-headless");
59
60 let options = new firefox.Options()
61 .setBinary(binary);
62
63 let driver = new webdriver.Builder()
64 .forBrowser("firefox")
65 .setFirefoxOptions(options)
66 .build();
67
68 installWebExt(driver, "./devenv.gecko");
69
70 driver.wait(() =>
71 // Wait for the firstrun-page to be loaded
72 driver.getAllWindowHandles().then(handles =>
73 {
74 if (handles.length > 1)
75 {
76 driver.switchTo().window(handles[1]);
77 return true;
78 }
79 return false;
80 })
81 ).then(() =>
82 // Navigate to the qunit index
83 driver.executeScript("location.href = \"qunit/index.html\";")
84 ).then(() =>
85 // Wait for qunit-results to be present
86 driver.wait(until.elementLocated(By.id("qunit-testresult")))
87 ).then(() =>
88 // Wait for tests to finish
89 driver.wait(() =>
90 driver.findElement(By.id("qunit-testresult"))
91 .getAttribute("innerHTML").then(data =>
92 data.search("Tests completed") >= 0))
Sebastian Noack 2018/08/24 12:29:10 If you use .includes() instead of .search() you ge
tlucas 2018/08/24 12:46:22 Done.
93 ).then(() => Promise.all([
94 reportElements(test, driver, "#qunit-tests .pass .test-name", true),
95 reportElements(test, driver, "#qunit-tests .fail .test-name", false)
Sebastian Noack 2018/08/24 12:29:11 You could make it even a little more DRY by removi
tlucas 2018/08/24 12:46:21 Good point, done.
96 ])).then(() =>
97 {
98 driver.quit();
99 test.done();
100 }).catch((err) =>
101 {
102 driver.quit().then(() =>
103 {
104 throw err;
105 });
106 });
107 });
108 };
OLDNEW
« README.md ('K') | « package.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld