experimentalOptions = new HashMap<>();
90 |
91 | public EdgeOptions() {
92 | setCapability(CapabilityType.BROWSER_NAME, BrowserType.EDGE);
93 | setCapability(USE_CHROMIUM, true);
94 | }
95 |
96 | @Override
97 | public EdgeOptions merge(Capabilities extraCapabilities) {
98 | super.merge(extraCapabilities);
99 | return this;
100 | }
101 |
102 | /**
103 | * Sets whether to launch an Edge (Chromium) WebView executable instead of
104 | * launching the Edge browser.
105 | *
106 | * @param useWebView Whether to launch a WebView executable.
107 | */
108 | public EdgeOptions setUseWebView(boolean useWebView) {
109 | setCapability(CapabilityType.BROWSER_NAME, useWebView ? WEBVIEW_BROWSER_NAME : BrowserType.EDGE);
110 | return this;
111 | }
112 |
113 | /**
114 | * Sets the path to the Edge executable. This path should exist on the
115 | * machine which will launch Edge. The path should either be absolute or
116 | * relative to the location of running EdgeDriver server.
117 | *
118 | * @param path Path to Edge executable.
119 | */
120 | public EdgeOptions setBinary(File path) {
121 | binary = checkNotNull(path).getPath();
122 | return this;
123 | }
124 |
125 | /**
126 | * Sets the path to the Edge executable. This path should exist on the
127 | * machine which will launch Edge. The path should either be absolute or
128 | * relative to the location of running EdgeDriver server.
129 | *
130 | * @param path Path to Edge executable.
131 | */
132 | public EdgeOptions setBinary(String path) {
133 | binary = checkNotNull(path);
134 | return this;
135 | }
136 |
137 | /**
138 | * @param arguments The arguments to use when starting Edge.
139 | * @see #addArguments(java.util.List)
140 | */
141 | public EdgeOptions addArguments(String... arguments) {
142 | addArguments(ImmutableList.copyOf(arguments));
143 | return this;
144 | }
145 |
146 | /**
147 | * Adds additional command line arguments to be used when starting Edge.
148 | * For example:
149 | *
150 | * options.setArguments(
151 | * "load-extension=/path/to/unpacked_extension",
152 | * "allow-outdated-plugins");
153 | *
154 | *
155 | * Each argument may contain an option "--" prefix: "--foo" or "foo".
156 | * Arguments with an associated value should be delimitted with an "=":
157 | * "foo=bar".
158 | *
159 | * @param arguments The arguments to use when starting Edge.
160 | */
161 | public EdgeOptions addArguments(List arguments) {
162 | args.addAll(arguments);
163 | return this;
164 | }
165 |
166 | /**
167 | * @param paths Paths to the extensions to install.
168 | * @see #addExtensions(java.util.List)
169 | */
170 | public EdgeOptions addExtensions(File... paths) {
171 | addExtensions(ImmutableList.copyOf(paths));
172 | return this;
173 | }
174 |
175 | /**
176 | * Adds a new Edge extension to install on browser startup. Each path should
177 | * specify a packed Edge extension (CRX file).
178 | *
179 | * @param paths Paths to the extensions to install.
180 | */
181 | public EdgeOptions addExtensions(List paths) {
182 | for (File path : paths) {
183 | checkNotNull(path);
184 | checkArgument(path.exists(), "%s does not exist", path.getAbsolutePath());
185 | checkArgument(!path.isDirectory(), "%s is a directory",
186 | path.getAbsolutePath());
187 | }
188 | extensionFiles.addAll(paths);
189 | return this;
190 | }
191 |
192 | /**
193 | * @param encoded Base64 encoded data of the extensions to install.
194 | * @see #addEncodedExtensions(java.util.List)
195 | */
196 | public EdgeOptions addEncodedExtensions(String... encoded) {
197 | addEncodedExtensions(ImmutableList.copyOf(encoded));
198 | return this;
199 | }
200 |
201 | /**
202 | * Adds a new Edge extension to install on browser startup. Each string data should
203 | * specify a Base64 encoded string of packed Edge extension (CRX file).
204 | *
205 | * @param encoded Base64 encoded data of the extensions to install.
206 | */
207 | public EdgeOptions addEncodedExtensions(List encoded) {
208 | for (String extension : encoded) {
209 | checkNotNull(extension);
210 | }
211 | extensions.addAll(encoded);
212 | return this;
213 | }
214 |
215 | /**
216 | * Sets an experimental option. Useful for new EdgeDriver options not yet
217 | * exposed through the {@link EdgeOptions} API.
218 | *
219 | * @param name Name of the experimental option.
220 | * @param value Value of the experimental option, which must be convertible
221 | * to JSON.
222 | */
223 | public EdgeOptions setExperimentalOption(String name, Object value) {
224 | experimentalOptions.put(checkNotNull(name), value);
225 | return this;
226 | }
227 |
228 | /**
229 | * Returns the value of an experimental option.
230 | *
231 | * @param name The option name.
232 | * @return The option value, or {@code null} if not set.
233 | * @deprecated Getters are not needed in browser Options classes.
234 | */
235 | @Deprecated
236 | public Object getExperimentalOption(String name) {
237 | return experimentalOptions.get(checkNotNull(name));
238 | }
239 |
240 | public EdgeOptions setPageLoadStrategy(PageLoadStrategy strategy) {
241 | setCapability(PAGE_LOAD_STRATEGY, strategy);
242 | return this;
243 | }
244 |
245 | public EdgeOptions setUnhandledPromptBehaviour(UnexpectedAlertBehaviour behaviour) {
246 | setCapability(UNHANDLED_PROMPT_BEHAVIOUR, behaviour);
247 | setCapability(UNEXPECTED_ALERT_BEHAVIOUR, behaviour);
248 | return this;
249 | }
250 |
251 | /**
252 | * Returns EdgeOptions with the capability ACCEPT_INSECURE_CERTS set.
253 | * @param acceptInsecureCerts
254 | * @return EdgeOptions
255 | */
256 | public EdgeOptions setAcceptInsecureCerts(boolean acceptInsecureCerts) {
257 | setCapability(ACCEPT_INSECURE_CERTS, acceptInsecureCerts);
258 | return this;
259 | }
260 |
261 | public EdgeOptions setHeadless(boolean headless) {
262 | args.remove("--headless");
263 | if (headless) {
264 | args.add("--headless");
265 | args.add("--disable-gpu");
266 | }
267 | return this;
268 | }
269 |
270 | public EdgeOptions setProxy(Proxy proxy) {
271 | setCapability(CapabilityType.PROXY, proxy);
272 | return this;
273 | }
274 |
275 | @Override
276 | protected int amendHashCode() {
277 | return Objects.hash(
278 | args,
279 | binary,
280 | experimentalOptions,
281 | extensionFiles,
282 | extensions);
283 | }
284 |
285 | @Override
286 | public Map asMap() {
287 | Map toReturn = new TreeMap<>(super.asMap());
288 |
289 | Map options = new TreeMap<>();
290 | experimentalOptions.forEach(options::put);
291 |
292 | if (binary != null) {
293 | options.put("binary", binary);
294 | }
295 |
296 | options.put("args", ImmutableList.copyOf(args));
297 |
298 | options.put(
299 | "extensions",
300 | Stream.concat(
301 | extensionFiles.stream()
302 | .map(file -> {
303 | try {
304 | return Base64.getEncoder().encodeToString(Files.toByteArray(file));
305 | } catch (IOException e) {
306 | throw new SessionNotCreatedException(e.getMessage(), e);
307 | }
308 | }),
309 | extensions.stream()
310 | ).collect(ImmutableList.toImmutableList()));
311 |
312 | toReturn.put(CAPABILITY, options);
313 | toReturn.put(USE_CHROMIUM, true);
314 |
315 | return Collections.unmodifiableMap(toReturn);
316 | }
317 | }
318 |
--------------------------------------------------------------------------------
/java/src/test/java/com/microsoft/edge/seleniumtools/EdgeDriverTest.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.edge.seleniumtools;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.*;
6 |
7 | class EdgeDriverTest {
8 |
9 | @Test
10 | void testDriver() {
11 | EdgeDriver driver = new EdgeDriver();
12 | try {
13 | assertEquals("msedge", driver.getCapabilities().getBrowserName());
14 | } finally {
15 | driver.quit();
16 | }
17 | }
18 |
19 | @Test
20 | void testDefaultOptions() {
21 | EdgeOptions options = new EdgeOptions();
22 | assertEquals("MicrosoftEdge", options.getBrowserName());
23 | assertTrue((Boolean)options.getCapability(EdgeOptions.USE_CHROMIUM));
24 | }
25 |
26 | @Test
27 | void testUseWebView() {
28 | EdgeOptions options = new EdgeOptions();
29 | options.setUseWebView(true);
30 | assertEquals("webview2", options.getBrowserName());
31 | assertTrue((Boolean)options.getCapability(EdgeOptions.USE_CHROMIUM));
32 | }
33 | }
--------------------------------------------------------------------------------
/js/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
--------------------------------------------------------------------------------
/js/README.md:
--------------------------------------------------------------------------------
1 | # DEPRECATED: Selenium Tools for Microsoft Edge
2 |
3 |
4 | :warning: **This project is no longer maintained. Please uninstall Selenium Tools for Microsoft Edge and upgrade to [Selenium 4](https://www.selenium.dev/) which has built-in support for Microsoft Edge (Chromium). For help upgrading your Selenium 3 browser tests to Selenium 4, see Selenium's guide [here](https://www.selenium.dev/documentation/webdriver/getting_started/upgrade_to_selenium_4/).** :warning:
5 |
6 | This repository will remain available as an example, and for users that have not yet had a chance to upgrade. However, there will be no further activity on issues or pull requests. The [@EdgeDevTools](https://twitter.com/EdgeDevTools) team will continue to work with the Selenium project to contribute future Microsoft Edge Driver features and bug fixes directly to Selenium 4.
7 |
8 | * * *
9 |
10 | [](https://dev.azure.com/ms/edge-selenium-tools/_build/latest?definitionId=345&branchName=master)
11 |
12 | Selenium Tools for Microsoft Edge extends [Selenium 3](https://github.com/SeleniumHQ/selenium/releases/tag/selenium-3.141.59) with a unified driver to help you write automated tests for both the Microsoft Edge (EdgeHTML) and new Microsoft Edge (Chromium) browsers.
13 |
14 | The libraries included in this project are fully compatible with Selenium's built-in Edge libraries, and run Microsoft Edge (EdgeHTML) by default so you can use our project as a seamless drop-in replacement. In addition to being compatible with your existing Selenium tests, Selenium Tools for Microsoft Edge gives you the ability to drive the new Microsoft Edge (Chromium) browser and unlock all of the latest functionality!
15 |
16 | The classes in this package are based on the existing ``Edge`` and ``Chrome`` driver classes included in the [Selenium](https://github.com/SeleniumHQ/selenium) project.
17 |
18 | ## Before you Begin
19 |
20 | Selenium Tools for Microsoft Edge was created as a compatiblity solution for developers who have existing Selenium 3 browser tests and want to add coverage for the latest Microsoft Edge (Chromium) browser. The [Microsoft Edge Developer Tools Team](https://twitter.com/EdgeDevTools) recommends using Selenium 4 instead because Selenium 4 has built-in support for Microsoft Edge (Chromium). If you are able to upgrade your existing tests, or write new tests using Selenium 4, then there is no need to use this package as Selenium should already have everything you need built in!
21 |
22 | See Selenium's upgrade [guide](https://www.selenium.dev/documentation/webdriver/getting_started/upgrade_to_selenium_4/) for help with upgrading from Selenium 3 to Selenium 4. If you are unable to upgrade due to a compatibility issues, please consider opening an issue in the official Selenium GitHub repo [here](https://github.com/SeleniumHQ/selenium/issues). If you have determined that you cannot upgrade from Selenium 3 at this time, and would still like to add test coverage for Microsoft Edge (Chromium) to your project, see the steps in the section below.
23 |
24 | ## Getting Started
25 |
26 | ### Downloading Driver Executables
27 |
28 | You will need the correct [WebDriver executable][webdriver-download] for the version of Microsoft Edge you want to drive. The executables are not included with this package. WebDriver executables for all supported versions of Microsoft Edge are available for download [here][webdriver-download]. For more information, and instructions on downloading the correct driver for your browser, see the [Microsoft Edge WebDriver documentation][webdriver-chromium-docs].
29 |
30 | ### Installation
31 |
32 | Selenium Tools for Microsoft Edge depends on the official Selenium 3 package to run. You will need to ensure that both Selenium 3 and the Tools and included in your project.
33 |
34 | ```
35 | npm install @microsoft/edge-selenium-tools
36 | ```
37 |
38 | ## Example Code
39 |
40 | See the [Microsoft Edge WebDriver documentation][webdriver-chromium-docs] for lots more information on using Microsoft Edge (Chromium) with WebDriver.
41 |
42 | ```js
43 | const edge = require("@microsoft/edge-selenium-tools");
44 |
45 | // Launch Microsoft Edge (EdgeHTML)
46 | let driver = edge.Driver.createSession();
47 |
48 | // Launch Microsoft Edge (Chromium)
49 | let options = new edge.Options().setEdgeChromium(true);
50 | let driver = edge.Driver.createSession(options);
51 | ```
52 |
53 | ## Contributing
54 |
55 | We are glad you are interested in automating the latest Microsoft Edge browser and improving the automation experience for the rest of the community!
56 |
57 | Before you begin, please read & follow our [Contributor's Guide](CONTRIBUTING.md). Consider also contributing your feature or bug fix directly to [Selenium](https://github.com/SeleniumHQ/selenium) so that it will be included in future Selenium releases.
58 |
59 | ## Code of Conduct
60 |
61 | This project has adopted the [Microsoft Open Source Code of Conduct][conduct-code].
62 | For more information see the [Code of Conduct FAQ][conduct-FAQ] or contact [opencode@microsoft.com][conduct-email] with any additional questions or comments.
63 |
64 | [webdriver-download]: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
65 | [webdriver-chromium-docs]: https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium
66 | [conduct-code]: https://opensource.microsoft.com/codeofconduct/
67 | [conduct-FAQ]: https://opensource.microsoft.com/codeofconduct/faq/
68 | [conduct-email]: mailto:opencode@microsoft.com
69 |
--------------------------------------------------------------------------------
/js/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@microsoft/edge-selenium-tools",
3 | "version": "3.6.2",
4 | "description": "An updated EdgeDriver implementation for Selenium 3 with newly-added support for Microsoft Edge (Chromium).",
5 | "keywords": [
6 | "automation",
7 | "selenium",
8 | "testing",
9 | "webdriver",
10 | "webdriverjs",
11 | "microsoft",
12 | "chromium",
13 | "edge"
14 | ],
15 | "repository": {
16 | "type": "git",
17 | "url": "https://github.com/microsoft/edge-selenium-tools"
18 | },
19 | "author": "Microsoft Corporation",
20 | "license": "Apache-2.0",
21 | "main": "./lib/edge.js",
22 | "directories": {
23 | "test": "test"
24 | },
25 | "scripts": {
26 | "test": "mocha"
27 | },
28 | "files": [
29 | "lib/**/*.js",
30 | "README.md",
31 | "LICENSE"
32 | ],
33 | "peerDependencies": {
34 | "selenium-webdriver": "3.6.0"
35 | },
36 | "devDependencies": {
37 | "mocha": "^7.1.2"
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/js/test/edge_driver_test.js:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Microsoft
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | const assert = require('assert');
15 | const edge = require("../lib/edge");
16 |
17 | describe('JS selenium binding tests', function () {
18 | this.timeout(0);
19 |
20 | it.skip('test default', async function () {
21 | let driver = await edge.Driver.createSession();
22 |
23 | let cap = await driver.getCapabilities();
24 | await assert.equal(cap.get('browserName'), 'MicrosoftEdge');
25 |
26 | await driver.quit();
27 | });
28 |
29 | it.skip('test legacy edge', async function () {
30 | let options = await new edge.Options().setEdgeChromium(false);
31 | let driver = await edge.Driver.createSession(options);
32 |
33 | let cap = await driver.getCapabilities();
34 | await assert.equal(cap.get('browserName'), 'MicrosoftEdge');
35 |
36 | await driver.quit();
37 | });
38 |
39 | it('test chromium edge', async function () {
40 | let options = await new edge.Options().setEdgeChromium(true);
41 | let driver = await edge.Driver.createSession(options);
42 |
43 | let cap = await driver.getCapabilities();
44 | await assert.equal(cap.get('browserName'), 'msedge');
45 |
46 | await driver.quit();
47 | });
48 |
49 | it('test legacy options to capabilities', async function () {
50 | let options = await new edge.Options();
51 | let cap = await options.toCapabilities();
52 | await assert.equal(cap.get('browserName'), 'MicrosoftEdge');
53 | await assert.equal(cap.has('ms:edgeOptions'), false);
54 | await assert.equal(cap.has('ms:edgeChromium'), true);
55 | await assert.equal(cap.get('ms:edgeChromium'), false);
56 | });
57 |
58 | it('test chromium options to capabilities', async function () {
59 | let options = await new edge
60 | .Options()
61 | .setEdgeChromium(true);
62 | let cap = await options.toCapabilities();
63 | await assert.equal(cap.get('browserName'), 'MicrosoftEdge');
64 | await assert.equal(cap.has('ms:edgeOptions'), true);
65 | await assert.equal(cap.get('ms:edgeOptions').getEdgeChromium(), true);
66 | await assert.equal(cap.has('ms:edgeChromium'), true);
67 | await assert.equal(cap.get('ms:edgeChromium'), true);
68 | });
69 |
70 | it('test webview options', function() {
71 | let options = new edge.Options();
72 | options.setEdgeChromium(true);
73 | options.setUseWebView(true);
74 | let cap = options.toCapabilities();
75 | assert.equal(cap.get('browserName'), 'webview2');
76 | });
77 | });
78 |
79 |
--------------------------------------------------------------------------------
/py/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
--------------------------------------------------------------------------------
/py/README.md:
--------------------------------------------------------------------------------
1 | # DEPRECATED: Selenium Tools for Microsoft Edge
2 |
3 |
4 | :warning: **This project is no longer maintained. Please uninstall Selenium Tools for Microsoft Edge and upgrade to [Selenium 4](https://www.selenium.dev/) which has built-in support for Microsoft Edge (Chromium). For help upgrading your Selenium 3 browser tests to Selenium 4, see Selenium's guide [here](https://www.selenium.dev/documentation/webdriver/getting_started/upgrade_to_selenium_4/).** :warning:
5 |
6 | This repository will remain available as an example, and for users that have not yet had a chance to upgrade. However, there will be no further activity on issues or pull requests. The [@EdgeDevTools](https://twitter.com/EdgeDevTools) team will continue to work with the Selenium project to contribute future Microsoft Edge Driver features and bug fixes directly to Selenium 4.
7 |
8 | * * *
9 |
10 | [](https://dev.azure.com/ms/edge-selenium-tools/_build/latest?definitionId=345&branchName=master)
11 |
12 | Selenium Tools for Microsoft Edge extends [Selenium 3](https://github.com/SeleniumHQ/selenium/releases/tag/selenium-3.141.59) with a unified driver to help you write automated tests for both the Microsoft Edge (EdgeHTML) and new Microsoft Edge (Chromium) browsers.
13 |
14 | The libraries included in this project are fully compatible with Selenium's built-in Edge libraries, and run Microsoft Edge (EdgeHTML) by default so you can use our project as a seamless drop-in replacement. In addition to being compatible with your existing Selenium tests, Selenium Tools for Microsoft Edge gives you the ability to drive the new Microsoft Edge (Chromium) browser and unlock all of the latest functionality!
15 |
16 | The classes in this package are based on the existing ``Edge`` and ``Chrome`` driver classes included in the [Selenium](https://github.com/SeleniumHQ/selenium) project.
17 |
18 | ## Before you Begin
19 |
20 | Selenium Tools for Microsoft Edge was created as a compatiblity solution for developers who have existing Selenium 3 browser tests and want to add coverage for the latest Microsoft Edge (Chromium) browser. The [Microsoft Edge Developer Tools Team](https://twitter.com/EdgeDevTools) recommends using Selenium 4 instead because Selenium 4 has built-in support for Microsoft Edge (Chromium). If you are able to upgrade your existing tests, or write new tests using Selenium 4, then there is no need to use this package as Selenium should already have everything you need built in!
21 |
22 | See Selenium's upgrade [guide](https://www.selenium.dev/documentation/webdriver/getting_started/upgrade_to_selenium_4/) for help with upgrading from Selenium 3 to Selenium 4. If you are unable to upgrade due to a compatibility issues, please consider opening an issue in the official Selenium GitHub repo [here](https://github.com/SeleniumHQ/selenium/issues). If you have determined that you cannot upgrade from Selenium 3 at this time, and would still like to add test coverage for Microsoft Edge (Chromium) to your project, see the steps in the section below.
23 |
24 | ## Getting Started
25 |
26 | ### Downloading Driver Executables
27 |
28 | You will need the correct [WebDriver executable][webdriver-download] for the version of Microsoft Edge you want to drive. The executables are not included with this package. WebDriver executables for all supported versions of Microsoft Edge are available for download [here][webdriver-download]. For more information, and instructions on downloading the correct driver for your browser, see the [Microsoft Edge WebDriver documentation][webdriver-chromium-docs].
29 |
30 | ### Installation
31 |
32 | Selenium Tools for Microsoft Edge depends on the official Selenium 3 package to run. You will need to ensure that both Selenium 3 and the Tools and included in your project.
33 |
34 | Use pip to install the [msedge-selenium-tools](https://pypi.org/project/msedge-selenium-tools/) and [selenium](https://pypi.org/project/selenium/3.141.0/) packages:
35 |
36 | ```
37 | pip install msedge-selenium-tools selenium==3.141
38 | ```
39 |
40 | ## Example Code
41 |
42 | See the [Microsoft Edge WebDriver documentation][webdriver-chromium-docs] for lots more information on using Microsoft Edge (Chromium) with WebDriver.
43 |
44 | ```python
45 | from msedge.selenium_tools import Edge, EdgeOptions
46 |
47 | # Launch Microsoft Edge (EdgeHTML)
48 | driver = Edge()
49 |
50 | # Launch Microsoft Edge (Chromium)
51 | options = EdgeOptions()
52 | options.use_chromium = True
53 | driver = Edge(options = options)
54 | ```
55 |
56 | ## Contributing
57 |
58 | We are glad you are interested in automating the latest Microsoft Edge browser and improving the automation experience for the rest of the community!
59 |
60 | Before you begin, please read & follow our [Contributor's Guide](CONTRIBUTING.md). Consider also contributing your feature or bug fix directly to [Selenium](https://github.com/SeleniumHQ/selenium) so that it will be included in future Selenium releases.
61 |
62 | ## Code of Conduct
63 |
64 | This project has adopted the [Microsoft Open Source Code of Conduct][conduct-code].
65 | For more information see the [Code of Conduct FAQ][conduct-FAQ] or contact [opencode@microsoft.com][conduct-email] with any additional questions or comments.
66 |
67 | [webdriver-download]: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
68 | [webdriver-chromium-docs]: https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium
69 | [conduct-code]: https://opensource.microsoft.com/codeofconduct/
70 | [conduct-FAQ]: https://opensource.microsoft.com/codeofconduct/faq/
71 | [conduct-email]: mailto:opencode@microsoft.com
72 |
--------------------------------------------------------------------------------
/py/msedge/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/edge-selenium-tools/59b98594e726b5181e11be392baa0dabf2a048c7/py/msedge/__init__.py
--------------------------------------------------------------------------------
/py/msedge/selenium_tools/__init__.py:
--------------------------------------------------------------------------------
1 | # Portions Copyright Microsoft 2020
2 | # Licensed under the Apache License, Version 2.0
3 | #
4 | # Licensed to the Software Freedom Conservancy (SFC) under one
5 | # or more contributor license agreements. See the NOTICE file
6 | # distributed with this work for additional information
7 | # regarding copyright ownership. The SFC licenses this file
8 | # to you under the Apache License, Version 2.0 (the
9 | # "License"); you may not use this file except in compliance
10 | # with the License. You may obtain a copy of the License at
11 | #
12 | # http://www.apache.org/licenses/LICENSE-2.0
13 | #
14 | # Unless required by applicable law or agreed to in writing,
15 | # software distributed under the License is distributed on an
16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | # KIND, either express or implied. See the License for the
18 | # specific language governing permissions and limitations
19 | # under the License.
20 |
21 | from .webdriver import WebDriver as Edge
22 | from .service import Service as EdgeService
23 | from .options import Options as EdgeOptions
--------------------------------------------------------------------------------
/py/msedge/selenium_tools/options.py:
--------------------------------------------------------------------------------
1 | # Portions Copyright Microsoft 2020
2 | # Licensed under the Apache License, Version 2.0
3 | #
4 | # Licensed to the Software Freedom Conservancy (SFC) under one
5 | # or more contributor license agreements. See the NOTICE file
6 | # distributed with this work for additional information
7 | # regarding copyright ownership. The SFC licenses this file
8 | # to you under the Apache License, Version 2.0 (the
9 | # "License"); you may not use this file except in compliance
10 | # with the License. You may obtain a copy of the License at
11 | #
12 | # http://www.apache.org/licenses/LICENSE-2.0
13 | #
14 | # Unless required by applicable law or agreed to in writing,
15 | # software distributed under the License is distributed on an
16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | # KIND, either express or implied. See the License for the
18 | # specific language governing permissions and limitations
19 | # under the License.
20 |
21 | import base64
22 | import os
23 | import platform
24 | import warnings
25 |
26 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
27 |
28 |
29 | class Options(object):
30 | KEY = "ms:edgeOptions"
31 |
32 | def __init__(self):
33 | self._page_load_strategy = "normal"
34 | self._binary_location = ''
35 | self._arguments = []
36 | self._extension_files = []
37 | self._extensions = []
38 | self._experimental_options = {}
39 | self._debugger_address = None
40 | self._caps = DesiredCapabilities.EDGE.copy()
41 | self._use_chromium = False
42 | self._use_webview = False
43 |
44 | @property
45 | def use_chromium(self):
46 | return self._use_chromium
47 |
48 | @use_chromium.setter
49 | def use_chromium(self, value):
50 | self._use_chromium = bool(value)
51 |
52 | @property
53 | def use_webview(self):
54 | return self._use_webview
55 |
56 | @use_webview.setter
57 | def use_webview(self, value):
58 | self._use_webview = bool(value)
59 |
60 | @property
61 | def page_load_strategy(self):
62 | return self._page_load_strategy
63 |
64 | @page_load_strategy.setter
65 | def page_load_strategy(self, value):
66 | if value not in ['normal', 'eager', 'none']:
67 | raise ValueError("Page Load Strategy should be 'normal', 'eager' or 'none'.")
68 | self._page_load_strategy = value
69 |
70 | @property
71 | def capabilities(self):
72 | return self._caps
73 |
74 | def set_capability(self, name, value):
75 | """Sets a capability."""
76 | self._caps[name] = value
77 |
78 | def to_capabilities(self):
79 | """
80 | Creates a capabilities with all the options that have been set and
81 |
82 | returns a dictionary with everything
83 | """
84 | if self.use_chromium:
85 | caps = self._caps
86 | if self._use_webview:
87 | caps['browserName'] = 'webview2'
88 | edge_options = self.experimental_options.copy()
89 | edge_options["extensions"] = self.extensions
90 | if self.binary_location:
91 | edge_options["binary"] = self.binary_location
92 | edge_options["args"] = self.arguments
93 | if self.debugger_address:
94 | edge_options["debuggerAddress"] = self.debugger_address
95 |
96 | caps[self.KEY] = edge_options
97 | else:
98 | caps = self._caps
99 | caps['pageLoadStrategy'] = self._page_load_strategy
100 | caps['ms:edgeChromium'] = self.use_chromium
101 | return caps
102 |
103 | @property
104 | def binary_location(self):
105 | """
106 | Returns the location of the binary otherwise an empty string
107 | """
108 | return self._binary_location
109 |
110 | @binary_location.setter
111 | def binary_location(self, value):
112 | """
113 | Allows you to set where the edge binary lives
114 |
115 | :Args:
116 | - value: path to the edge binary
117 | """
118 | self._binary_location = value
119 |
120 | @property
121 | def debugger_address(self):
122 | """
123 | Returns the address of the remote devtools instance
124 | """
125 | return self._debugger_address
126 |
127 | @debugger_address.setter
128 | def debugger_address(self, value):
129 | """
130 | Allows you to set the address of the remote devtools instance
131 | that the EdgeDriver instance will try to connect to during an
132 | active wait.
133 |
134 | :Args:
135 | - value: address of remote devtools instance if any (hostname[:port])
136 | """
137 | self._debugger_address = value
138 |
139 | @property
140 | def arguments(self):
141 | """
142 | Returns a list of arguments needed for the browser
143 | """
144 | return self._arguments
145 |
146 | def add_argument(self, argument):
147 | """
148 | Adds an argument to the list
149 |
150 | :Args:
151 | - Sets the arguments
152 | """
153 | if argument:
154 | self._arguments.append(argument)
155 | else:
156 | raise ValueError("argument can not be null")
157 |
158 | @property
159 | def extensions(self):
160 | """
161 | Returns a list of encoded extensions that will be loaded into edge
162 |
163 | """
164 | encoded_extensions = []
165 | for ext in self._extension_files:
166 | file_ = open(ext, 'rb')
167 | # Should not use base64.encodestring() which inserts newlines every
168 | # 76 characters (per RFC 1521). Edgedriver has to remove those
169 | # unnecessary newlines before decoding, causing performance hit.
170 | encoded_extensions.append(base64.b64encode(file_.read()).decode('UTF-8'))
171 |
172 | file_.close()
173 | return encoded_extensions + self._extensions
174 |
175 | def add_extension(self, extension):
176 | """
177 | Adds the path to the extension to a list that will be used to extract it
178 | to the EdgeDriver
179 |
180 | :Args:
181 | - extension: path to the \*.crx file
182 | """
183 | if extension:
184 | extension_to_add = os.path.abspath(os.path.expanduser(extension))
185 | if os.path.exists(extension_to_add):
186 | self._extension_files.append(extension_to_add)
187 | else:
188 | raise IOError("Path to the extension doesn't exist")
189 | else:
190 | raise ValueError("argument can not be null")
191 |
192 | def add_encoded_extension(self, extension):
193 | """
194 | Adds Base64 encoded string with extension data to a list that will be used to extract it
195 | to the EdgeDriver
196 |
197 | :Args:
198 | - extension: Base64 encoded string with extension data
199 | """
200 | if extension:
201 | self._extensions.append(extension)
202 | else:
203 | raise ValueError("argument can not be null")
204 |
205 | @property
206 | def experimental_options(self):
207 | """
208 | Returns a dictionary of experimental options for edge.
209 | """
210 | return self._experimental_options
211 |
212 | def add_experimental_option(self, name, value):
213 | """
214 | Adds an experimental option which is passed to edge.
215 |
216 | Args:
217 | name: The experimental option name.
218 | value: The option value.
219 | """
220 | self._experimental_options[name] = value
221 |
222 | @property
223 | def headless(self):
224 | """
225 | Returns whether or not the headless argument is set
226 | """
227 | return '--headless' in self._arguments
228 |
229 | @headless.setter
230 | def headless(self, value):
231 | """
232 | Sets the headless argument
233 |
234 | Args:
235 | value: boolean value indicating to set the headless option
236 | """
237 | args = {'--headless'}
238 | if platform.system().lower() == 'windows':
239 | args.add('--disable-gpu')
240 | if value is True:
241 | self._arguments.extend(args)
242 | else:
243 | self._arguments = list(set(self._arguments) - args)
244 |
245 | def set_headless(self, headless=True):
246 | """ Deprecated, options.headless = True """
247 | warnings.warn('use setter for headless property instead of set_headless',
248 | DeprecationWarning, stacklevel=2)
249 | self.headless = headless
--------------------------------------------------------------------------------
/py/msedge/selenium_tools/remote_connection.py:
--------------------------------------------------------------------------------
1 | # Portions Copyright Microsoft 2020
2 | # Licensed under the Apache License, Version 2.0
3 | #
4 | # Licensed to the Software Freedom Conservancy (SFC) under one
5 | # or more contributor license agreements. See the NOTICE file
6 | # distributed with this work for additional information
7 | # regarding copyright ownership. The SFC licenses this file
8 | # to you under the Apache License, Version 2.0 (the
9 | # "License"); you may not use this file except in compliance
10 | # with the License. You may obtain a copy of the License at
11 | #
12 | # http://www.apache.org/licenses/LICENSE-2.0
13 | #
14 | # Unless required by applicable law or agreed to in writing,
15 | # software distributed under the License is distributed on an
16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | # KIND, either express or implied. See the License for the
18 | # specific language governing permissions and limitations
19 | # under the License.
20 |
21 | from selenium.webdriver.remote.remote_connection import RemoteConnection
22 |
23 |
24 | class EdgeRemoteConnection(RemoteConnection):
25 |
26 | def __init__(self, remote_server_addr, keep_alive=True):
27 | RemoteConnection.__init__(self, remote_server_addr, keep_alive)
28 | self._commands["launchApp"] = ('POST', '/session/$sessionId/chromium/launch_app')
29 | self._commands["setNetworkConditions"] = ('POST', '/session/$sessionId/chromium/network_conditions')
30 | self._commands["getNetworkConditions"] = ('GET', '/session/$sessionId/chromium/network_conditions')
31 | self._commands['executeCdpCommand'] = ('POST', '/session/$sessionId/ms/cdp/execute')
32 |
--------------------------------------------------------------------------------
/py/msedge/selenium_tools/service.py:
--------------------------------------------------------------------------------
1 | # Portions Copyright Microsoft 2020
2 | # Licensed under the Apache License, Version 2.0
3 | #
4 | # Licensed to the Software Freedom Conservancy (SFC) under one
5 | # or more contributor license agreements. See the NOTICE file
6 | # distributed with this work for additional information
7 | # regarding copyright ownership. The SFC licenses this file
8 | # to you under the Apache License, Version 2.0 (the
9 | # "License"); you may not use this file except in compliance
10 | # with the License. You may obtain a copy of the License at
11 | #
12 | # http://www.apache.org/licenses/LICENSE-2.0
13 | #
14 | # Unless required by applicable law or agreed to in writing,
15 | # software distributed under the License is distributed on an
16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | # KIND, either express or implied. See the License for the
18 | # specific language governing permissions and limitations
19 | # under the License.
20 |
21 | from selenium.webdriver.common import service
22 |
23 |
24 | class Service(service.Service):
25 |
26 | def __init__(self, executable_path, port=0, verbose=False, log_path=None,
27 | service_args=None, env=None):
28 | """
29 | Creates a new instance of the EdgeDriver service.
30 |
31 | EdgeDriver provides an interface for Microsoft WebDriver to use
32 | with Microsoft Edge.
33 |
34 | :param executable_path: Path to the Microsoft WebDriver binary.
35 | :param port: Run the remote service on a specified port.
36 | Defaults to 0, which binds to a random open port of the
37 | system's choosing.
38 | :verbose: Whether to make the webdriver more verbose (passes the
39 | --verbose option to the binary). Defaults to False.
40 | :param log_path: Optional path for the webdriver binary to log to.
41 | Defaults to None which disables logging.
42 | :param service_args : List of args to pass to the edgedriver service
43 |
44 | """
45 | self.service_args = service_args or []
46 | if verbose:
47 | self.service_args.append("--verbose")
48 |
49 | params = {
50 | "executable": executable_path,
51 | "port": port,
52 | "env": env,
53 | "start_error_message": "Please download from http://go.microsoft.com/fwlink/?LinkId=619687"
54 | }
55 |
56 | if log_path:
57 | params["log_file"] = open(log_path, "a+")
58 |
59 | service.Service.__init__(self, **params)
60 |
61 | def command_line_args(self):
62 | return ["--port=%d" % self.port] + self.service_args
63 |
--------------------------------------------------------------------------------
/py/msedge/selenium_tools/webdriver.py:
--------------------------------------------------------------------------------
1 | # Portions Copyright Microsoft 2020
2 | # Licensed under the Apache License, Version 2.0
3 | #
4 | # Licensed to the Software Freedom Conservancy (SFC) under one
5 | # or more contributor license agreements. See the NOTICE file
6 | # distributed with this work for additional information
7 | # regarding copyright ownership. The SFC licenses this file
8 | # to you under the Apache License, Version 2.0 (the
9 | # "License"); you may not use this file except in compliance
10 | # with the License. You may obtain a copy of the License at
11 | #
12 | # http://www.apache.org/licenses/LICENSE-2.0
13 | #
14 | # Unless required by applicable law or agreed to in writing,
15 | # software distributed under the License is distributed on an
16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | # KIND, either express or implied. See the License for the
18 | # specific language governing permissions and limitations
19 | # under the License.
20 | import warnings
21 |
22 | from selenium.webdriver.common import utils
23 | from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
24 | from selenium.webdriver.remote.remote_connection import RemoteConnection
25 | from .remote_connection import EdgeRemoteConnection
26 | from .service import Service
27 | from .options import Options
28 |
29 |
30 | class WebDriver(RemoteWebDriver):
31 |
32 | def __init__(self, executable_path='',
33 | capabilities=None, port=0, verbose=False, service_log_path=None,
34 | log_path=None, keep_alive=None,
35 | desired_capabilities=None, service_args=None, options=None):
36 | """
37 | Creates a new instance of the edge driver.
38 |
39 | Starts the service and then creates new instance of edge driver.
40 |
41 | :Args:
42 | - executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH
43 | - capabilities - Dictionary object with non-browser specific
44 | capabilities only, such as "proxy" or "loggingPref".
45 | - port - port you would like the service to run, if left as 0, a free port will be found.
46 | - verbose - whether to set verbose logging in the service
47 | - service_log_path - Where to log information from the driver.
48 | - log_path: Deprecated argument for service_log_path
49 | - keep_alive - Whether to configure EdgeRemoteConnection to use HTTP keep-alive.
50 | - desired_capabilities - Dictionary object with non-browser specific
51 | capabilities only, such as "proxy" or "loggingPref".
52 | - service_args - List of args to pass to the driver service
53 | - options - this takes an instance of EdgeOptions
54 |
55 | """
56 |
57 | warnings.warn(
58 | "Selenium Tools for Microsoft Edge is deprecated. Please upgrade to Selenium 4 which has built-in support for Microsoft Edge (Chromium): https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium/#upgrading-from-selenium-3",
59 | DeprecationWarning, stacklevel=2)
60 |
61 | use_chromium = False
62 | if (options and options.use_chromium) or \
63 | (desired_capabilities and 'ms:edgeChromium' in desired_capabilities \
64 | and desired_capabilities['ms:edgeChromium']):
65 | use_chromium = True
66 |
67 | if keep_alive is None:
68 | if use_chromium:
69 | keep_alive = True
70 | else:
71 | keep_alive = False
72 |
73 | if executable_path is '':
74 | executable_path = 'msedgedriver' if use_chromium else 'MicrosoftWebDriver.exe'
75 |
76 | # Note that legacy edge uses capabilities while chrome edge
77 | # uses desired_capabilities as argument
78 | if not use_chromium and capabilities is not None:
79 | desired_capabilities = capabilities
80 |
81 | if options is None:
82 | # desired_capabilities stays as passed in
83 | if desired_capabilities is None:
84 | desired_capabilities = self.create_options().to_capabilities()
85 | else:
86 | if desired_capabilities is None:
87 | desired_capabilities = options.to_capabilities()
88 | else:
89 | desired_capabilities.update(options.to_capabilities())
90 |
91 | if log_path:
92 | warnings.warn('use service_log_path instead of log_path',
93 | DeprecationWarning, stacklevel=2)
94 | service_log_path = log_path
95 |
96 | self.port = port
97 |
98 | self.service = Service(
99 | executable_path,
100 | port=self.port,
101 | verbose=verbose,
102 | service_args=service_args,
103 | log_path=service_log_path)
104 | self.service.start()
105 |
106 | try:
107 | RemoteWebDriver.__init__(
108 | self,
109 | command_executor = EdgeRemoteConnection(
110 | remote_server_addr=self.service.service_url,
111 | keep_alive=keep_alive),
112 | desired_capabilities=desired_capabilities)
113 | except Exception:
114 | self.quit()
115 | raise
116 | self._is_remote = False
117 |
118 | def launch_app(self, id):
119 | """Launches Edge app specified by id."""
120 | return self.execute("launchApp", {'id': id})
121 |
122 | def get_network_conditions(self):
123 | """
124 | Gets Edge network emulation settings.
125 |
126 | :Returns:
127 | A dict. For example:
128 |
129 | {'latency': 4, 'download_throughput': 2, 'upload_throughput': 2,
130 | 'offline': False}
131 |
132 | """
133 | return self.execute("getNetworkConditions")['value']
134 |
135 | def set_network_conditions(self, **network_conditions):
136 | """
137 | Sets Edge network emulation settings.
138 |
139 | :Args:
140 | - network_conditions: A dict with conditions specification.
141 |
142 | :Usage:
143 | driver.set_network_conditions(
144 | offline=False,
145 | latency=5, # additional latency (ms)
146 | download_throughput=500 * 1024, # maximal throughput
147 | upload_throughput=500 * 1024) # maximal throughput
148 |
149 | Note: 'throughput' can be used to set both (for download and upload).
150 | """
151 | self.execute("setNetworkConditions", {
152 | 'network_conditions': network_conditions
153 | })
154 |
155 | def execute_cdp_cmd(self, cmd, cmd_args):
156 | """
157 | Execute Edge Devtools Protocol command and get returned result
158 |
159 | The command and command args should follow Edge devtools protocol domains/commands, refer to link
160 | https://chromedevtools.github.io/devtools-protocol/
161 |
162 | :Args:
163 | - cmd: A str, command name
164 | - cmd_args: A dict, command args. empty dict {} if there is no command args
165 |
166 | :Usage:
167 | driver.execute_cdp_cmd('Network.getResponseBody', {'requestId': requestId})
168 |
169 | :Returns:
170 | A dict, empty dict {} if there is no result to return.
171 | For example to getResponseBody:
172 |
173 | {'base64Encoded': False, 'body': 'response body string'}
174 |
175 | """
176 | return self.execute("executeCdpCommand", {'cmd': cmd, 'params': cmd_args})['value']
177 |
178 | def quit(self):
179 | """
180 | Closes the browser and shuts down the EdgeDriver executable
181 | that is started when starting the EdgeDriver
182 | """
183 | try:
184 | RemoteWebDriver.quit(self)
185 | except Exception:
186 | # We don't care about the message because something probably has gone wrong
187 | pass
188 | finally:
189 | self.service.stop()
190 |
191 | def create_options(self):
192 | return Options()
193 |
--------------------------------------------------------------------------------
/py/setup.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Microsoft
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | from os.path import dirname, join, abspath
16 | from setuptools import setup
17 |
18 | with open(join(abspath(dirname(__file__)), 'README.md'), 'r') as fh:
19 | long_description = fh.read()
20 |
21 | setup(
22 | name = 'msedge-selenium-tools',
23 | version = '3.141.4',
24 | description = 'An updated EdgeDriver implementation for Selenium 3 with newly-added support for Microsoft Edge (Chromium).',
25 | long_description = long_description,
26 | long_description_content_type = 'text/markdown',
27 | url = 'https://github.com/microsoft/edge-selenium-tools',
28 | author = 'Microsoft Corporation',
29 | author_email = 'EdgeDevToolsOSS@microsoft.com',
30 | license = 'Apache 2.0',
31 | packages = [
32 | 'msedge',
33 | 'msedge.selenium_tools'
34 | ],
35 | install_requires = [
36 | 'selenium==3.141'
37 | ],
38 | classifiers = [
39 | 'Development Status :: 5 - Production/Stable',
40 | 'Intended Audience :: Developers',
41 | 'License :: OSI Approved :: Apache Software License',
42 | 'Operating System :: POSIX',
43 | 'Operating System :: Microsoft :: Windows',
44 | 'Operating System :: MacOS :: MacOS X',
45 | 'Topic :: Software Development :: Testing',
46 | 'Topic :: Software Development :: Libraries',
47 | 'Programming Language :: Python',
48 | 'Programming Language :: Python :: 2.7',
49 | 'Programming Language :: Python :: 3.4',
50 | 'Programming Language :: Python :: 3.5',
51 | 'Programming Language :: Python :: 3.6'
52 | ],
53 | zip_safe = False
54 | )
--------------------------------------------------------------------------------
/py/tests/edge_driver_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Microsoft
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import unittest
16 | import sys
17 | import os
18 |
19 | sys.path.insert(1, os.path.join(sys.path[0], '..'))
20 | from msedge.selenium_tools import Edge, EdgeOptions, EdgeService
21 |
22 | class EdgeDriverTest(unittest.TestCase):
23 |
24 | @unittest.skip(reason="Edge Legacy is not available on Azure hosted environment.")
25 | def test_default(self):
26 | try:
27 | driver = Edge()
28 | cap = driver.capabilities
29 | self.assertEqual('MicrosoftEdge', cap['browserName'], 'Driver launches Edge Legacy.')
30 | except:
31 | self.assertTrue(False, 'Test default options failed.')
32 | else:
33 | driver.quit()
34 |
35 | @unittest.skip(reason="Edge Legacy is not available on Azure hosted environment.")
36 | def test_legacy_options(self):
37 | try:
38 | options = EdgeOptions()
39 | options.use_chromium = False
40 | driver = Edge(options = options)
41 | cap = driver.capabilities
42 | self.assertEqual('MicrosoftEdge', cap['browserName'], 'Driver launches Edge Legacy.')
43 | except:
44 | self.assertTrue(False, 'Test legacy options failed.')
45 | else:
46 | driver.quit()
47 |
48 | def test_chromium_options(self):
49 | try:
50 | options = EdgeOptions()
51 | options.use_chromium = True
52 | driver = Edge(options = options)
53 | cap = driver.capabilities
54 | self.assertEqual('msedge', cap['browserName'], 'Driver launches Edge Chromium.')
55 |
56 | result = driver.execute_cdp_cmd('Browser.getVersion', {})
57 | self.assertTrue('userAgent' in result, 'Driver can send Chromium-specific commands.')
58 | except:
59 | self.assertTrue(False, 'Test chromium options failed.')
60 | else:
61 | driver.quit()
62 |
63 | def test_chromium_driver_with_chromium_options(self):
64 | options = EdgeOptions()
65 | options.use_chromium = True
66 | try:
67 | driver = Edge('msedgedriver.exe', options=options)
68 | except:
69 | self.assertTrue(False, 'Test chromium driver with chromium options failed.')
70 | else:
71 | driver.quit()
72 |
73 | @unittest.skip(reason="Edge Legacy is not available on Azure hosted environment.")
74 | def test_legacy_driver_with_legacy_options(self):
75 | options = EdgeOptions()
76 | try:
77 | driver = Edge('MicrosoftWebDriver.exe', options=options)
78 | except Exception as e:
79 | self.assertTrue(False, 'Test legacy driver with legacy options failed.')
80 | else:
81 | driver.quit()
82 |
83 | def test_chromium_options_to_capabilities(self):
84 | options = EdgeOptions()
85 | options.use_chromium = True
86 | options._page_load_strategy = 'eager' # common
87 | options._debugger_address = 'localhost:9222' # chromium only
88 |
89 | cap = options.to_capabilities()
90 | self.assertEqual('MicrosoftEdge', cap['browserName'])
91 | self.assertIn('ms:edgeOptions', cap)
92 | self.assertTrue(cap['ms:edgeChromium'])
93 |
94 | edge_options_dict = cap['ms:edgeOptions']
95 | self.assertIsNotNone(edge_options_dict)
96 | self.assertEqual('localhost:9222', edge_options_dict['debuggerAddress'])
97 |
98 | def test_legacy_options_to_capabilities(self):
99 | options = EdgeOptions()
100 | options._page_load_strategy = 'eager' # common
101 | options._debugger_address = 'localhost:9222' # chromium only
102 |
103 | cap = options.to_capabilities()
104 | self.assertEqual('MicrosoftEdge', cap['browserName'])
105 | self.assertEqual('eager', cap['pageLoadStrategy'])
106 | self.assertFalse('ms:edgeOptions' in cap)
107 | self.assertFalse(cap['ms:edgeChromium'])
108 |
109 | def test_webview_options_to_capabilities(self):
110 | options = EdgeOptions()
111 | options.use_chromium = True
112 | options.use_webview = True
113 |
114 | cap = options.to_capabilities()
115 | self.assertEqual('webview2', cap['browserName'])
116 |
117 | if __name__=='__main__':
118 | unittest.main()
--------------------------------------------------------------------------------