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, 1:09 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
Sebastian Noack 2018/08/24 13:27:59 Nit: We usually only put one blank line after the
tlucas 2018/08/24 15:26:00 Done.
30
31 function reportElements(test, driver, success)
32 {
33 return driver.findElements(
34 By.css(`#qunit-tests ${success ? ".pass" : ".fail"} .test-name`)
35 ).then(elements => Promise.all(elements.map(elem =>
36 elem.getAttribute("innerHTML").then(data => test.ok(success, data))
37 )));
38 }
39
40 exports.runFirefox = function(test)
41 {
42 // https://stackoverflow.com/a/45045036
43 function installWebExt(driver, extension)
44 {
45 let cmd = new Command("moz-install-web-ext")
46 .setParameter("path", path.resolve(extension))
47 .setParameter("temporary", true);
48
49 driver.getExecutor()
50 .defineCommand(cmd.getName(), "POST",
51 "/session/:sessionId/moz/addon/install");
52
53 return driver.schedule(cmd, `installWebExt(${extension})`);
54 }
55
56 ensureFirefox(FIREFOX_VERSION).then(firefoxPath =>
57 {
58 let binary = new firefox.Binary(firefoxPath);
59
60 binary.addArguments("-headless");
61
62 let options = new firefox.Options()
63 .setBinary(binary);
64
65 let driver = new webdriver.Builder()
66 .forBrowser("firefox")
67 .setFirefoxOptions(options)
68 .build();
69
70 installWebExt(driver, "./devenv.gecko");
71
72 driver.wait(() =>
73 // Wait for the firstrun-page to be loaded
74 driver.getAllWindowHandles().then(handles =>
75 {
76 if (handles.length > 1)
77 {
78 driver.switchTo().window(handles[1]);
79 return true;
80 }
81 return false;
82 })
83 ).then(() =>
84 // Navigate to the qunit index
85 driver.executeScript("location.href = \"qunit/index.html\";")
86 ).then(() =>
87 // Wait for qunit-results to be present
88 driver.wait(until.elementLocated(By.id("qunit-testresult")))
89 ).then(() =>
90 // Wait for tests to finish
91 driver.wait(() =>
92 driver.findElement(By.id("qunit-testresult"))
93 .getAttribute("innerHTML").then(data =>
94 data.includes("Tests completed")))
95 ).then(() => Promise.all([
96 reportElements(test, driver, true),
97 reportElements(test, driver, false)
98 ])).then(() =>
99 {
100 driver.quit();
101 test.done();
102 }).catch((err) =>
Sebastian Noack 2018/08/24 13:27:59 I'd suggest to change the error handling like that
tlucas 2018/08/24 15:26:00 Done. (Still waiting for driver.quit() to finish b
103 {
104 driver.quit().then(() =>
105 {
106 throw err;
107 });
108 });
109 });
110 };
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