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

Side by Side Diff: test/firefox.js

Issue 29866577: Issue 6887 - add Chrome to "npm test" (Closed)
Patch Set: Created Aug. 28, 2018, 8:17 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
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 /* eslint-env mocha */
19
20 "use strict";
21
22 const FIREFOX_VERSION = "57.0";
23
24 const path = require("path");
25 const assert = require("assert");
26 const webdriver = require("selenium-webdriver");
27 const {By, until} = webdriver;
28 const firefox = require("selenium-webdriver/firefox");
29 const {Command} = require("selenium-webdriver/lib/command");
30 const {ensureFirefox} = require("../adblockpluscore/test/runners/" +
31 "firefox_download");
32
33 describe("Firefox", function()
34 {
35 this.timeout(0);
36
37 let driver;
38 let origin;
39
40 before(() =>
41 ensureFirefox(FIREFOX_VERSION).then(firefoxPath =>
42 {
43 let binary = new firefox.Binary(firefoxPath);
44 binary.addArguments("-headless");
45
46 driver = new webdriver.Builder()
47 .forBrowser("firefox")
48 .setFirefoxOptions(new firefox.Options().setBinary(binary))
49 .build();
50
51 let devenv = "./devenv.gecko";
52 let cmd = new Command("moz-install-web-ext")
53 .setParameter("path", path.resolve(devenv))
54 .setParameter("temporary", true);
55
56 driver.getExecutor().defineCommand(
57 cmd.getName(), "POST",
58 "/session/:sessionId/moz/addon/install"
59 );
60 driver.schedule(cmd, `installWebExt(${devenv})`);
61
62 return driver.wait(() =>
63 driver.getAllWindowHandles().then(handles => handles[1])
64 ).then(handle =>
65 driver.switchTo().window(handle)
66 ).then(() =>
67 driver.executeScript("return location.origin;")
68 ).then(result => { origin = result; });
69 })
70 );
71
72 it("qunit", () =>
73 driver.navigate().to(origin + "/qunit/index.html").then(() =>
74 // Wait for qunit-results to be present
75 driver.wait(until.elementLocated(By.id("qunit-testresult")))
76 ).then(() =>
77 // Wait for tests to finish
78 driver.wait(() =>
79 driver.findElement(By.id("qunit-testresult"))
80 .getAttribute("innerHTML").then(data =>
81 data.includes("Tests completed")))
82 ).then(() => Promise.all([[true, ".pass"], [false, ".fail"]].map(
83 ([success, sel]) => driver.findElements(
84 By.css(`#qunit-tests ${sel} .test-name`)
85 ).then(elements => Promise.all(elements.map(elem =>
86 elem.getAttribute("textContent").then(data => assert.ok(success, data))
87 )))
88 )))
89 );
90
91 after(() => driver.quit());
92 });
OLDNEW

Powered by Google App Engine
This is Rietveld