Left: | ||
Right: |
OLD | NEW |
---|---|
(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 node */ | |
19 /* eslint no-console: "off" */ | |
20 | |
21 "use strict"; | |
22 | |
23 const path = require("path"); | |
24 | |
25 const {Builder, Capabilities, logging} = require("selenium-webdriver"); | |
26 const firefox = require("selenium-webdriver/firefox"); | |
27 require("geckodriver"); | |
28 | |
29 logging.installConsoleHandler(); | |
30 // logging.getLogger("webdriver.http").setLevel(logging.Level.ALL); | |
31 | |
32 let prefs = new logging.Preferences(); | |
33 prefs.setLevel(logging.Type.BROWSER, logging.Level.ALL); | |
34 prefs.setLevel(logging.Type.CLIENT, logging.Level.ALL); | |
35 let caps = Capabilities.firefox(); | |
36 caps.setLoggingPrefs(prefs); | |
37 | |
38 function runScript(script, scriptName, scriptArgs) | |
39 { | |
40 let binary = new firefox.Binary(firefox.Channel.NIGHTLY); | |
41 binary.addArguments("-headless"); | |
42 | |
43 const options = new firefox.Options() | |
44 .setBinary(binary); | |
45 | |
46 const driver = new Builder() | |
47 .forBrowser("firefox") | |
48 .setFirefoxOptions(options) | |
49 .build(); | |
50 | |
51 let index = path.join(__dirname, "test", "browser"); | |
52 let realScript = `let f = ${script} return f(...arguments);`; | |
53 return driver.get(`file://${index}/index.html`) | |
54 .then(result => driver.executeScript( | |
55 ` window.consoleLogs = []; | |
56 let oldLog = console.log; | |
57 console.log = msg => { | |
58 window.consoleLogs.push(msg); | |
59 oldLog.call(this, msg); | |
60 };` | |
61 )) | |
62 .then(result => driver.executeScript(realScript, scriptArgs)) | |
63 .then(result => driver.executeScript("return window.consoleLogs;")) | |
64 .then(result => | |
65 { | |
66 console.log("\nTest in Firefox\n"); | |
67 result.forEach(item => console.log(item)); | |
68 }) | |
69 .then(() => driver.quit()); | |
70 } | |
71 | |
72 module.exports = function(script, scriptName, ...scriptArgs) | |
73 { | |
74 return Promise.race([ | |
75 runScript(script, scriptName, scriptArgs) | |
Sebastian Noack
2018/03/12 23:17:31
Isn't Promise.race([p]) equivalent to p?
hub
2018/03/13 01:59:37
indeed. will fix that.
| |
76 ]).then(result => | |
77 { | |
78 return result; | |
79 }).catch(error => | |
80 { | |
81 throw error; | |
82 }); | |
83 }; | |
OLD | NEW |