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