1717
1818/**
1919 * @fileoverview Defines a {@linkplain Driver WebDriver} client for
20- * Microsoft's Edge web browser. Both Edge (Chromium), and Edge Legacy (EdgeHTML) are
21- * supported. Before using this module, you must download and install the correct
22- * [WebDriver](https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/)
23- * server.
20+ * Microsoft's Edge web browser. Edge (Chromium) is supported and support
21+ * for Edge Legacy (EdgeHTML) as part of https://github.com/SeleniumHQ/selenium/issues/9166.
22+ * Before using this module, you must download and install the correct
23+ * [WebDriver](https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/) server.
2424 *
25- * Ensure that the either MicrosoftWebDriver (EdgeHTML) or msedgedriver (Chromium)
26- * is on your [PATH](http://en.wikipedia.org/wiki/PATH_%28variable%29). MicrosoftWebDriver
27- * and Edge Legacy (EdgeHTML) will be used by default.
25+ * Ensure that the msedgedriver (Chromium)
26+ * is on your [PATH](http://en.wikipedia.org/wiki/PATH_%28variable%29).
2827 *
29- * You may use {@link Options} to specify whether Edge Chromium should be used:
28+ * You may use {@link Options} to specify whether Edge Chromium options should be used:
3029
31- * var edge = require('selenium-webdriver/edge');
32- * var options = new edge.Options();
33- * options.setEdgeChromium(true);
34- * // configure browser options ...
35- * let driver = await new Builder()
36- * .forBrowser('MicrosoftEdge')
37- * .setEdgeOptions(options)
38- * .build();
30+ * const edge = require('selenium-webdriver/edge');
31+ * const options = new edge.Options();
3932
40- * Note that Chromium-specific {@link Options} will be ignored when using Edge Legacy.
41- *
4233 * There are three primary classes exported by this module:
4334 *
4435 * 1. {@linkplain ServiceBuilder}: configures the
6556 * You may also create a {@link Driver} with its own driver service. This is
6657 * useful if you need to capture the server's log output for a specific session:
6758 *
68- * var edge = require('selenium-webdriver/edge');
59+ * const edge = require('selenium-webdriver/edge');
6960 *
70- * var service = new edge.ServiceBuilder()
61+ * const service = new edge.ServiceBuilder()
7162 * .setPort(55555)
7263 * .build();
7364 *
74- * var options = new edge.Options();
65+ * let options = new edge.Options();
7566 * // configure browser options ...
7667 *
77- * var driver = edge.Driver.createSession(options, service);
68+ * let driver = edge.Driver.createSession(options, service);
7869 *
7970 * Users should only instantiate the {@link Driver} class directly when they
8071 * need a custom driver service configuration (as shown above). For normal
81- * operation, users should start MicrosoftEdge using the
72+ * operation, users should start msedgedriver using the
8273 * {@link ./builder.Builder selenium-webdriver.Builder}.
8374 *
84- * [WebDriver (EdgeHTML)]: https://docs.microsoft.com/en-us/microsoft-edge/webdriver
8575 * [WebDriver (Chromium)]: https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium
8676 */
8777
8878'use strict'
8979
90- const http = require ( './http ' )
80+ const { Browser } = require ( './lib/capabilities ' )
9181const io = require ( './io' )
92- const webdriver = require ( './lib/webdriver' )
93- const { Browser, Capabilities } = require ( './lib/capabilities' )
9482const chromium = require ( './chromium' )
83+ const http = require ( './http' )
84+ const webdriver = require ( './lib/webdriver' )
9585
96- const EDGE_CHROMIUM_BROWSER_NAME = 'msedge'
97- const EDGEDRIVER_LEGACY_EXE = 'MicrosoftWebDriver.exe'
86+ /**
87+ * Name of the EdgeDriver executable.
88+ * @type {string }
89+ * @const
90+ */
9891const EDGEDRIVER_CHROMIUM_EXE =
9992 process . platform === 'win32' ? 'msedgedriver.exe' : 'msedgedriver'
10093
94+ /** @type {remote.DriverService } */
95+ let defaultService = null
96+
10197/**
102- * _Synchronously_ attempts to locate the Edge driver executable
103- * on the current system. Searches for the legacy MicrosoftWebDriver by default.
104- *
105- * @param {string= } browserName Name of the Edge driver executable to locate.
106- * May be either 'msedge' to locate the Edge Chromium driver, or 'MicrosoftEdge' to
107- * locate the Edge Legacy driver. If omitted, will attempt to locate Edge Legacy.
108- * @return {?string } the located executable, or `null`.
98+ * Creates {@link selenium-webdriver/remote.DriverService} instances that manage
99+ * a [ChromeDriver](https://chromedriver.chromium.org/)
100+ * server in a child process.
109101 */
110- function locateSynchronously ( browserName ) {
111- browserName = browserName || Browser . EDGE
112-
113- if ( browserName === EDGE_CHROMIUM_BROWSER_NAME ) {
114- return io . findInPath ( EDGEDRIVER_CHROMIUM_EXE , true )
102+ class ServiceBuilder extends chromium . ServiceBuilder {
103+ /**
104+ * @param {string= } opt_exe Path to the server executable to use. If omitted,
105+ * the builder will attempt to locate the msedgedriver on the current
106+ * PATH.
107+ * @throws {Error } If provided executable does not exist, or the msedgedriver
108+ * cannot be found on the PATH.
109+ */
110+ constructor ( opt_exe ) {
111+ let exe = opt_exe || locateSynchronously ( )
112+ if ( ! exe ) {
113+ throw Error (
114+ `The WebDriver for Edge could not be found on the current PATH. Please download the ` +
115+ `latest version of ${ EDGEDRIVER_CHROMIUM_EXE } from ` +
116+ `https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ ` +
117+ `and ensure it can be found on your PATH.`
118+ )
119+ }
120+ super ( exe )
121+ this . setLoopback ( true )
115122 }
116-
117- return process . platform === 'win32'
118- ? io . findInPath ( EDGEDRIVER_LEGACY_EXE , true )
119- : null
120123}
121124
122125/**
123- * Class for managing Edge specific options.
126+ * Class for managing edge chromium specific options.
124127 */
125128class Options extends chromium . Options {
126129 /**
127- * Instruct the EdgeDriver to use Edge Chromium if true.
128- * Otherwise, use Edge Legacy (EdgeHTML). Defaults to using Edge Legacy.
130+ * Sets the path to the edge binary to use
131+ *
132+ * The binary path be absolute or relative to the msedgedriver server
133+ * executable, but it must exist on the machine that will launch edge chromium.
129134 *
130- * @param {boolean } useEdgeChromium
135+ * @param {string } path The path to the edgedriver binary to use.
131136 * @return {!Options } A self reference.
132137 */
133- setEdgeChromium ( useEdgeChromium ) {
134- this . set ( Options . USE_EDGE_CHROMIUM , ! ! useEdgeChromium )
135- return this
138+ setEdgeChromiumBinaryPath ( path ) {
139+ return this . setBinaryPath ( path )
136140 }
137141}
138142
139- Options . USE_EDGE_CHROMIUM = 'ms:edgeChromium'
140- Options . prototype . BROWSER_NAME_VALUE = Browser . EDGE
141- Options . prototype . CAPABILITY_KEY = 'ms:edgeOptions'
142- Options . prototype . VENDOR_CAPABILITY_PREFIX = 'ms'
143-
144143/**
145- * @param {(Capabilities|Object<string, *>)= } o The options object
146- * @return {boolean }
144+ * Creates a new WebDriver client for Microsoft's Edge.
147145 */
148- function useEdgeChromium ( o ) {
149- if ( o instanceof Capabilities ) {
150- return ! ! o . get ( Options . USE_EDGE_CHROMIUM )
151- }
146+ class Driver extends webdriver . WebDriver {
147+ /**
148+ * Creates a new browser session for Microsoft's Edge browser.
149+ *
150+ * @param {(Capabilities|Options)= } options The configuration options.
151+ * @param {remote.DriverService= } opt_service The service to use; will create
152+ * a new Legacy or Chromium service based on {@linkplain Options} by default.
153+ * @return {!Driver } A new driver instance.
154+ */
155+ static createSession ( options , opt_service ) {
156+ options = options || new Options ( )
157+ let service = opt_service || getDefaultService ( )
158+ let client = service . start ( ) . then ( ( url ) => new http . HttpClient ( url ) )
159+ let executor = new http . Executor ( client )
152160
153- if ( o && typeof o === 'object' ) {
154- return ! ! o [ Options . USE_EDGE_CHROMIUM ]
161+ return /** @type {!Driver } */ ( super . createSession ( executor , options , ( ) =>
162+ service . kill ( )
163+ ) )
155164 }
156165
157- return false
158- }
159-
160- /**
161- * Creates {@link remote.DriverService} instances that manage a
162- * WebDriver server in a child process. Used for driving both
163- * Microsoft Edge Legacy and Chromium. A ServiceBuilder constructed
164- * with default parameters will launch a MicrosoftWebDriver child
165- * process for driving Edge Legacy. You may pass in a path to
166- * msedgedriver.exe to use Edge Chromium instead.
167- */
168- class ServiceBuilder extends chromium . ServiceBuilder {
169166 /**
170- * @param {string= } opt_exe Path to the server executable to use. If omitted,
171- * the builder will attempt to locate MicrosoftWebDriver on the current
172- * PATH.
173- * @throws {Error } If provided executable does not exist, or the
174- * MicrosoftWebDriver cannot be found on the PATH.
167+ * This function is a no-op as file detectors are not supported by this
168+ * implementation.
169+ * @override
175170 */
176- constructor ( opt_exe ) {
177- const exe = opt_exe || locateSynchronously ( )
178- if ( ! exe ) {
179- throw Error (
180- 'The WebDriver for Edge could not be found on the current PATH. Please ' +
181- 'download the latest version of ' +
182- EDGEDRIVER_LEGACY_EXE +
183- ' from ' +
184- 'https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ and ' +
185- 'ensure it can be found on your PATH.'
186- )
187- }
188-
189- super ( exe )
190- }
171+ setFileDetector ( ) { }
191172}
192173
193- /** @type {remote.DriverService } */
194- var defaultService = null
195-
196174/**
197175 * Sets the default service to use for new Edge instances.
198176 * @param {!remote.DriverService } service The service to use.
@@ -202,7 +180,7 @@ function setDefaultService(service) {
202180 if ( defaultService && defaultService . isRunning ( ) ) {
203181 throw Error (
204182 'The previously configured EdgeDriver service is still running. ' +
205- 'You must shut it down before you may adjust its configuration.'
183+ 'You must shut it down before you may adjust its configuration.'
206184 )
207185 }
208186 defaultService = service
@@ -221,45 +199,21 @@ function getDefaultService() {
221199 return defaultService
222200}
223201
224- function createServiceFromCapabilities ( options ) {
225- let exe
226- if ( useEdgeChromium ( options ) ) {
227- exe = locateSynchronously ( EDGE_CHROMIUM_BROWSER_NAME )
228- }
229- return new ServiceBuilder ( exe ) . build ( )
230- }
231202
232203/**
233- * Creates a new WebDriver client for Microsoft's Edge.
204+ * _Synchronously_ attempts to locate the chromedriver executable on the current
205+ * system.
206+ *
207+ * @return {?string } the located executable, or `null`.
234208 */
235- class Driver extends webdriver . WebDriver {
236- /**
237- * Creates a new browser session for Microsoft's Edge browser.
238- *
239- * @param {(Capabilities|Options)= } options The configuration options.
240- * @param {remote.DriverService= } opt_service The service to use; will create
241- * a new Legacy or Chromium service based on {@linkplain Options} by default.
242- * @return {!Driver } A new driver instance.
243- */
244- static createSession ( options , opt_service ) {
245- options = options || new Options ( )
246- let service = opt_service || createServiceFromCapabilities ( options )
247- let client = service . start ( ) . then ( ( url ) => new http . HttpClient ( url ) )
248- let executor = new http . Executor ( client )
249-
250- return /** @type {!Driver } */ ( super . createSession ( executor , options , ( ) =>
251- service . kill ( )
252- ) )
253- }
254-
255- /**
256- * This function is a no-op as file detectors are not supported by this
257- * implementation.
258- * @override
259- */
260- setFileDetector ( ) { }
209+ function locateSynchronously ( ) {
210+ return io . findInPath ( EDGEDRIVER_CHROMIUM_EXE , true )
261211}
262212
213+ Options . prototype . BROWSER_NAME_VALUE = Browser . EDGE
214+ Options . prototype . CAPABILITY_KEY = 'ms:edgeOptions'
215+ Driver . prototype . VENDOR_CAPABILITY_PREFIX = 'ms'
216+
263217// PUBLIC API
264218
265219exports . Driver = Driver
0 commit comments