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. 21, 2018, 10:57 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
« package.json ('K') | « package.json ('k') | test_runner.js » ('j') | 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 {ensureFirefox} = require("../adblockpluscore/test/runners/" +
21 "firefox_download");
22 const webdriver = require("selenium-webdriver");
23 const By = webdriver.By;
24 const until = webdriver.until;
25
26 const FIREFOX_VERSION = "57.0";
27
28 const Command = require("selenium-webdriver/lib/command").Command;
29 const path = require("path");
30 const firefox = require("selenium-webdriver/firefox");
31
32 exports.runFirefox = function(test)
33 {
34 test.expect(14);
35 // https://stackoverflow.com/a/45045036
36 function installWebExt(driver, extension)
37 {
38 let cmd = new Command("moz-install-web-ext")
39 .setParameter("path", path.resolve(extension))
40 .setParameter("temporary", true);
41
42 driver.getExecutor()
43 .defineCommand(cmd.getName(), "POST",
44 "/session/:sessionId/moz/addon/install");
45
46 return driver.schedule(cmd, "installWebExt(" + extension + ")");
47 }
48
49 // Spawn the Firefox process in headless mode
50
51 ensureFirefox(FIREFOX_VERSION).then(firefoxPath =>
52 {
53 let binary = new firefox.Binary(firefoxPath);
54
55 binary.addArguments("-headless");
56
57 let options = new firefox.Options()
58 .setBinary(binary);
59
60 let driver = new webdriver.Builder()
61 .forBrowser("firefox")
62 .setFirefoxOptions(options)
63 .build();
64
65 installWebExt(driver, "./devenv.gecko");
66
67 driver.wait(() =>
68 {
69 // Wait for the firstrun-page to be loaded
70 return driver.getAllWindowHandles().then(handles =>
71 {
72 if (handles.length > 1)
73 {
74 driver.switchTo().window(handles[1]);
75 return true;
76 }
77 return false;
78 });
79 }).then(() =>
80 {
81 // Navigate to the qunit index
82 driver.executeScript("location.href = \"qunit/index.html\";");
83 }).then(() =>
84 {
85 // Wait for qunit-results to be present
86 driver.wait(until.elementLocated(By.id("qunit-testresult")));
87 }).then(() =>
88 {
89 // Wait for tests to finish
90 driver.wait(() =>
91 {
92 return driver.findElement(By.id("qunit-testresult"))
93 .getAttribute("innerHTML").then(data =>
94 {
95 return data.search("Tests completed") >= 0;
96 });
97 });
98 }).then(() =>
99 {
100 // Find passed tests
101 driver.findElements(By.css("#qunit-tests .pass .test-name"))
102 .then(elements =>
103 {
104 elements.forEach(elem =>
105 {
106 elem.getAttribute("innerHTML").then(data =>
107 {
108 test.ok(true, data);
109 });
110 });
111 });
112 // Find failed tests
113 driver.findElements(By.css("#qunit-tests .fail .test-name"))
114 .then(elements =>
115 {
116 elements.forEach(elem =>
117 {
118 elem.getAttribute("innerHTML").then(data =>
119 {
120 test.ok(false, "Undefined error in " + data);
121 });
122 });
123 });
124 }).then(() =>
125 {
126 driver.quit();
127 test.done();
128 });
129 });
130 };
OLDNEW
« package.json ('K') | « package.json ('k') | test_runner.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld