selenium-webdriver 3.0.0-beta-1 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/CHANGES.md +109 -0
  2. package/LICENSE +1 -1
  3. package/README.md +7 -6
  4. package/chrome.js +31 -128
  5. package/edge.js +13 -91
  6. package/example/chrome_android.js +18 -13
  7. package/example/chrome_mobile_emulation.js +19 -15
  8. package/example/google_search.js +11 -11
  9. package/example/google_search_generator.js +23 -18
  10. package/example/google_search_test.js +31 -17
  11. package/example/logging.js +9 -17
  12. package/example/parallel_flows.js +3 -0
  13. package/firefox/binary.js +17 -0
  14. package/firefox/index.js +198 -101
  15. package/firefox/profile.js +24 -3
  16. package/http/util.js +95 -59
  17. package/ie.js +6 -10
  18. package/index.js +636 -2
  19. package/lib/actions.js +18 -10
  20. package/lib/atoms/getAttribute.js +11 -0
  21. package/lib/atoms/isDisplayed.js +106 -0
  22. package/lib/firefox/amd64/libnoblur64.so +0 -0
  23. package/lib/firefox/i386/libnoblur.so +0 -0
  24. package/lib/firefox/webdriver.xpi +0 -0
  25. package/lib/http.js +159 -46
  26. package/lib/logging.js +7 -1
  27. package/lib/promise.js +602 -358
  28. package/lib/proxy.js +28 -0
  29. package/lib/session.js +1 -1
  30. package/lib/test/build.js +26 -28
  31. package/lib/test/data/formPage.html +1 -0
  32. package/lib/test/fileserver.js +12 -10
  33. package/lib/test/httpserver.js +4 -6
  34. package/lib/test/index.js +18 -11
  35. package/lib/test/promise.js +79 -0
  36. package/lib/webdriver.js +587 -479
  37. package/opera.js +12 -88
  38. package/package.json +13 -14
  39. package/phantomjs.js +7 -14
  40. package/remote/index.js +201 -30
  41. package/safari.js +62 -416
  42. package/test/actions_test.js +9 -11
  43. package/test/chrome/options_test.js +8 -8
  44. package/test/chrome/service_test.js +2 -2
  45. package/test/cookie_test.js +57 -57
  46. package/test/element_finding_test.js +201 -185
  47. package/test/execute_script_test.js +108 -111
  48. package/test/fingerprint_test.js +16 -11
  49. package/test/firefox/firefox_test.js +75 -49
  50. package/test/firefox/profile_test.js +1 -3
  51. package/test/http/util_test.js +21 -27
  52. package/test/io_test.js +2 -5
  53. package/test/lib/http_test.js +8 -6
  54. package/test/lib/promise_aplus_test.js +48 -44
  55. package/test/lib/promise_error_test.js +687 -611
  56. package/test/lib/promise_flow_test.js +1810 -1806
  57. package/test/lib/promise_generator_test.js +227 -225
  58. package/test/lib/promise_test.js +864 -835
  59. package/test/lib/until_test.js +1 -1
  60. package/test/lib/webdriver_test.js +520 -424
  61. package/test/logging_test.js +43 -45
  62. package/test/net/portprober_test.js +23 -24
  63. package/test/page_loading_test.js +84 -78
  64. package/test/phantomjs/execute_phantomjs_test.js +11 -25
  65. package/test/proxy_test.js +23 -23
  66. package/test/remote_test.js +22 -22
  67. package/test/safari_test.js +108 -0
  68. package/test/session_test.js +11 -10
  69. package/test/stale_element_test.js +18 -16
  70. package/test/tag_name_test.js +7 -5
  71. package/test/testing/assert_test.js +2 -3
  72. package/test/testing/index_test.js +163 -117
  73. package/test/upload_test.js +13 -13
  74. package/test/window_test.js +94 -70
  75. package/testing/index.js +176 -37
  76. package/builder.js +0 -553
  77. package/lib/safari/client.js +0 -56
package/index.js CHANGED
@@ -22,7 +22,11 @@
22
22
 
23
23
  'use strict';
24
24
 
25
- const builder = require('./builder');
25
+ const chrome = require('./chrome');
26
+ const edge = require('./edge');
27
+ const firefox = require('./firefox');
28
+ const _http = require('./http');
29
+ const ie = require('./ie');
26
30
  const actions = require('./lib/actions');
27
31
  const by = require('./lib/by');
28
32
  const capabilities = require('./lib/capabilities');
@@ -35,21 +39,651 @@ const promise = require('./lib/promise');
35
39
  const session = require('./lib/session');
36
40
  const until = require('./lib/until');
37
41
  const webdriver = require('./lib/webdriver');
42
+ const opera = require('./opera');
43
+ const phantomjs = require('./phantomjs');
44
+ const remote = require('./remote');
45
+ const safari = require('./safari');
46
+
47
+ const Browser = capabilities.Browser;
48
+ const Capabilities = capabilities.Capabilities;
49
+ const Capability = capabilities.Capability;
50
+ const Session = session.Session;
51
+ const WebDriver = webdriver.WebDriver;
52
+
53
+
54
+
55
+ var seleniumServer;
56
+
57
+ /**
58
+ * Starts an instance of the Selenium server if not yet running.
59
+ * @param {string} jar Path to the server jar to use.
60
+ * @return {!Promise<string>} A promise for the server's
61
+ * addrss once started.
62
+ */
63
+ function startSeleniumServer(jar) {
64
+ if (!seleniumServer) {
65
+ seleniumServer = new remote.SeleniumServer(jar);
66
+ }
67
+ return seleniumServer.start();
68
+ }
69
+
70
+
71
+ /**
72
+ * {@linkplain webdriver.WebDriver#setFileDetector WebDriver's setFileDetector}
73
+ * method uses a non-standard command to transfer files from the local client
74
+ * to the remote end hosting the browser. Many of the WebDriver sub-types, like
75
+ * the {@link chrome.Driver} and {@link firefox.Driver}, do not support this
76
+ * command. Thus, these classes override the `setFileDetector` to no-op.
77
+ *
78
+ * This function uses a mixin to re-enable `setFileDetector` by calling the
79
+ * original method on the WebDriver prototype directly. This is used only when
80
+ * the builder creates a Chrome or Firefox instance that communicates with a
81
+ * remote end (and thus, support for remote file detectors is unknown).
82
+ *
83
+ * @param {function(new: webdriver.WebDriver, ...?)} ctor
84
+ * @return {function(new: webdriver.WebDriver, ...?)}
85
+ */
86
+ function ensureFileDetectorsAreEnabled(ctor) {
87
+ const mixin = class extends ctor {
88
+ /** @param {input.FileDetector} detector */
89
+ setFileDetector(detector) {
90
+ webdriver.WebDriver.prototype.setFileDetector.call(this, detector);
91
+ }
92
+ };
93
+ return mixin;
94
+ }
95
+
96
+
97
+ /**
98
+ * A thenable wrapper around a {@linkplain webdriver.IWebDriver IWebDriver}
99
+ * instance that allows commands to be issued directly instead of having to
100
+ * repeatedly call `then`:
101
+ *
102
+ * let driver = new Builder().build();
103
+ * driver.then(d => d.get(url)); // You can do this...
104
+ * driver.get(url); // ...or this
105
+ *
106
+ * If the driver instance fails to resolve (e.g. the session cannot be created),
107
+ * every issued command will fail.
108
+ *
109
+ * @extends {webdriver.IWebDriver}
110
+ * @extends {promise.CancellableThenable<!webdriver.IWebDriver>}
111
+ * @interface
112
+ */
113
+ class ThenableWebDriver {
114
+ /** @param {...?} args */
115
+ static createSession(...args) {}
116
+ }
117
+
118
+
119
+ /**
120
+ * @const {!Map<function(new: WebDriver, !IThenable<!Session>, ...?),
121
+ * function(new: ThenableWebDriver, !IThenable<!Session>, ...?)>}
122
+ */
123
+ const THENABLE_DRIVERS = new Map;
124
+
125
+
126
+ /**
127
+ * @param {function(new: WebDriver, !IThenable<!Session>, ...?)} ctor
128
+ * @param {...?} args
129
+ * @return {!ThenableWebDriver}
130
+ */
131
+ function createDriver(ctor, ...args) {
132
+ let thenableWebDriverProxy = THENABLE_DRIVERS.get(ctor);
133
+ if (!thenableWebDriverProxy) {
134
+ /** @implements {ThenableWebDriver} */
135
+ thenableWebDriverProxy = class extends ctor {
136
+ /**
137
+ * @param {!IThenable<!Session>} session
138
+ * @param {...?} rest
139
+ */
140
+ constructor(session, ...rest) {
141
+ super(session, ...rest);
142
+
143
+ const pd = this.getSession().then(session => {
144
+ return new ctor(session, ...rest);
145
+ });
146
+
147
+ /**
148
+ * @param {(string|Error)=} opt_reason
149
+ * @override
150
+ */
151
+ this.cancel = function(opt_reason) {
152
+ if (promise.CancellableThenable.isImplementation(pd)) {
153
+ /** @type {!promise.CancellableThenable} */(pd).cancel(opt_reason);
154
+ }
155
+ };
156
+
157
+ /** @override */
158
+ this.then = pd.then.bind(pd);
159
+
160
+ /** @override */
161
+ this.catch = pd.then.bind(pd);
162
+ }
163
+ }
164
+ promise.CancellableThenable.addImplementation(thenableWebDriverProxy);
165
+ THENABLE_DRIVERS.set(ctor, thenableWebDriverProxy);
166
+ }
167
+ return thenableWebDriverProxy.createSession(...args);
168
+ }
169
+
170
+
171
+ /**
172
+ * Creates new {@link webdriver.WebDriver WebDriver} instances. The environment
173
+ * variables listed below may be used to override a builder's configuration,
174
+ * allowing quick runtime changes.
175
+ *
176
+ * - {@code SELENIUM_BROWSER}: defines the target browser in the form
177
+ * {@code browser[:version][:platform]}.
178
+ *
179
+ * - {@code SELENIUM_REMOTE_URL}: defines the remote URL for all builder
180
+ * instances. This environment variable should be set to a fully qualified
181
+ * URL for a WebDriver server (e.g. http://localhost:4444/wd/hub). This
182
+ * option always takes precedence over {@code SELENIUM_SERVER_JAR}.
183
+ *
184
+ * - {@code SELENIUM_SERVER_JAR}: defines the path to the
185
+ * <a href="http://selenium-release.storage.googleapis.com/index.html">
186
+ * standalone Selenium server</a> jar to use. The server will be started the
187
+ * first time a WebDriver instance and be killed when the process exits.
188
+ *
189
+ * Suppose you had mytest.js that created WebDriver with
190
+ *
191
+ * var driver = new webdriver.Builder()
192
+ * .forBrowser('chrome')
193
+ * .build();
194
+ *
195
+ * This test could be made to use Firefox on the local machine by running with
196
+ * `SELENIUM_BROWSER=firefox node mytest.js`. Rather than change the code to
197
+ * target Google Chrome on a remote machine, you can simply set the
198
+ * `SELENIUM_BROWSER` and `SELENIUM_REMOTE_URL` environment variables:
199
+ *
200
+ * SELENIUM_BROWSER=chrome:36:LINUX \
201
+ * SELENIUM_REMOTE_URL=http://www.example.com:4444/wd/hub \
202
+ * node mytest.js
203
+ *
204
+ * You could also use a local copy of the standalone Selenium server:
205
+ *
206
+ * SELENIUM_BROWSER=chrome:36:LINUX \
207
+ * SELENIUM_SERVER_JAR=/path/to/selenium-server-standalone.jar \
208
+ * node mytest.js
209
+ */
210
+ class Builder {
211
+ constructor() {
212
+ /** @private @const */
213
+ this.log_ = logging.getLogger('webdriver.Builder');
214
+
215
+ /** @private {promise.ControlFlow} */
216
+ this.flow_ = null;
217
+
218
+ /** @private {string} */
219
+ this.url_ = '';
220
+
221
+ /** @private {?string} */
222
+ this.proxy_ = null;
223
+
224
+ /** @private {!Capabilities} */
225
+ this.capabilities_ = new Capabilities();
226
+
227
+ /** @private {chrome.Options} */
228
+ this.chromeOptions_ = null;
229
+
230
+ /** @private {firefox.Options} */
231
+ this.firefoxOptions_ = null;
232
+
233
+ /** @private {opera.Options} */
234
+ this.operaOptions_ = null;
235
+
236
+ /** @private {ie.Options} */
237
+ this.ieOptions_ = null;
238
+
239
+ /** @private {safari.Options} */
240
+ this.safariOptions_ = null;
241
+
242
+ /** @private {edge.Options} */
243
+ this.edgeOptions_ = null;
244
+
245
+ /** @private {boolean} */
246
+ this.ignoreEnv_ = false;
247
+
248
+ /** @private {http.Agent} */
249
+ this.agent_ = null;
250
+ }
251
+
252
+ /**
253
+ * Configures this builder to ignore any environment variable overrides and to
254
+ * only use the configuration specified through this instance's API.
255
+ *
256
+ * @return {!Builder} A self reference.
257
+ */
258
+ disableEnvironmentOverrides() {
259
+ this.ignoreEnv_ = true;
260
+ return this;
261
+ }
262
+
263
+ /**
264
+ * Sets the URL of a remote WebDriver server to use. Once a remote URL has
265
+ * been specified, the builder direct all new clients to that server. If this
266
+ * method is never called, the Builder will attempt to create all clients
267
+ * locally.
268
+ *
269
+ * As an alternative to this method, you may also set the
270
+ * `SELENIUM_REMOTE_URL` environment variable.
271
+ *
272
+ * @param {string} url The URL of a remote server to use.
273
+ * @return {!Builder} A self reference.
274
+ */
275
+ usingServer(url) {
276
+ this.url_ = url;
277
+ return this;
278
+ }
279
+
280
+ /**
281
+ * @return {string} The URL of the WebDriver server this instance is
282
+ * configured to use.
283
+ */
284
+ getServerUrl() {
285
+ return this.url_;
286
+ }
287
+
288
+ /**
289
+ * Sets the URL of the proxy to use for the WebDriver's HTTP connections.
290
+ * If this method is never called, the Builder will create a connection
291
+ * without a proxy.
292
+ *
293
+ * @param {string} proxy The URL of a proxy to use.
294
+ * @return {!Builder} A self reference.
295
+ */
296
+ usingWebDriverProxy(proxy) {
297
+ this.proxy_ = proxy;
298
+ return this;
299
+ }
300
+
301
+ /**
302
+ * @return {?string} The URL of the proxy server to use for the WebDriver's
303
+ * HTTP connections, or `null` if not set.
304
+ */
305
+ getWebDriverProxy() {
306
+ return this.proxy_;
307
+ }
308
+
309
+ /**
310
+ * Sets the http agent to use for each request.
311
+ * If this method is not called, the Builder will use http.globalAgent by default.
312
+ *
313
+ * @param {http.Agent} agent The agent to use for each request.
314
+ * @return {!Builder} A self reference.
315
+ */
316
+ usingHttpAgent(agent) {
317
+ this.agent_ = agent;
318
+ return this;
319
+ }
320
+
321
+ /**
322
+ * @return {http.Agent} The http agent used for each request
323
+ */
324
+ getHttpAgent() {
325
+ return this.agent_;
326
+ }
327
+
328
+ /**
329
+ * Sets the desired capabilities when requesting a new session. This will
330
+ * overwrite any previously set capabilities.
331
+ * @param {!(Object|Capabilities)} capabilities The desired capabilities for
332
+ * a new session.
333
+ * @return {!Builder} A self reference.
334
+ */
335
+ withCapabilities(capabilities) {
336
+ this.capabilities_ = new Capabilities(capabilities);
337
+ return this;
338
+ }
339
+
340
+ /**
341
+ * Returns the base set of capabilities this instance is currently configured
342
+ * to use.
343
+ * @return {!Capabilities} The current capabilities for this builder.
344
+ */
345
+ getCapabilities() {
346
+ return this.capabilities_;
347
+ }
348
+
349
+ /**
350
+ * Configures the target browser for clients created by this instance.
351
+ * Any calls to {@link #withCapabilities} after this function will
352
+ * overwrite these settings.
353
+ *
354
+ * You may also define the target browser using the {@code SELENIUM_BROWSER}
355
+ * environment variable. If set, this environment variable should be of the
356
+ * form `browser[:[version][:platform]]`.
357
+ *
358
+ * @param {(string|Browser)} name The name of the target browser;
359
+ * common defaults are available on the {@link webdriver.Browser} enum.
360
+ * @param {string=} opt_version A desired version; may be omitted if any
361
+ * version should be used.
362
+ * @param {string=} opt_platform The desired platform; may be omitted if any
363
+ * version may be used.
364
+ * @return {!Builder} A self reference.
365
+ */
366
+ forBrowser(name, opt_version, opt_platform) {
367
+ this.capabilities_.set(Capability.BROWSER_NAME, name);
368
+ this.capabilities_.set(Capability.VERSION, opt_version || null);
369
+ this.capabilities_.set(Capability.PLATFORM, opt_platform || null);
370
+ return this;
371
+ }
372
+
373
+ /**
374
+ * Sets the proxy configuration for the target browser.
375
+ * Any calls to {@link #withCapabilities} after this function will
376
+ * overwrite these settings.
377
+ *
378
+ * @param {!capabilities.ProxyConfig} config The configuration to use.
379
+ * @return {!Builder} A self reference.
380
+ */
381
+ setProxy(config) {
382
+ this.capabilities_.setProxy(config);
383
+ return this;
384
+ }
385
+
386
+ /**
387
+ * Sets the logging preferences for the created session. Preferences may be
388
+ * changed by repeated calls, or by calling {@link #withCapabilities}.
389
+ * @param {!(./lib/logging.Preferences|Object<string, string>)} prefs The
390
+ * desired logging preferences.
391
+ * @return {!Builder} A self reference.
392
+ */
393
+ setLoggingPrefs(prefs) {
394
+ this.capabilities_.setLoggingPrefs(prefs);
395
+ return this;
396
+ }
397
+
398
+ /**
399
+ * Sets whether native events should be used.
400
+ * @param {boolean} enabled Whether to enable native events.
401
+ * @return {!Builder} A self reference.
402
+ */
403
+ setEnableNativeEvents(enabled) {
404
+ this.capabilities_.setEnableNativeEvents(enabled);
405
+ return this;
406
+ }
407
+
408
+ /**
409
+ * Sets how elements should be scrolled into view for interaction.
410
+ * @param {number} behavior The desired scroll behavior: either 0 to align
411
+ * with the top of the viewport or 1 to align with the bottom.
412
+ * @return {!Builder} A self reference.
413
+ */
414
+ setScrollBehavior(behavior) {
415
+ this.capabilities_.setScrollBehavior(behavior);
416
+ return this;
417
+ }
418
+
419
+ /**
420
+ * Sets the default action to take with an unexpected alert before returning
421
+ * an error.
422
+ * @param {string} behavior The desired behavior; should be "accept",
423
+ * "dismiss", or "ignore". Defaults to "dismiss".
424
+ * @return {!Builder} A self reference.
425
+ */
426
+ setAlertBehavior(behavior) {
427
+ this.capabilities_.setAlertBehavior(behavior);
428
+ return this;
429
+ }
430
+
431
+ /**
432
+ * Sets Chrome specific {@linkplain chrome.Options options} for drivers
433
+ * created by this builder. Any logging or proxy settings defined on the given
434
+ * options will take precedence over those set through
435
+ * {@link #setLoggingPrefs} and {@link #setProxy}, respectively.
436
+ *
437
+ * @param {!chrome.Options} options The ChromeDriver options to use.
438
+ * @return {!Builder} A self reference.
439
+ */
440
+ setChromeOptions(options) {
441
+ this.chromeOptions_ = options;
442
+ return this;
443
+ }
444
+
445
+ /**
446
+ * Sets Firefox specific {@linkplain firefox.Options options} for drivers
447
+ * created by this builder. Any logging or proxy settings defined on the given
448
+ * options will take precedence over those set through
449
+ * {@link #setLoggingPrefs} and {@link #setProxy}, respectively.
450
+ *
451
+ * @param {!firefox.Options} options The FirefoxDriver options to use.
452
+ * @return {!Builder} A self reference.
453
+ */
454
+ setFirefoxOptions(options) {
455
+ this.firefoxOptions_ = options;
456
+ return this;
457
+ }
458
+
459
+ /**
460
+ * @return {firefox.Options} the Firefox specific options currently configured
461
+ * for this instance.
462
+ */
463
+ getFirefoxOptions() {
464
+ return this.firefoxOptions_;
465
+ }
466
+
467
+ /**
468
+ * Sets Opera specific {@linkplain opera.Options options} for drivers created
469
+ * by this builder. Any logging or proxy settings defined on the given options
470
+ * will take precedence over those set through {@link #setLoggingPrefs} and
471
+ * {@link #setProxy}, respectively.
472
+ *
473
+ * @param {!opera.Options} options The OperaDriver options to use.
474
+ * @return {!Builder} A self reference.
475
+ */
476
+ setOperaOptions(options) {
477
+ this.operaOptions_ = options;
478
+ return this;
479
+ }
480
+
481
+ /**
482
+ * Set Internet Explorer specific {@linkplain ie.Options options} for drivers
483
+ * created by this builder. Any proxy settings defined on the given options
484
+ * will take precedence over those set through {@link #setProxy}.
485
+ *
486
+ * @param {!ie.Options} options The IEDriver options to use.
487
+ * @return {!Builder} A self reference.
488
+ */
489
+ setIeOptions(options) {
490
+ this.ieOptions_ = options;
491
+ return this;
492
+ }
493
+
494
+ /**
495
+ * Set {@linkplain edge.Options options} specific to Microsoft's Edge browser
496
+ * for drivers created by this builder. Any proxy settings defined on the
497
+ * given options will take precedence over those set through
498
+ * {@link #setProxy}.
499
+ *
500
+ * @param {!edge.Options} options The MicrosoftEdgeDriver options to use.
501
+ * @return {!Builder} A self reference.
502
+ */
503
+ setEdgeOptions(options) {
504
+ this.edgeOptions_ = options;
505
+ return this;
506
+ }
507
+
508
+ /**
509
+ * Sets Safari specific {@linkplain safari.Options options} for drivers
510
+ * created by this builder. Any logging settings defined on the given options
511
+ * will take precedence over those set through {@link #setLoggingPrefs}.
512
+ *
513
+ * @param {!safari.Options} options The Safari options to use.
514
+ * @return {!Builder} A self reference.
515
+ */
516
+ setSafariOptions(options) {
517
+ this.safariOptions_ = options;
518
+ return this;
519
+ }
520
+
521
+ /**
522
+ * @return {safari.Options} the Safari specific options currently configured
523
+ * for this instance.
524
+ */
525
+ getSafariOptions() {
526
+ return this.safariOptions_;
527
+ }
528
+
529
+ /**
530
+ * Sets the control flow that created drivers should execute actions in. If
531
+ * the flow is never set, or is set to {@code null}, it will use the active
532
+ * flow at the time {@link #build()} is called.
533
+ * @param {promise.ControlFlow} flow The control flow to use, or
534
+ * {@code null} to
535
+ * @return {!Builder} A self reference.
536
+ */
537
+ setControlFlow(flow) {
538
+ this.flow_ = flow;
539
+ return this;
540
+ }
541
+
542
+ /**
543
+ * Creates a new WebDriver client based on this builder's current
544
+ * configuration.
545
+ *
546
+ * This method will return a {@linkplain ThenableWebDriver} instance, allowing
547
+ * users to issue commands directly without calling `then()`. The returned
548
+ * thenable wraps a promise that will resolve to a concrete
549
+ * {@linkplain webdriver.WebDriver WebDriver} instance. The promise will be
550
+ * rejected if the remote end fails to create a new session.
551
+ *
552
+ * @return {!ThenableWebDriver} A new WebDriver instance.
553
+ * @throws {Error} If the current configuration is invalid.
554
+ */
555
+ build() {
556
+ // Create a copy for any changes we may need to make based on the current
557
+ // environment.
558
+ var capabilities = new Capabilities(this.capabilities_);
559
+
560
+ var browser;
561
+ if (!this.ignoreEnv_ && process.env.SELENIUM_BROWSER) {
562
+ this.log_.fine(`SELENIUM_BROWSER=${process.env.SELENIUM_BROWSER}`);
563
+ browser = process.env.SELENIUM_BROWSER.split(/:/, 3);
564
+ capabilities.set(Capability.BROWSER_NAME, browser[0]);
565
+ capabilities.set(Capability.VERSION, browser[1] || null);
566
+ capabilities.set(Capability.PLATFORM, browser[2] || null);
567
+ }
568
+
569
+ browser = capabilities.get(Capability.BROWSER_NAME);
570
+
571
+ if (typeof browser !== 'string') {
572
+ throw TypeError(
573
+ `Target browser must be a string, but is <${typeof browser}>;` +
574
+ ' did you forget to call forBrowser()?');
575
+ }
576
+
577
+ if (browser === 'ie') {
578
+ browser = Browser.INTERNET_EXPLORER;
579
+ }
580
+
581
+ // Apply browser specific overrides.
582
+ if (browser === Browser.CHROME && this.chromeOptions_) {
583
+ capabilities.merge(this.chromeOptions_.toCapabilities());
584
+
585
+ } else if (browser === Browser.FIREFOX && this.firefoxOptions_) {
586
+ capabilities.merge(this.firefoxOptions_.toCapabilities());
587
+
588
+ } else if (browser === Browser.INTERNET_EXPLORER && this.ieOptions_) {
589
+ capabilities.merge(this.ieOptions_.toCapabilities());
590
+
591
+ } else if (browser === Browser.OPERA && this.operaOptions_) {
592
+ capabilities.merge(this.operaOptions_.toCapabilities());
593
+
594
+ } else if (browser === Browser.SAFARI && this.safariOptions_) {
595
+ capabilities.merge(this.safariOptions_.toCapabilities());
596
+
597
+ } else if (browser === Browser.EDGE && this.edgeOptions_) {
598
+ capabilities.merge(this.edgeOptions_.toCapabilities());
599
+ }
600
+
601
+ // Check for a remote browser.
602
+ let url = this.url_;
603
+ if (!this.ignoreEnv_) {
604
+ if (process.env.SELENIUM_REMOTE_URL) {
605
+ this.log_.fine(
606
+ `SELENIUM_REMOTE_URL=${process.env.SELENIUM_REMOTE_URL}`);
607
+ url = process.env.SELENIUM_REMOTE_URL;
608
+ } else if (process.env.SELENIUM_SERVER_JAR) {
609
+ this.log_.fine(
610
+ `SELENIUM_SERVER_JAR=${process.env.SELENIUM_SERVER_JAR}`);
611
+ url = startSeleniumServer(process.env.SELENIUM_SERVER_JAR);
612
+ }
613
+ }
614
+
615
+ if (url) {
616
+ this.log_.fine('Creating session on remote server');
617
+ let client = Promise.resolve(url)
618
+ .then(url => new _http.HttpClient(url, this.agent_, this.proxy_));
619
+ let executor = new _http.Executor(client);
620
+
621
+ if (browser === Browser.CHROME) {
622
+ const driver = ensureFileDetectorsAreEnabled(chrome.Driver);
623
+ return createDriver(
624
+ driver, capabilities, executor, this.flow_);
625
+ }
626
+
627
+ if (browser === Browser.FIREFOX) {
628
+ const driver = ensureFileDetectorsAreEnabled(firefox.Driver);
629
+ return createDriver(
630
+ driver, capabilities, executor, this.flow_);
631
+ }
632
+ return createDriver(
633
+ WebDriver, executor, capabilities, this.flow_);
634
+ }
635
+
636
+ // Check for a native browser.
637
+ switch (browser) {
638
+ case Browser.CHROME:
639
+ return createDriver(chrome.Driver, capabilities, null, this.flow_);
640
+
641
+ case Browser.FIREFOX:
642
+ return createDriver(firefox.Driver, capabilities, null, this.flow_);
643
+
644
+ case Browser.INTERNET_EXPLORER:
645
+ return createDriver(ie.Driver, capabilities, this.flow_);
646
+
647
+ case Browser.EDGE:
648
+ return createDriver(edge.Driver, capabilities, null, this.flow_);
649
+
650
+ case Browser.OPERA:
651
+ return createDriver(opera.Driver, capabilities, null, this.flow_);
652
+
653
+ case Browser.PHANTOM_JS:
654
+ return createDriver(phantomjs.Driver, capabilities, this.flow_);
655
+
656
+ case Browser.SAFARI:
657
+ return createDriver(safari.Driver, capabilities, this.flow_);
658
+
659
+ default:
660
+ throw new Error('Do not know how to build driver: ' + browser
661
+ + '; did you forget to call usingServer(url)?');
662
+ }
663
+ }
664
+ }
665
+
666
+
667
+ // PUBLIC API
38
668
 
39
669
 
40
670
  exports.ActionSequence = actions.ActionSequence;
41
671
  exports.Browser = capabilities.Browser;
42
- exports.Builder = builder.Builder;
672
+ exports.Builder = Builder;
43
673
  exports.Button = input.Button;
44
674
  exports.By = by.By;
45
675
  exports.Capabilities = capabilities.Capabilities;
46
676
  exports.Capability = capabilities.Capability;
677
+ exports.Condition = webdriver.Condition;
47
678
  exports.EventEmitter = events.EventEmitter;
48
679
  exports.FileDetector = input.FileDetector;
49
680
  exports.Key = input.Key;
50
681
  exports.Session = session.Session;
682
+ exports.ThenableWebDriver = ThenableWebDriver;
683
+ exports.TouchSequence = actions.TouchSequence;
51
684
  exports.WebDriver = webdriver.WebDriver;
52
685
  exports.WebElement = webdriver.WebElement;
686
+ exports.WebElementCondition = webdriver.WebElementCondition;
53
687
  exports.WebElementPromise = webdriver.WebElementPromise;
54
688
  exports.error = error;
55
689
  exports.logging = logging;