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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/browsers/edge.js
diff --git a/test/browsers/edge.js b/test/browsers/edge.js
new file mode 100644
index 0000000000000000000000000000000000000000..b7d5a2fd7bc9b0a34fe0a15ed78e9b29835b1c01
--- /dev/null
+++ b/test/browsers/edge.js
@@ -0,0 +1,113 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-present eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+"use strict";
+
+const webdriver = require("selenium-webdriver");
+const edge = require("selenium-webdriver/edge");
+const path = require("path");
+const os = require("os");
+const fs = require("fs");
+const {exec} = require("child_process");
+
+function getSideloadLocation(buildDir)
+{
+ return path.join(
+ os.homedir(),
+ "AppData", "Local", "Packages", "Microsoft.MicrosoftEdge_8wekyb3d8bbwe",
Sebastian Noack 2018/12/06 03:47:31 Will this work universally? Microsoft.MicrosoftEdg
+ "LocalState",
+ buildDir
+ );
+}
+
+function removeExtensionDir(extPath)
+{
+ return new Promise((resolve, reject) =>
+ {
+ exec(
+ `powershell Remove-Item ${extPath} -Recurse`,
+ error =>
+ {
+ if (error)
+ reject(error);
+ else resolve();
+ }
+ );
+ });
+}
+
+function copyExtensionDir(extDir, buildDir)
+{
+ return new Promise((resolve, reject) =>
+ {
+ exec(
+ `powershell Copy-Item ${buildDir} -Destination ${extDir} -Recurse`,
Sebastian Noack 2018/12/06 03:47:31 Calling into powershell to recursively copy a dire
+ error =>
+ {
+ if (error)
+ {
+ reject(error);
+ }
+ else resolve(extDir);
+ });
+ });
+}
+
+exports.sideloadExtension = function(buildDir)
+{
+ let extDir = getSideloadLocation(buildDir);
+
+ return new Promise((resolve, reject) =>
+ fs.exists(extDir, exists =>
Sebastian Noack 2018/12/06 03:47:31 Could you use util.promisify() here?
+ {
+ if (exists)
+ return removeExtensionDir(extDir)
+ .then(() => copyExtensionDir(extDir, buildDir))
+ .then(resolve);
+
+ return copyExtensionDir(extDir, buildDir)
+ .then(resolve);
+ }));
+};
+
+exports.platform = "edge";
+
+exports.getDriver = function(extensionPath)
+{
+ let service = new edge.ServiceBuilder()
+ .build();
Sebastian Noack 2018/12/06 03:47:31 Nit: It seems wrapping this line isn't necessary.
+
+ // For compatibility reasons between Windows 10 build 1083 and 1089
+ // we use both extensionPaths and ms:extensionPaths, respectively
+ let capabilities = new webdriver.Capabilities({
+ "browserName": "MicrosoftEdge",
+ "ms:extensionPaths": [extensionPath],
+ "extensionPaths": [extensionPath]
+ });
+
+ let driver = edge.Driver.createSession(capabilities, service);
Sebastian Noack 2018/12/06 03:47:31 Nit: Just return the driver without creating tempo
+
+ return driver;
+};
+
Sebastian Noack 2018/12/06 03:47:31 Nit: Redundant blank lines at end of file.
+
+
+
+
+
+
+

Powered by Google App Engine
This is Rietveld