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

Delta Between Two Patch Sets: test/firefox.js

Issue 29860555: Issue 6717 - Part 2: run qunit in headless firefox (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/file/3270e924ba9f
Left Patch Set: Created Aug. 23, 2018, 6:55 p.m.
Right Patch Set: No func change, reindent Created Aug. 24, 2018, 6:56 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « package.json ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 const FIREFOX_VERSION = "57.0"; 20 const FIREFOX_VERSION = "57.0";
21 21
22 const path = require("path"); 22 const path = require("path");
23
24 const webdriver = require("selenium-webdriver"); 23 const webdriver = require("selenium-webdriver");
25 const {By, until} = webdriver; 24 const {By, until} = webdriver;
26 const firefox = require("selenium-webdriver/firefox"); 25 const firefox = require("selenium-webdriver/firefox");
27 const {Command} = require("selenium-webdriver/lib/command"); 26 const {Command} = require("selenium-webdriver/lib/command");
28
29 const {ensureFirefox} = require("../adblockpluscore/test/runners/" + 27 const {ensureFirefox} = require("../adblockpluscore/test/runners/" +
30 "firefox_download"); 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 }
31 38
32 exports.runFirefox = function(test) 39 exports.runFirefox = function(test)
33 { 40 {
34 // https://stackoverflow.com/a/45045036 41 // https://stackoverflow.com/a/45045036
35 function installWebExt(driver, extension) 42 function installWebExt(driver, extension)
36 { 43 {
37 let cmd = new Command("moz-install-web-ext") 44 let cmd = new Command("moz-install-web-ext")
38 .setParameter("path", path.resolve(extension)) 45 .setParameter("path", path.resolve(extension))
39 .setParameter("temporary", true); 46 .setParameter("temporary", true);
40 47
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 // Navigate to the qunit index 83 // Navigate to the qunit index
77 driver.executeScript("location.href = \"qunit/index.html\";") 84 driver.executeScript("location.href = \"qunit/index.html\";")
78 ).then(() => 85 ).then(() =>
79 // Wait for qunit-results to be present 86 // Wait for qunit-results to be present
80 driver.wait(until.elementLocated(By.id("qunit-testresult"))) 87 driver.wait(until.elementLocated(By.id("qunit-testresult")))
81 ).then(() => 88 ).then(() =>
82 // Wait for tests to finish 89 // Wait for tests to finish
83 driver.wait(() => 90 driver.wait(() =>
84 driver.findElement(By.id("qunit-testresult")) 91 driver.findElement(By.id("qunit-testresult"))
85 .getAttribute("innerHTML").then(data => 92 .getAttribute("innerHTML").then(data =>
86 data.search("Tests completed") >= 0)) 93 data.includes("Tests completed")))
87 ).then(() => 94 ).then(() => Promise.all([
88 { 95 reportElements(test, driver, true),
89 // Find passed tests 96 reportElements(test, driver, false)
90 driver.findElements(By.css("#qunit-tests .pass .test-name")) 97 ])).then(() =>
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 { 98 {
111 driver.quit(); 99 driver.quit();
Sebastian Noack 2018/08/23 21:54:20 This looks like a potential race condition. You wa
tlucas 2018/08/24 10:25:09 Done + made it dry
112 test.done(); 100 test.done();
113 }); 101 }, err =>
102 driver.quit().then(() =>
103 {
104 throw err;
105 })
106 );
114 }); 107 });
115 }; 108 };
LEFTRIGHT
« package.json ('k') | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld