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, 8:45 a.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";
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");
20 const {ensureFirefox} = require("../adblockpluscore/test/runners/" + 27 const {ensureFirefox} = require("../adblockpluscore/test/runners/" +
21 "firefox_download"); 28 "firefox_download");
22 const webdriver = require("selenium-webdriver");
23 const {By, until} = webdriver;
24 29
25 const FIREFOX_VERSION = "57.0"; 30 function reportElements(test, driver, success)
26 31 {
27 const Command = require("selenium-webdriver/lib/command").Command; 32 return driver.findElements(
hub 2018/08/23 12:53:59 you could use destructuring here too.
tlucas 2018/08/23 13:42:14 Could you please explain which lines / how exactly
hub 2018/08/23 14:46:33 change const Command = require("selenium-webdrive
tlucas 2018/08/23 15:32:05 Thank you! And no, "npm run lint" did not complai
28 const path = require("path"); 33 By.css(`#qunit-tests ${success ? ".pass" : ".fail"} .test-name`)
29 const firefox = require("selenium-webdriver/firefox"); 34 ).then(elements => Promise.all(elements.map(elem =>
35 elem.getAttribute("innerHTML").then(data => test.ok(success, data))
36 )));
37 }
30 38
31 exports.runFirefox = function(test) 39 exports.runFirefox = function(test)
32 { 40 {
33 // https://stackoverflow.com/a/45045036 41 // https://stackoverflow.com/a/45045036
34 function installWebExt(driver, extension) 42 function installWebExt(driver, extension)
35 { 43 {
36 let cmd = new Command("moz-install-web-ext") 44 let cmd = new Command("moz-install-web-ext")
37 .setParameter("path", path.resolve(extension)) 45 .setParameter("path", path.resolve(extension))
38 .setParameter("temporary", true); 46 .setParameter("temporary", true);
39 47
40 driver.getExecutor() 48 driver.getExecutor()
41 .defineCommand(cmd.getName(), "POST", 49 .defineCommand(cmd.getName(), "POST",
42 "/session/:sessionId/moz/addon/install"); 50 "/session/:sessionId/moz/addon/install");
43 51
44 return driver.schedule(cmd, "installWebExt(" + extension + ")"); 52 return driver.schedule(cmd, `installWebExt(${extension})`);
hub 2018/08/23 12:54:00 I'd rather use template a string here: `installWeb
tlucas 2018/08/23 13:42:15 Done.
45 } 53 }
46 54
47 ensureFirefox(FIREFOX_VERSION).then(firefoxPath => 55 ensureFirefox(FIREFOX_VERSION).then(firefoxPath =>
48 { 56 {
49 let binary = new firefox.Binary(firefoxPath); 57 let binary = new firefox.Binary(firefoxPath);
50 58
51 binary.addArguments("-headless"); 59 binary.addArguments("-headless");
52 60
53 let options = new firefox.Options() 61 let options = new firefox.Options()
54 .setBinary(binary); 62 .setBinary(binary);
55 63
56 let driver = new webdriver.Builder() 64 let driver = new webdriver.Builder()
57 .forBrowser("firefox") 65 .forBrowser("firefox")
58 .setFirefoxOptions(options) 66 .setFirefoxOptions(options)
59 .build(); 67 .build();
60 68
61 installWebExt(driver, "./devenv.gecko"); 69 installWebExt(driver, "./devenv.gecko");
62 70
63 driver.wait(() => 71 driver.wait(() =>
64 // Wait for the firstrun-page to be loaded 72 // Wait for the firstrun-page to be loaded
65 driver.getAllWindowHandles().then(handles => 73 driver.getAllWindowHandles().then(handles =>
66 { 74 {
67 if (handles.length > 1) 75 if (handles.length > 1)
68 { 76 {
69 driver.switchTo().window(handles[1]); 77 driver.switchTo().window(handles[1]);
70 return true; 78 return true;
71 } 79 }
72 return false; 80 return false;
73 }) 81 })
74 ).then(() => 82 ).then(() =>
75 {
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\";")
hub 2018/08/23 12:54:00 you could go `() => driver.executeScript(...)` (dr
tlucas 2018/08/23 13:42:14 Done.
78 }).then(() => 85 ).then(() =>
79 {
80 // Wait for qunit-results to be present 86 // Wait for qunit-results to be present
81 driver.wait(until.elementLocated(By.id("qunit-testresult"))); 87 driver.wait(until.elementLocated(By.id("qunit-testresult")))
hub 2018/08/23 12:53:59 here too.
tlucas 2018/08/23 13:42:15 Done.
82 }).then(() => 88 ).then(() =>
83 {
84 // Wait for tests to finish 89 // Wait for tests to finish
85 driver.wait(() => 90 driver.wait(() =>
hub 2018/08/23 12:53:59 and here
tlucas 2018/08/23 13:42:14 Done.
86 driver.findElement(By.id("qunit-testresult")) 91 driver.findElement(By.id("qunit-testresult"))
87 .getAttribute("innerHTML").then(data => 92 .getAttribute("innerHTML").then(data =>
88 data.search("Tests completed") >= 0)); 93 data.includes("Tests completed")))
89 }).then(() => 94 ).then(() => Promise.all([
90 { 95 reportElements(test, driver, true),
91 // Find passed tests 96 reportElements(test, driver, false)
92 driver.findElements(By.css("#qunit-tests .pass .test-name")) 97 ])).then(() =>
93 .then(elements =>
94 {
95 for (let elem of elements)
96 {
97 elem.getAttribute("innerHTML").then(data =>
98 {
99 test.ok(true, data);
100 });
101 }
102 });
103 // Find failed tests
104 driver.findElements(By.css("#qunit-tests .fail .test-name"))
105 .then(elements =>
106 {
107 for (let elem of elements)
108 {
109 elem.getAttribute("innerHTML").then(data =>
110 {
111 test.ok(false, "Undefined error in " + data);
hub 2018/08/23 12:54:00 And a template string here too.
tlucas 2018/08/23 13:42:15 Done.
112 });
113 }
114 });
115 }).then(() =>
116 { 98 {
117 driver.quit(); 99 driver.quit();
118 test.done(); 100 test.done();
119 }); 101 }, err =>
102 driver.quit().then(() =>
103 {
104 throw err;
105 })
106 );
120 }); 107 });
121 }; 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