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

Side by Side Diff: test/browsers/edge.js

Issue 29959561: Issue 6930 - Add support for Microsoft Edge to WebDriver-based test automation
Patch Set: Created Dec. 5, 2018, 1:09 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
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 webdriver = require("selenium-webdriver");
21 const edge = require("selenium-webdriver/edge");
22 const path = require("path");
23 const os = require("os");
24 const fs = require("fs");
25 const {exec} = require("child_process");
26
27 function getSideloadLocation(buildDir)
28 {
29 return path.join(
30 os.homedir(),
31 "AppData", "Local", "Packages", "Microsoft.MicrosoftEdge_8wekyb3d8bbwe",
Sebastian Noack 2018/12/06 03:47:31 Will this work universally? Microsoft.MicrosoftEdg
32 "LocalState",
33 buildDir
34 );
35 }
36
37 function removeExtensionDir(extPath)
38 {
39 return new Promise((resolve, reject) =>
40 {
41 exec(
42 `powershell Remove-Item ${extPath} -Recurse`,
43 error =>
44 {
45 if (error)
46 reject(error);
47 else resolve();
48 }
49 );
50 });
51 }
52
53 function copyExtensionDir(extDir, buildDir)
54 {
55 return new Promise((resolve, reject) =>
56 {
57 exec(
58 `powershell Copy-Item ${buildDir} -Destination ${extDir} -Recurse`,
Sebastian Noack 2018/12/06 03:47:31 Calling into powershell to recursively copy a dire
59 error =>
60 {
61 if (error)
62 {
63 reject(error);
64 }
65 else resolve(extDir);
66 });
67 });
68 }
69
70 exports.sideloadExtension = function(buildDir)
71 {
72 let extDir = getSideloadLocation(buildDir);
73
74 return new Promise((resolve, reject) =>
75 fs.exists(extDir, exists =>
Sebastian Noack 2018/12/06 03:47:31 Could you use util.promisify() here?
76 {
77 if (exists)
78 return removeExtensionDir(extDir)
79 .then(() => copyExtensionDir(extDir, buildDir))
80 .then(resolve);
81
82 return copyExtensionDir(extDir, buildDir)
83 .then(resolve);
84 }));
85 };
86
87 exports.platform = "edge";
88
89 exports.getDriver = function(extensionPath)
90 {
91 let service = new edge.ServiceBuilder()
92 .build();
Sebastian Noack 2018/12/06 03:47:31 Nit: It seems wrapping this line isn't necessary.
93
94 // For compatibility reasons between Windows 10 build 1083 and 1089
95 // we use both extensionPaths and ms:extensionPaths, respectively
96 let capabilities = new webdriver.Capabilities({
97 "browserName": "MicrosoftEdge",
98 "ms:extensionPaths": [extensionPath],
99 "extensionPaths": [extensionPath]
100 });
101
102 let driver = edge.Driver.createSession(capabilities, service);
Sebastian Noack 2018/12/06 03:47:31 Nit: Just return the driver without creating tempo
103
104 return driver;
105 };
106
Sebastian Noack 2018/12/06 03:47:31 Nit: Redundant blank lines at end of file.
107
108
109
110
111
112
113
OLDNEW

Powered by Google App Engine
This is Rietveld