Skip to content

Commit 4e1fd04

Browse files
committedMay 18, 2024
[js] Marking those as modules
1 parent 9ff86f3 commit 4e1fd04

File tree

6 files changed

+1977
-1908
lines changed

6 files changed

+1977
-1908
lines changed
 

‎javascript/node/selenium-webdriver/chrome.js

+87-84
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,15 @@
118118
* [PATH]: http://en.wikipedia.org/wiki/PATH_%28variable%29
119119
* [android]: https://chromedriver.chromium.org/getting-started/getting-started---android
120120
* [webview]: https://developer.chrome.com/multidevice/webview/overview
121+
*
122+
* @module selenium-webdriver/chrome
121123
*/
122124

123-
'use strict'
125+
"use strict";
124126

125-
const { Browser } = require('./lib/capabilities')
126-
const chromium = require('./chromium')
127-
const CHROME_CAPABILITY_KEY = 'goog:chromeOptions'
127+
const { Browser } = require("./lib/capabilities");
128+
const chromium = require("./chromium");
129+
const CHROME_CAPABILITY_KEY = "goog:chromeOptions";
128130

129131
/** @type {remote.DriverService} */
130132

@@ -134,104 +136,105 @@ const CHROME_CAPABILITY_KEY = 'goog:chromeOptions'
134136
* server in a child process.
135137
*/
136138
class ServiceBuilder extends chromium.ServiceBuilder {
137-
/**
138-
* @param {string=} opt_exe Path to the server executable to use. If omitted,
139-
* the builder will attempt to locate the chromedriver on the current
140-
* PATH. If the chromedriver is not available in path, selenium-manager will
141-
* download the chromedriver
142-
* @throws {Error} If provided executable does not exist, or the chromedriver
143-
* cannot be found on the PATH.
144-
*/
145-
constructor(opt_exe) {
146-
super(opt_exe)
147-
}
139+
/**
140+
* @param {string=} opt_exe Path to the server executable to use. If omitted,
141+
* the builder will attempt to locate the chromedriver on the current
142+
* PATH. If the chromedriver is not available in path, selenium-manager will
143+
* download the chromedriver
144+
* @throws {Error} If provided executable does not exist, or the chromedriver
145+
* cannot be found on the PATH.
146+
*/
147+
constructor (opt_exe) {
148+
super(opt_exe);
149+
}
148150
}
149151

150152
/**
151153
* Class for managing ChromeDriver specific options.
152154
*/
153155
class Options extends chromium.Options {
154-
/**
155-
* Sets the path to the Chrome binary to use. On Mac OS X, this path should
156-
* reference the actual Chrome executable, not just the application binary
157-
* (e.g. "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome").
158-
*
159-
* The binary path be absolute or relative to the chromedriver server
160-
* executable, but it must exist on the machine that will launch Chrome.
161-
*
162-
* @param {string} path The path to the Chrome binary to use.
163-
* @return {!Options} A self reference.
164-
*/
165-
setChromeBinaryPath(path) {
166-
return this.setBinaryPath(path)
167-
}
156+
/**
157+
* Sets the path to the Chrome binary to use. On Mac OS X, this path should
158+
* reference the actual Chrome executable, not just the application binary
159+
* (e.g. "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome").
160+
*
161+
* The binary path be absolute or relative to the chromedriver server
162+
* executable, but it must exist on the machine that will launch Chrome.
163+
*
164+
* @param {string} path The path to the Chrome binary to use.
165+
* @return {!Options} A self reference.
166+
*/
167+
setChromeBinaryPath (path) {
168+
return this.setBinaryPath(path);
169+
}
168170

169-
/**
170-
* Configures the ChromeDriver to launch Chrome on Android via adb. This
171-
* function is shorthand for
172-
* {@link #androidPackage options.androidPackage('com.android.chrome')}.
173-
* @return {!Options} A self reference.
174-
*/
175-
androidChrome() {
176-
return this.androidPackage('com.android.chrome')
177-
}
171+
/**
172+
* Configures the ChromeDriver to launch Chrome on Android via adb. This
173+
* function is shorthand for
174+
* {@link #androidPackage options.androidPackage('com.android.chrome')}.
175+
* @return {!Options} A self reference.
176+
*/
177+
androidChrome () {
178+
return this.androidPackage("com.android.chrome");
179+
}
178180

179-
/**
180-
* Sets the path to Chrome's log file. This path should exist on the machine
181-
* that will launch Chrome.
182-
* @param {string} path Path to the log file to use.
183-
* @return {!Options} A self reference.
184-
*/
185-
setChromeLogFile(path) {
186-
return this.setBrowserLogFile(path)
187-
}
181+
/**
182+
* Sets the path to Chrome's log file. This path should exist on the machine
183+
* that will launch Chrome.
184+
* @param {string} path Path to the log file to use.
185+
* @return {!Options} A self reference.
186+
*/
187+
setChromeLogFile (path) {
188+
return this.setBrowserLogFile(path);
189+
}
188190

189-
/**
190-
* Sets the directory to store Chrome minidumps in. This option is only
191-
* supported when ChromeDriver is running on Linux.
192-
* @param {string} path The directory path.
193-
* @return {!Options} A self reference.
194-
*/
195-
setChromeMinidumpPath(path) {
196-
return this.setBrowserMinidumpPath(path)
197-
}
191+
/**
192+
* Sets the directory to store Chrome minidumps in. This option is only
193+
* supported when ChromeDriver is running on Linux.
194+
* @param {string} path The directory path.
195+
* @return {!Options} A self reference.
196+
*/
197+
setChromeMinidumpPath (path) {
198+
return this.setBrowserMinidumpPath(path);
199+
}
198200
}
199201

200202
/**
201203
* Creates a new WebDriver client for Chrome.
202204
*/
203205
class Driver extends chromium.Driver {
204-
/**
205-
* Creates a new session with the ChromeDriver.
206-
*
207-
* @param {(Capabilities|Options)=} opt_config The configuration options.
208-
* @param {(remote.DriverService|http.Executor)=} opt_serviceExecutor Either
209-
* a DriverService to use for the remote end, or a preconfigured executor
210-
* for an externally managed endpoint. If neither is provided, the
211-
* {@linkplain ##getDefaultService default service} will be used by
212-
* default.
213-
* @return {!Driver} A new driver instance.
214-
*/
215-
static createSession(opt_config, opt_serviceExecutor) {
216-
let caps = opt_config || new Options()
217-
return /** @type {!Driver} */ (super.createSession(caps, opt_serviceExecutor, 'goog', CHROME_CAPABILITY_KEY))
218-
}
206+
/**
207+
* Creates a new session with the ChromeDriver.
208+
*
209+
* @param {(Capabilities|Options)=} opt_config The configuration options.
210+
* @param {(remote.DriverService|http.Executor)=} opt_serviceExecutor Either
211+
* a DriverService to use for the remote end, or a preconfigured executor
212+
* for an externally managed endpoint. If neither is provided, the
213+
* {@linkplain ##getDefaultService default service} will be used by
214+
* default.
215+
* @return {!Driver} A new driver instance.
216+
*/
217+
static createSession (opt_config, opt_serviceExecutor) {
218+
let caps = opt_config || new Options();
219+
return /** @type {!Driver} */ (super.createSession(caps,
220+
opt_serviceExecutor, "goog", CHROME_CAPABILITY_KEY));
221+
}
219222

220-
/**
221-
* returns new instance chrome driver service
222-
* @returns {remote.DriverService}
223-
*/
224-
static getDefaultService() {
225-
return new ServiceBuilder().build()
226-
}
223+
/**
224+
* returns new instance chrome driver service
225+
* @returns {remote.DriverService}
226+
*/
227+
static getDefaultService () {
228+
return new ServiceBuilder().build();
229+
}
227230
}
228231

229-
Options.prototype.CAPABILITY_KEY = CHROME_CAPABILITY_KEY
230-
Options.prototype.BROWSER_NAME_VALUE = Browser.CHROME
232+
Options.prototype.CAPABILITY_KEY = CHROME_CAPABILITY_KEY;
233+
Options.prototype.BROWSER_NAME_VALUE = Browser.CHROME;
231234

232235
// PUBLIC API
233236
module.exports = {
234-
Driver,
235-
Options,
236-
ServiceBuilder,
237-
}
237+
Driver,
238+
Options,
239+
ServiceBuilder
240+
};

‎javascript/node/selenium-webdriver/chromium.js

+759-733
Large diffs are not rendered by default.

‎javascript/node/selenium-webdriver/edge.js

+73-70
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,15 @@
7373
* {@link ./builder.Builder selenium-webdriver.Builder}.
7474
*
7575
* [WebDriver (Chromium)]: https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium
76+
*
77+
* @module selenium-webdriver/edge
7678
*/
7779

78-
'use strict'
80+
"use strict";
7981

80-
const { Browser } = require('./lib/capabilities')
81-
const chromium = require('./chromium')
82-
const EDGE_CAPABILITY_KEY = 'ms:edgeOptions'
82+
const { Browser } = require("./lib/capabilities");
83+
const chromium = require("./chromium");
84+
const EDGE_CAPABILITY_KEY = "ms:edgeOptions";
8385

8486
/** @type {remote.DriverService} */
8587

@@ -89,90 +91,91 @@ const EDGE_CAPABILITY_KEY = 'ms:edgeOptions'
8991
* server in a child process.
9092
*/
9193
class ServiceBuilder extends chromium.ServiceBuilder {
92-
/**
93-
* @param {string=} opt_exe Path to the server executable to use. If omitted,
94-
* the builder will attempt to locate the msedgedriver on the current
95-
* PATH.
96-
* @throws {Error} If provided executable does not exist, or the msedgedriver
97-
* cannot be found on the PATH.
98-
*/
99-
constructor(opt_exe) {
100-
super(opt_exe)
101-
this.setLoopback(true)
102-
}
94+
/**
95+
* @param {string=} opt_exe Path to the server executable to use. If omitted,
96+
* the builder will attempt to locate the msedgedriver on the current
97+
* PATH.
98+
* @throws {Error} If provided executable does not exist, or the msedgedriver
99+
* cannot be found on the PATH.
100+
*/
101+
constructor (opt_exe) {
102+
super(opt_exe);
103+
this.setLoopback(true);
104+
}
103105
}
104106

105107
/**
106108
* Class for managing edge chromium specific options.
107109
*/
108110
class Options extends chromium.Options {
109-
/**
110-
* Sets the path to the edge binary to use
111-
*
112-
* The binary path be absolute or relative to the msedgedriver server
113-
* executable, but it must exist on the machine that will launch edge chromium.
114-
*
115-
* @param {string} path The path to the msedgedriver binary to use.
116-
* @return {!Options} A self reference.
117-
*/
118-
setEdgeChromiumBinaryPath(path) {
119-
return this.setBinaryPath(path)
120-
}
111+
/**
112+
* Sets the path to the edge binary to use
113+
*
114+
* The binary path be absolute or relative to the msedgedriver server
115+
* executable, but it must exist on the machine that will launch edge chromium.
116+
*
117+
* @param {string} path The path to the msedgedriver binary to use.
118+
* @return {!Options} A self reference.
119+
*/
120+
setEdgeChromiumBinaryPath (path) {
121+
return this.setBinaryPath(path);
122+
}
121123

122-
/**
123-
* Changes the browser name to 'webview2' to enable
124-
* <a href="https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/webdriver">
125-
* test automation of WebView2 apps with Microsoft Edge WebDriver
126-
* </a>
127-
*
128-
* @param {boolean} enable flag to enable or disable the 'webview2' usage
129-
*/
130-
useWebView(enable) {
131-
const browserName = enable ? 'webview2' : Browser.EDGE
132-
return this.setBrowserName(browserName)
133-
}
124+
/**
125+
* Changes the browser name to 'webview2' to enable
126+
* <a href="https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/webdriver">
127+
* test automation of WebView2 apps with Microsoft Edge WebDriver
128+
* </a>
129+
*
130+
* @param {boolean} enable flag to enable or disable the 'webview2' usage
131+
*/
132+
useWebView (enable) {
133+
const browserName = enable ? "webview2" : Browser.EDGE;
134+
return this.setBrowserName(browserName);
135+
}
134136
}
135137

136138
/**
137139
* Creates a new WebDriver client for Microsoft's Edge.
138140
*/
139141
class Driver extends chromium.Driver {
140-
/**
141-
* Creates a new browser session for Microsoft's Edge browser.
142-
*
143-
* @param {(Capabilities|Options)=} opt_config The configuration options.
144-
* @param {remote.DriverService=} opt_serviceExecutor The service to use; will create
145-
* a new Legacy or Chromium service based on {@linkplain Options} by default.
146-
* @return {!Driver} A new driver instance.
147-
*/
148-
static createSession(opt_config, opt_serviceExecutor) {
149-
let caps = opt_config || new Options()
150-
return /** @type {!Driver} */ (super.createSession(caps, opt_serviceExecutor, 'ms', EDGE_CAPABILITY_KEY))
151-
}
142+
/**
143+
* Creates a new browser session for Microsoft's Edge browser.
144+
*
145+
* @param {(Capabilities|Options)=} opt_config The configuration options.
146+
* @param {remote.DriverService=} opt_serviceExecutor The service to use; will create
147+
* a new Legacy or Chromium service based on {@linkplain Options} by default.
148+
* @return {!Driver} A new driver instance.
149+
*/
150+
static createSession (opt_config, opt_serviceExecutor) {
151+
let caps = opt_config || new Options();
152+
return /** @type {!Driver} */ (super.createSession(caps,
153+
opt_serviceExecutor, "ms", EDGE_CAPABILITY_KEY));
154+
}
152155

153-
/**
154-
* returns new instance of edge driver service
155-
* @returns {remote.DriverService}
156-
*/
157-
static getDefaultService() {
158-
return new ServiceBuilder().build()
159-
}
156+
/**
157+
* returns new instance of edge driver service
158+
* @returns {remote.DriverService}
159+
*/
160+
static getDefaultService () {
161+
return new ServiceBuilder().build();
162+
}
160163

161-
/**
162-
* This function is a no-op as file detectors are not supported by this
163-
* implementation.
164-
* @override
165-
*/
166-
setFileDetector() {}
164+
/**
165+
* This function is a no-op as file detectors are not supported by this
166+
* implementation.
167+
* @override
168+
*/
169+
setFileDetector () {}
167170
}
168171

169-
Options.prototype.BROWSER_NAME_VALUE = Browser.EDGE
170-
Options.prototype.CAPABILITY_KEY = EDGE_CAPABILITY_KEY
172+
Options.prototype.BROWSER_NAME_VALUE = Browser.EDGE;
173+
Options.prototype.CAPABILITY_KEY = EDGE_CAPABILITY_KEY;
171174

172175
// PUBLIC API
173176

174177
module.exports = {
175-
Driver,
176-
Options,
177-
ServiceBuilder,
178-
}
178+
Driver,
179+
Options,
180+
ServiceBuilder
181+
};

‎javascript/node/selenium-webdriver/firefox.js

+561-534
Large diffs are not rendered by default.

‎javascript/node/selenium-webdriver/ie.js

+417-411
Large diffs are not rendered by default.

‎javascript/node/selenium-webdriver/safari.js

+80-76
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@
1717

1818
/**
1919
* @fileoverview Defines a WebDriver client for Safari.
20+
*
21+
* @module selenium-webdriver/safari
2022
*/
2123

22-
'use strict'
24+
"use strict";
2325

24-
const http = require('./http')
25-
const remote = require('./remote')
26-
const webdriver = require('./lib/webdriver')
27-
const { Browser, Capabilities } = require('./lib/capabilities')
28-
const { getBinaryPaths } = require('./common/driverFinder')
26+
const http = require("./http");
27+
const remote = require("./remote");
28+
const webdriver = require("./lib/webdriver");
29+
const { Browser, Capabilities } = require("./lib/capabilities");
30+
const { getBinaryPaths } = require("./common/driverFinder");
2931

3032
/**
3133
* Creates {@link remote.DriverService} instances that manage
@@ -34,68 +36,68 @@ const { getBinaryPaths } = require('./common/driverFinder')
3436
* [safaridriver]: https://developer.apple.com/library/prerelease/content/releasenotes/General/WhatsNewInSafari/Articles/Safari_10_0.html#//apple_ref/doc/uid/TP40014305-CH11-DontLinkElementID_28
3537
*/
3638
class ServiceBuilder extends remote.DriverService.Builder {
37-
/**
38-
* @param {string=} opt_exe Path to the server executable to use. If omitted,
39-
* the builder will attempt to locate the safaridriver on the system PATH.
40-
*/
41-
constructor(opt_exe) {
42-
super(opt_exe)
43-
this.setLoopback(true) // Required.
44-
}
39+
/**
40+
* @param {string=} opt_exe Path to the server executable to use. If omitted,
41+
* the builder will attempt to locate the safaridriver on the system PATH.
42+
*/
43+
constructor (opt_exe) {
44+
super(opt_exe);
45+
this.setLoopback(true); // Required.
46+
}
4547
}
4648

47-
const OPTIONS_CAPABILITY_KEY = 'safari:options'
48-
const TECHNOLOGY_PREVIEW_OPTIONS_KEY = 'technologyPreview'
49+
const OPTIONS_CAPABILITY_KEY = "safari:options";
50+
const TECHNOLOGY_PREVIEW_OPTIONS_KEY = "technologyPreview";
4951

5052
/**
5153
* Configuration options specific to the {@link Driver SafariDriver}.
5254
*/
5355
class Options extends Capabilities {
54-
/**
55-
* @param {(Capabilities|Map<string, ?>|Object)=} other Another set of
56-
* capabilities to initialize this instance from.
57-
*/
58-
constructor(other = undefined) {
59-
super(other)
60-
61-
/** @private {!Object} */
62-
this.options_ = this.get(OPTIONS_CAPABILITY_KEY) || {}
63-
64-
this.set(OPTIONS_CAPABILITY_KEY, this.options_)
65-
this.setBrowserName(Browser.SAFARI)
66-
}
67-
68-
/**
69-
* Instruct the SafariDriver to use the Safari Technology Preview if true.
70-
* Otherwise, use the release version of Safari. Defaults to using the release version of Safari.
71-
*
72-
* @param {boolean} useTechnologyPreview
73-
* @return {!Options} A self reference.
74-
*/
75-
setTechnologyPreview(useTechnologyPreview) {
76-
this.options_[TECHNOLOGY_PREVIEW_OPTIONS_KEY] = !!useTechnologyPreview
77-
return this
78-
}
56+
/**
57+
* @param {(Capabilities|Map<string, ?>|Object)=} other Another set of
58+
* capabilities to initialize this instance from.
59+
*/
60+
constructor (other = undefined) {
61+
super(other);
62+
63+
/** @private {!Object} */
64+
this.options_ = this.get(OPTIONS_CAPABILITY_KEY) || {};
65+
66+
this.set(OPTIONS_CAPABILITY_KEY, this.options_);
67+
this.setBrowserName(Browser.SAFARI);
68+
}
69+
70+
/**
71+
* Instruct the SafariDriver to use the Safari Technology Preview if true.
72+
* Otherwise, use the release version of Safari. Defaults to using the release version of Safari.
73+
*
74+
* @param {boolean} useTechnologyPreview
75+
* @return {!Options} A self reference.
76+
*/
77+
setTechnologyPreview (useTechnologyPreview) {
78+
this.options_[TECHNOLOGY_PREVIEW_OPTIONS_KEY] = !!useTechnologyPreview;
79+
return this;
80+
}
7981
}
8082

8183
/**
8284
* @param {(Capabilities|Object<string, *>)=} o The options object
8385
* @return {boolean}
8486
*/
85-
function useTechnologyPreview(o) {
86-
if (o instanceof Capabilities) {
87-
let options = o.get(OPTIONS_CAPABILITY_KEY)
88-
return !!(options && options[TECHNOLOGY_PREVIEW_OPTIONS_KEY])
89-
}
87+
function useTechnologyPreview (o) {
88+
if (o instanceof Capabilities) {
89+
let options = o.get(OPTIONS_CAPABILITY_KEY);
90+
return !!(options && options[TECHNOLOGY_PREVIEW_OPTIONS_KEY]);
91+
}
9092

91-
if (o && typeof o === 'object') {
92-
return !!o[TECHNOLOGY_PREVIEW_OPTIONS_KEY]
93-
}
93+
if (o && typeof o === "object") {
94+
return !!o[TECHNOLOGY_PREVIEW_OPTIONS_KEY];
95+
}
9496

95-
return false
97+
return false;
9698
}
9799

98-
const SAFARIDRIVER_TECHNOLOGY_PREVIEW_EXE = '/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver'
100+
const SAFARIDRIVER_TECHNOLOGY_PREVIEW_EXE = "/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver";
99101

100102
/**
101103
* A WebDriver client for Safari. This class should never be instantiated
@@ -107,32 +109,34 @@ const SAFARIDRIVER_TECHNOLOGY_PREVIEW_EXE = '/Applications/Safari Technology Pre
107109
*
108110
*/
109111
class Driver extends webdriver.WebDriver {
110-
/**
111-
* Creates a new Safari session.
112-
*
113-
* @param {(Options|Capabilities)=} options The configuration options.
114-
* @return {!Driver} A new driver instance.
115-
*/
116-
static createSession(options) {
117-
let caps = options || new Options()
118-
119-
let exe
120-
if (useTechnologyPreview(caps.get(OPTIONS_CAPABILITY_KEY))) {
121-
exe = SAFARIDRIVER_TECHNOLOGY_PREVIEW_EXE
122-
}
123-
124-
let service = new ServiceBuilder(exe).build()
125-
if (!service.getExecutable()) {
126-
service.setExecutable(getBinaryPaths(caps).driverPath)
127-
}
128-
let executor = new http.Executor(service.start().then((url) => new http.HttpClient(url)))
129-
130-
return /** @type {!Driver} */ (super.createSession(executor, caps, () => service.kill()))
131-
}
112+
/**
113+
* Creates a new Safari session.
114+
*
115+
* @param {(Options|Capabilities)=} options The configuration options.
116+
* @return {!Driver} A new driver instance.
117+
*/
118+
static createSession (options) {
119+
let caps = options || new Options();
120+
121+
let exe;
122+
if (useTechnologyPreview(caps.get(OPTIONS_CAPABILITY_KEY))) {
123+
exe = SAFARIDRIVER_TECHNOLOGY_PREVIEW_EXE;
124+
}
125+
126+
let service = new ServiceBuilder(exe).build();
127+
if (!service.getExecutable()) {
128+
service.setExecutable(getBinaryPaths(caps).driverPath);
129+
}
130+
let executor = new http.Executor(
131+
service.start().then((url) => new http.HttpClient(url)));
132+
133+
return /** @type {!Driver} */ (super.createSession(executor, caps,
134+
() => service.kill()));
135+
}
132136
}
133137

134138
// Public API
135139

136-
exports.Driver = Driver
137-
exports.Options = Options
138-
exports.ServiceBuilder = ServiceBuilder
140+
exports.Driver = Driver;
141+
exports.Options = Options;
142+
exports.ServiceBuilder = ServiceBuilder;

0 commit comments

Comments
 (0)
Please sign in to comment.