Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/selenium-webdriver/index.js
2884 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
/**
19
* @fileoverview The main user facing module. Exports WebDriver's primary
20
* public API and provides convenience assessors to certain sub-modules.
21
*/
22
23
'use strict'
24
25
const _http = require('./http')
26
const by = require('./lib/by')
27
const capabilities = require('./lib/capabilities')
28
const chrome = require('./chrome')
29
const edge = require('./edge')
30
const error = require('./lib/error')
31
const firefox = require('./firefox')
32
const ie = require('./ie')
33
const input = require('./lib/input')
34
const logging = require('./lib/logging')
35
const promise = require('./lib/promise')
36
const remote = require('./remote')
37
const safari = require('./safari')
38
const session = require('./lib/session')
39
const until = require('./lib/until')
40
const webdriver = require('./lib/webdriver')
41
const select = require('./lib/select')
42
const LogInspector = require('./bidi/logInspector')
43
const BrowsingContext = require('./bidi/browsingContext')
44
const BrowsingContextInspector = require('./bidi/browsingContextInspector')
45
const ScriptManager = require('./bidi/scriptManager')
46
const NetworkInspector = require('./bidi/networkInspector')
47
const version = require('./package.json').version
48
49
const Browser = capabilities.Browser
50
const Capabilities = capabilities.Capabilities
51
const Capability = capabilities.Capability
52
const WebDriver = webdriver.WebDriver
53
54
let seleniumServer
55
56
/**
57
* Starts an instance of the Selenium server if not yet running.
58
* @param {string} jar Path to the server jar to use.
59
* @return {!Promise<string>} A promise for the server's
60
* address once started.
61
*/
62
function startSeleniumServer(jar) {
63
if (!seleniumServer) {
64
seleniumServer = new remote.SeleniumServer(jar)
65
}
66
return seleniumServer.start()
67
}
68
69
/**
70
* {@linkplain webdriver.WebDriver#setFileDetector WebDriver's setFileDetector}
71
* method uses a non-standard command to transfer files from the local client
72
* to the remote end hosting the browser. Many of the WebDriver sub-types, like
73
* the {@link chrome.Driver} and {@link firefox.Driver}, do not support this
74
* command. Thus, these classes override the `setFileDetector` to no-op.
75
*
76
* This function uses a mixin to re-enable `setFileDetector` by calling the
77
* original method on the WebDriver prototype directly. This is used only when
78
* the builder creates a Chrome or Firefox instance that communicates with a
79
* remote end (and thus, support for remote file detectors is unknown).
80
*
81
* @param {function(new: webdriver.WebDriver, ...?)} ctor
82
* @return {function(new: webdriver.WebDriver, ...?)}
83
*/
84
function ensureFileDetectorsAreEnabled(ctor) {
85
return class extends ctor {
86
/** @param {input.FileDetector} detector */
87
setFileDetector(detector) {
88
webdriver.WebDriver.prototype.setFileDetector.call(this, detector)
89
}
90
}
91
}
92
93
/**
94
* A thenable wrapper around a {@linkplain webdriver.IWebDriver IWebDriver}
95
* instance that allows commands to be issued directly instead of having to
96
* repeatedly call `then`:
97
*
98
* let driver = new Builder().build();
99
* driver.then(d => d.get(url)); // You can do this...
100
* driver.get(url); // ...or this
101
*
102
* If the driver instance fails to resolve (e.g. the session cannot be created),
103
* every issued command will fail.
104
*
105
* @extends {webdriver.IWebDriver}
106
* @extends {IThenable<!webdriver.IWebDriver>}
107
* @interface
108
*/
109
class ThenableWebDriver {
110
/** @param {...?} args */
111
static createSession(...args) {} // eslint-disable-line
112
}
113
114
/**
115
* @const {!Map<function(new: WebDriver, !IThenable<!Session>, ...?),
116
* function(new: ThenableWebDriver, !IThenable<!Session>, ...?)>}
117
*/
118
const THENABLE_DRIVERS = new Map()
119
120
/**
121
* @param {function(new: WebDriver, !IThenable<!Session>, ...?)} ctor
122
* @param {...?} args
123
* @return {!ThenableWebDriver}
124
*/
125
function createDriver(ctor, ...args) {
126
let thenableWebDriverProxy = THENABLE_DRIVERS.get(ctor)
127
if (!thenableWebDriverProxy) {
128
/**
129
* @extends {WebDriver} // Needed since `ctor` is dynamically typed.
130
* @implements {ThenableWebDriver}
131
*/
132
thenableWebDriverProxy = class extends ctor {
133
/**
134
* @param {!IThenable<!Session>} session
135
* @param {...?} rest
136
*/
137
constructor(session, ...rest) {
138
super(session, ...rest)
139
140
const pd = this.getSession().then((session) => {
141
return new ctor(session, ...rest)
142
})
143
144
/** @override */
145
this.then = pd.then.bind(pd)
146
147
/** @override */
148
this.catch = pd.catch.bind(pd)
149
}
150
}
151
THENABLE_DRIVERS.set(ctor, thenableWebDriverProxy)
152
}
153
return thenableWebDriverProxy.createSession(...args)
154
}
155
156
/**
157
* Creates new {@link webdriver.WebDriver WebDriver} instances. The environment
158
* variables listed below may be used to override a builder's configuration,
159
* allowing quick runtime changes.
160
*
161
* - {@code SELENIUM_BROWSER}: defines the target browser in the form
162
* {@code browser[:version][:platform]}.
163
*
164
* - {@code SELENIUM_REMOTE_URL}: defines the remote URL for all builder
165
* instances. This environment variable should be set to a fully qualified
166
* URL for a WebDriver server (e.g. http://localhost:4444/wd/hub). This
167
* option always takes precedence over {@code SELENIUM_SERVER_JAR}.
168
*
169
* - {@code SELENIUM_SERVER_JAR}: defines the path to the
170
* <a href="https://www.selenium.dev/downloads/">
171
* standalone Selenium server</a> jar to use. The server will be started the
172
* first time a WebDriver instance and be killed when the process exits.
173
*
174
* Suppose you had mytest.js that created WebDriver with
175
*
176
* var driver = new webdriver.Builder()
177
* .forBrowser('chrome')
178
* .build();
179
*
180
* This test could be made to use Firefox on the local machine by running with
181
* `SELENIUM_BROWSER=firefox node mytest.js`. Rather than change the code to
182
* target Google Chrome on a remote machine, you can simply set the
183
* `SELENIUM_BROWSER` and `SELENIUM_REMOTE_URL` environment variables:
184
*
185
* SELENIUM_BROWSER=chrome:36:LINUX \
186
* SELENIUM_REMOTE_URL=http://www.example.com:4444/wd/hub \
187
* node mytest.js
188
*
189
* You could also use a local copy of the standalone Selenium server:
190
*
191
* SELENIUM_BROWSER=chrome:36:LINUX \
192
* SELENIUM_SERVER_JAR=/path/to/selenium-server-standalone.jar \
193
* node mytest.js
194
*/
195
class Builder {
196
constructor() {
197
/** @private @const */
198
this.log_ = logging.getLogger(`${logging.Type.DRIVER}.Builder`)
199
200
/** @private {string} */
201
this.url_ = ''
202
203
/** @private {?string} */
204
this.proxy_ = null
205
206
/** @private {!Capabilities} */
207
this.capabilities_ = new Capabilities()
208
209
/** @private {chrome.Options} */
210
this.chromeOptions_ = null
211
212
/** @private {chrome.ServiceBuilder} */
213
this.chromeService_ = null
214
215
/** @private {firefox.Options} */
216
this.firefoxOptions_ = null
217
218
/** @private {firefox.ServiceBuilder} */
219
this.firefoxService_ = null
220
221
/** @private {ie.Options} */
222
this.ieOptions_ = null
223
224
/** @private {ie.ServiceBuilder} */
225
this.ieService_ = null
226
227
/** @private {safari.Options} */
228
this.safariOptions_ = null
229
230
/** @private {edge.Options} */
231
this.edgeOptions_ = null
232
233
/** @private {remote.DriverService.Builder} */
234
this.edgeService_ = null
235
236
/** @private {boolean} */
237
this.ignoreEnv_ = false
238
239
/** @private {http.Agent} */
240
this.agent_ = null
241
}
242
243
/**
244
* Configures this builder to ignore any environment variable overrides and to
245
* only use the configuration specified through this instance's API.
246
*
247
* @return {!Builder} A self reference.
248
*/
249
disableEnvironmentOverrides() {
250
this.ignoreEnv_ = true
251
return this
252
}
253
254
/**
255
* Sets the URL of a remote WebDriver server to use. Once a remote URL has
256
* been specified, the builder direct all new clients to that server. If this
257
* method is never called, the Builder will attempt to create all clients
258
* locally.
259
*
260
* As an alternative to this method, you may also set the
261
* `SELENIUM_REMOTE_URL` environment variable.
262
*
263
* @param {string} url The URL of a remote server to use.
264
* @return {!Builder} A self reference.
265
*/
266
usingServer(url) {
267
this.url_ = url
268
return this
269
}
270
271
/**
272
* @return {string} The URL of the WebDriver server this instance is
273
* configured to use.
274
*/
275
getServerUrl() {
276
return this.url_
277
}
278
279
/**
280
* Sets the URL of the proxy to use for the WebDriver's HTTP connections.
281
* If this method is never called, the Builder will create a connection
282
* without a proxy.
283
*
284
* @param {string} proxy The URL of a proxy to use.
285
* @return {!Builder} A self reference.
286
*/
287
usingWebDriverProxy(proxy) {
288
this.proxy_ = proxy
289
return this
290
}
291
292
/**
293
* @return {?string} The URL of the proxy server to use for the WebDriver's
294
* HTTP connections, or `null` if not set.
295
*/
296
getWebDriverProxy() {
297
return this.proxy_
298
}
299
300
/**
301
* Sets the http agent to use for each request.
302
* If this method is not called, the Builder will use http.globalAgent by default.
303
*
304
* @param {http.Agent} agent The agent to use for each request.
305
* @return {!Builder} A self reference.
306
*/
307
usingHttpAgent(agent) {
308
this.agent_ = agent
309
return this
310
}
311
312
/**
313
* @return {http.Agent} The http agent used for each request
314
*/
315
getHttpAgent() {
316
return this.agent_
317
}
318
319
/**
320
* Recommended way is to use set*Options where * is the browser(eg setChromeOptions)
321
*
322
* Sets the desired capabilities when requesting a new session. This will
323
* overwrite any previously set capabilities.
324
* @param {!(Object|Capabilities)} capabilities The desired capabilities for
325
* a new session.
326
* @return {!Builder} A self reference.
327
*/
328
withCapabilities(capabilities) {
329
this.capabilities_ = new Capabilities(capabilities)
330
return this
331
}
332
333
/**
334
* Returns the base set of capabilities this instance is currently configured
335
* to use.
336
* @return {!Capabilities} The current capabilities for this builder.
337
*/
338
getCapabilities() {
339
return this.capabilities_
340
}
341
342
/**
343
* Sets the desired capability when requesting a new session.
344
* If there is already a capability named key, its value will be overwritten with value.
345
* This is a convenience wrapper around builder.getCapabilities().set(key, value) to support Builder method chaining.
346
* @param {string} key The capability key.
347
* @param {*} value The capability value.
348
* @return {!Builder} A self reference.
349
*/
350
setCapability(key, value) {
351
this.capabilities_.set(key, value)
352
return this
353
}
354
355
/**
356
* Configures the target browser for clients created by this instance.
357
* Any calls to {@link #withCapabilities} after this function will
358
* overwrite these settings.
359
*
360
* You may also define the target browser using the {@code SELENIUM_BROWSER}
361
* environment variable. If set, this environment variable should be of the
362
* form `browser[:[version][:platform]]`.
363
*
364
* @param {(string|!Browser)} name The name of the target browser;
365
* common defaults are available on the {@link webdriver.Browser} enum.
366
* @param {string=} opt_version A desired version; may be omitted if any
367
* version should be used.
368
* @param {(string|!capabilities.Platform)=} opt_platform
369
* The desired platform; may be omitted if any platform may be used.
370
* @return {!Builder} A self reference.
371
*/
372
forBrowser(name, opt_version, opt_platform) {
373
this.capabilities_.setBrowserName(name)
374
if (opt_version) {
375
this.capabilities_.setBrowserVersion(opt_version)
376
}
377
if (opt_platform) {
378
this.capabilities_.setPlatform(opt_platform)
379
}
380
return this
381
}
382
383
/**
384
* Sets the proxy configuration for the target browser.
385
* Any calls to {@link #withCapabilities} after this function will
386
* overwrite these settings.
387
*
388
* @param {!./lib/proxy.Config} config The configuration to use.
389
* @return {!Builder} A self reference.
390
*/
391
setProxy(config) {
392
this.capabilities_.setProxy(config)
393
return this
394
}
395
396
/**
397
* Sets the logging preferences for the created session. Preferences may be
398
* changed by repeated calls, or by calling {@link #withCapabilities}.
399
* @param {!(./lib/logging.Preferences|Object<string, string>)} prefs The
400
* desired logging preferences.
401
* @return {!Builder} A self reference.
402
*/
403
setLoggingPrefs(prefs) {
404
this.capabilities_.setLoggingPrefs(prefs)
405
return this
406
}
407
408
/**
409
* Sets the default action to take with an unexpected alert before returning
410
* an error.
411
*
412
* @param {?capabilities.UserPromptHandler} behavior The desired behavior.
413
* @return {!Builder} A self reference.
414
* @see capabilities.Capabilities#setAlertBehavior
415
*/
416
setAlertBehavior(behavior) {
417
this.capabilities_.setAlertBehavior(behavior)
418
return this
419
}
420
421
/**
422
* Sets Chrome specific {@linkplain chrome.Options options} for drivers
423
* created by this builder. Any logging or proxy settings defined on the given
424
* options will take precedence over those set through
425
* {@link #setLoggingPrefs} and {@link #setProxy}, respectively.
426
*
427
* @param {!chrome.Options} options The ChromeDriver options to use.
428
* @return {!Builder} A self reference.
429
*/
430
setChromeOptions(options) {
431
this.chromeOptions_ = options
432
return this
433
}
434
435
/**
436
* @return {chrome.Options} the Chrome specific options currently configured
437
* for this builder.
438
*/
439
getChromeOptions() {
440
return this.chromeOptions_
441
}
442
443
/**
444
* Sets the service builder to use for managing the chromedriver child process
445
* when creating new Chrome sessions.
446
*
447
* @param {chrome.ServiceBuilder} service the service to use.
448
* @return {!Builder} A self reference.
449
*/
450
setChromeService(service) {
451
if (service && !(service instanceof chrome.ServiceBuilder)) {
452
throw TypeError('not a chrome.ServiceBuilder object')
453
}
454
this.chromeService_ = service
455
return this
456
}
457
458
/**
459
* Sets Firefox specific {@linkplain firefox.Options options} for drivers
460
* created by this builder. Any logging or proxy settings defined on the given
461
* options will take precedence over those set through
462
* {@link #setLoggingPrefs} and {@link #setProxy}, respectively.
463
*
464
* @param {!firefox.Options} options The FirefoxDriver options to use.
465
* @return {!Builder} A self reference.
466
*/
467
setFirefoxOptions(options) {
468
this.firefoxOptions_ = options
469
return this
470
}
471
472
/**
473
* @return {firefox.Options} the Firefox specific options currently configured
474
* for this instance.
475
*/
476
getFirefoxOptions() {
477
return this.firefoxOptions_
478
}
479
480
/**
481
* Sets the {@link firefox.ServiceBuilder} to use to manage the geckodriver
482
* child process when creating Firefox sessions locally.
483
*
484
* @param {firefox.ServiceBuilder} service the service to use.
485
* @return {!Builder} a self reference.
486
*/
487
setFirefoxService(service) {
488
if (service && !(service instanceof firefox.ServiceBuilder)) {
489
throw TypeError('not a firefox.ServiceBuilder object')
490
}
491
this.firefoxService_ = service
492
return this
493
}
494
495
/**
496
* Set Internet Explorer specific {@linkplain ie.Options options} for drivers
497
* created by this builder. Any proxy settings defined on the given options
498
* will take precedence over those set through {@link #setProxy}.
499
*
500
* @param {!ie.Options} options The IEDriver options to use.
501
* @return {!Builder} A self reference.
502
*/
503
setIeOptions(options) {
504
this.ieOptions_ = options
505
return this
506
}
507
508
/**
509
* Sets the {@link ie.ServiceBuilder} to use to manage the geckodriver
510
* child process when creating IE sessions locally.
511
*
512
* @param {ie.ServiceBuilder} service the service to use.
513
* @return {!Builder} a self reference.
514
*/
515
setIeService(service) {
516
this.ieService_ = service
517
return this
518
}
519
520
/**
521
* Set {@linkplain edge.Options options} specific to Microsoft's Edge browser
522
* for drivers created by this builder. Any proxy settings defined on the
523
* given options will take precedence over those set through
524
* {@link #setProxy}.
525
*
526
* @param {!edge.Options} options The MicrosoftEdgeDriver options to use.
527
* @return {!Builder} A self reference.
528
*/
529
setEdgeOptions(options) {
530
this.edgeOptions_ = options
531
return this
532
}
533
534
/**
535
* Sets the {@link edge.ServiceBuilder} to use to manage the
536
* MicrosoftEdgeDriver child process when creating sessions locally.
537
*
538
* @param {edge.ServiceBuilder} service the service to use.
539
* @return {!Builder} a self reference.
540
*/
541
setEdgeService(service) {
542
if (service && !(service instanceof edge.ServiceBuilder)) {
543
throw TypeError('not a edge.ServiceBuilder object')
544
}
545
this.edgeService_ = service
546
return this
547
}
548
549
/**
550
* Sets Safari specific {@linkplain safari.Options options} for drivers
551
* created by this builder. Any logging settings defined on the given options
552
* will take precedence over those set through {@link #setLoggingPrefs}.
553
*
554
* @param {!safari.Options} options The Safari options to use.
555
* @return {!Builder} A self reference.
556
*/
557
setSafariOptions(options) {
558
this.safariOptions_ = options
559
return this
560
}
561
562
/**
563
* @return {safari.Options} the Safari specific options currently configured
564
* for this instance.
565
*/
566
getSafariOptions() {
567
return this.safariOptions_
568
}
569
570
/**
571
* Creates a new WebDriver client based on this builder's current
572
* configuration.
573
*
574
* This method will return a {@linkplain ThenableWebDriver} instance, allowing
575
* users to issue commands directly without calling `then()`. The returned
576
* thenable wraps a promise that will resolve to a concrete
577
* {@linkplain webdriver.WebDriver WebDriver} instance. The promise will be
578
* rejected if the remote end fails to create a new session.
579
*
580
* @return {!ThenableWebDriver} A new WebDriver instance.
581
* @throws {Error} If the current configuration is invalid.
582
*/
583
build() {
584
// Create a copy for any changes we may need to make based on the current
585
// environment.
586
const capabilities = new Capabilities(this.capabilities_)
587
588
let browser
589
if (!this.ignoreEnv_ && process.env.SELENIUM_BROWSER) {
590
this.log_.fine(`SELENIUM_BROWSER=${process.env.SELENIUM_BROWSER}`)
591
browser = process.env.SELENIUM_BROWSER.split(/:/, 3)
592
capabilities.setBrowserName(browser[0])
593
594
browser[1] && capabilities.setBrowserVersion(browser[1])
595
browser[2] && capabilities.setPlatform(browser[2])
596
}
597
598
browser = capabilities.get(Capability.BROWSER_NAME)
599
600
/**
601
* If browser is not defined in forBrowser, check if browserOptions are defined to pick the browserName
602
*/
603
if (!browser) {
604
const options =
605
this.chromeOptions_ || this.firefoxOptions_ || this.ieOptions_ || this.safariOptions_ || this.edgeOptions_
606
if (options) {
607
browser = options['map_'].get(Capability.BROWSER_NAME)
608
}
609
}
610
611
if (typeof browser !== 'string') {
612
throw TypeError(
613
`Target browser must be a string, but is <${typeof browser}>;` + ' did you forget to call forBrowser()?',
614
)
615
}
616
617
if (browser === 'ie') {
618
browser = Browser.INTERNET_EXPLORER
619
}
620
621
// Apply browser specific overrides.
622
if (browser === Browser.CHROME && this.chromeOptions_) {
623
capabilities.merge(this.chromeOptions_)
624
} else if (browser === Browser.FIREFOX && this.firefoxOptions_) {
625
capabilities.merge(this.firefoxOptions_)
626
} else if (browser === Browser.INTERNET_EXPLORER && this.ieOptions_) {
627
capabilities.merge(this.ieOptions_)
628
} else if (browser === Browser.SAFARI && this.safariOptions_) {
629
capabilities.merge(this.safariOptions_)
630
} else if (browser === Browser.EDGE && this.edgeOptions_) {
631
capabilities.merge(this.edgeOptions_)
632
}
633
634
checkOptions(capabilities, 'chromeOptions', chrome.Options, 'setChromeOptions')
635
checkOptions(capabilities, 'moz:firefoxOptions', firefox.Options, 'setFirefoxOptions')
636
checkOptions(capabilities, 'safari.options', safari.Options, 'setSafariOptions')
637
638
// Check for a remote browser.
639
let url = this.url_
640
if (!this.ignoreEnv_) {
641
if (process.env.SELENIUM_REMOTE_URL) {
642
this.log_.fine(`SELENIUM_REMOTE_URL=${process.env.SELENIUM_REMOTE_URL}`)
643
url = process.env.SELENIUM_REMOTE_URL
644
} else if (process.env.SELENIUM_SERVER_JAR) {
645
this.log_.fine(`SELENIUM_SERVER_JAR=${process.env.SELENIUM_SERVER_JAR}`)
646
url = startSeleniumServer(process.env.SELENIUM_SERVER_JAR)
647
}
648
}
649
650
if (url) {
651
this.log_.fine('Creating session on remote server')
652
let client = Promise.resolve(url).then((url) => new _http.HttpClient(url, this.agent_, this.proxy_))
653
let executor = new _http.Executor(client)
654
655
if (browser === Browser.CHROME) {
656
const driver = ensureFileDetectorsAreEnabled(chrome.Driver)
657
return createDriver(driver, capabilities, executor)
658
}
659
660
if (browser === Browser.FIREFOX) {
661
const driver = ensureFileDetectorsAreEnabled(firefox.Driver)
662
return createDriver(driver, capabilities, executor)
663
}
664
return createDriver(WebDriver, executor, capabilities)
665
}
666
667
// Check for a native browser.
668
switch (browser) {
669
case Browser.CHROME: {
670
let service = null
671
if (this.chromeService_) {
672
service = this.chromeService_.build()
673
}
674
return createDriver(chrome.Driver, capabilities, service)
675
}
676
677
case Browser.FIREFOX: {
678
let service = null
679
if (this.firefoxService_) {
680
service = this.firefoxService_.build()
681
}
682
return createDriver(firefox.Driver, capabilities, service)
683
}
684
685
case Browser.INTERNET_EXPLORER: {
686
let service = null
687
if (this.ieService_) {
688
service = this.ieService_.build()
689
}
690
return createDriver(ie.Driver, capabilities, service)
691
}
692
693
case Browser.EDGE: {
694
let service = null
695
if (this.edgeService_) {
696
service = this.edgeService_.build()
697
}
698
return createDriver(edge.Driver, capabilities, service)
699
}
700
701
case Browser.SAFARI:
702
return createDriver(safari.Driver, capabilities)
703
704
default:
705
throw new Error('Do not know how to build driver: ' + browser + '; did you forget to call usingServer(url)?')
706
}
707
}
708
}
709
710
/**
711
* In the 3.x releases, the various browser option classes
712
* (e.g. firefox.Options) had to be manually set as an option using the
713
* Capabilities class:
714
*
715
* let ffo = new firefox.Options();
716
* // Configure firefox options...
717
*
718
* let caps = new Capabilities();
719
* caps.set('moz:firefoxOptions', ffo);
720
*
721
* let driver = new Builder()
722
* .withCapabilities(caps)
723
* .build();
724
*
725
* The options are now subclasses of Capabilities and can be used directly. A
726
* direct translation of the above is:
727
*
728
* let ffo = new firefox.Options();
729
* // Configure firefox options...
730
*
731
* let driver = new Builder()
732
* .withCapabilities(ffo)
733
* .build();
734
*
735
* You can also set the options for various browsers at once and let the builder
736
* choose the correct set at runtime (see Builder docs above):
737
*
738
* let ffo = new firefox.Options();
739
* // Configure ...
740
*
741
* let co = new chrome.Options();
742
* // Configure ...
743
*
744
* let driver = new Builder()
745
* .setChromeOptions(co)
746
* .setFirefoxOptions(ffo)
747
* .build();
748
*
749
* @param {!Capabilities} caps
750
* @param {string} key
751
* @param {function(new: Capabilities)} optionType
752
* @param {string} setMethod
753
* @throws {error.InvalidArgumentError}
754
*/
755
function checkOptions(caps, key, optionType, setMethod) {
756
let val = caps.get(key)
757
if (val instanceof optionType) {
758
throw new error.InvalidArgumentError(
759
'Options class extends Capabilities and should not be set as key ' +
760
`"${key}"; set browser-specific options with ` +
761
`Builder.${setMethod}(). For more information, see the ` +
762
'documentation attached to the function that threw this error',
763
)
764
}
765
}
766
767
// PUBLIC API
768
769
exports.Browser = capabilities.Browser
770
exports.Builder = Builder
771
exports.Button = input.Button
772
exports.By = by.By
773
exports.RelativeBy = by.RelativeBy
774
exports.withTagName = by.withTagName
775
exports.locateWith = by.locateWith
776
exports.Capabilities = capabilities.Capabilities
777
exports.Capability = capabilities.Capability
778
exports.Condition = webdriver.Condition
779
exports.FileDetector = input.FileDetector
780
exports.Key = input.Key
781
exports.Origin = input.Origin
782
exports.Session = session.Session
783
exports.ThenableWebDriver = ThenableWebDriver
784
exports.WebDriver = webdriver.WebDriver
785
exports.WebElement = webdriver.WebElement
786
exports.WebElementCondition = webdriver.WebElementCondition
787
exports.WebElementPromise = webdriver.WebElementPromise
788
exports.error = error
789
exports.logging = logging
790
exports.promise = promise
791
exports.until = until
792
exports.Select = select.Select
793
exports.LogInspector = LogInspector
794
exports.BrowsingContext = BrowsingContext
795
exports.BrowsingContextInspector = BrowsingContextInspector
796
exports.ScriptManager = ScriptManager
797
exports.NetworkInspector = NetworkInspector
798
exports.version = version
799
800