|
22 | 22 |
|
23 | 23 | 'use strict';
|
24 | 24 |
|
25 |
| -const chrome = require('./chrome'); |
26 |
| -const edge = require('./edge'); |
27 |
| -const firefox = require('./firefox'); |
28 | 25 | const _http = require('./http');
|
29 |
| -const ie = require('./ie'); |
30 | 26 | const by = require('./lib/by');
|
31 | 27 | const capabilities = require('./lib/capabilities');
|
| 28 | +const chrome = require('./chrome'); |
32 | 29 | const command = require('./lib/command');
|
| 30 | +const edge = require('./edge'); |
33 | 31 | const error = require('./lib/error');
|
| 32 | +const firefox = require('./firefox'); |
| 33 | +const ie = require('./ie'); |
34 | 34 | const input = require('./lib/input');
|
35 | 35 | const logging = require('./lib/logging');
|
36 | 36 | const promise = require('./lib/promise');
|
| 37 | +const remote = require('./remote'); |
| 38 | +const safari = require('./safari'); |
37 | 39 | const session = require('./lib/session');
|
38 | 40 | const until = require('./lib/until');
|
39 | 41 | const webdriver = require('./lib/webdriver');
|
40 |
| -const remote = require('./remote'); |
41 |
| -const safari = require('./safari'); |
42 | 42 |
|
43 | 43 | const Browser = capabilities.Browser;
|
44 | 44 | const Capabilities = capabilities.Capabilities;
|
@@ -597,6 +597,14 @@ class Builder {
|
597 | 597 | capabilities.merge(this.edgeOptions_);
|
598 | 598 | }
|
599 | 599 |
|
| 600 | + checkOptions( |
| 601 | + capabilities, 'chromeOptions', chrome.Options, 'setChromeOptions'); |
| 602 | + checkOptions( |
| 603 | + capabilities, 'moz:firefoxOptions', firefox.Options, |
| 604 | + 'setFirefoxOptions'); |
| 605 | + checkOptions( |
| 606 | + capabilities, 'safari.options', safari.Options, 'setSafariOptions'); |
| 607 | + |
600 | 608 | // Check for a remote browser.
|
601 | 609 | let url = this.url_;
|
602 | 610 | if (!this.ignoreEnv_) {
|
@@ -669,6 +677,63 @@ class Builder {
|
669 | 677 | }
|
670 | 678 |
|
671 | 679 |
|
| 680 | +/** |
| 681 | + * In the 3.x releases, the various browser option classes |
| 682 | + * (e.g. firefox.Options) had to be manually set as an option using the |
| 683 | + * Capabilties class: |
| 684 | + * |
| 685 | + * let ffo = new firefox.Options(); |
| 686 | + * // Configure firefox options... |
| 687 | + * |
| 688 | + * let caps = new Capabilities(); |
| 689 | + * caps.set('moz:firefoxOptions', ffo); |
| 690 | + * |
| 691 | + * let driver = new Builder() |
| 692 | + * .withCapabilities(caps) |
| 693 | + * .build(); |
| 694 | + * |
| 695 | + * The options are now subclasses of Capabilities and can be used directly. A |
| 696 | + * direct translation of the above is: |
| 697 | + * |
| 698 | + * let ffo = new firefox.Options(); |
| 699 | + * // Configure firefox options... |
| 700 | + * |
| 701 | + * let driver = new Builder() |
| 702 | + * .withCapabilities(ffo) |
| 703 | + * .build(); |
| 704 | + * |
| 705 | + * You can also set the options for various browsers at once and let the builder |
| 706 | + * choose the correct set at runtime (see Builder docs above): |
| 707 | + * |
| 708 | + * let ffo = new firefox.Options(); |
| 709 | + * // Configure ... |
| 710 | + * |
| 711 | + * let co = new chrome.Options(); |
| 712 | + * // Configure ... |
| 713 | + * |
| 714 | + * let driver = new Builder() |
| 715 | + * .setChromeOptions(co) |
| 716 | + * .setFirefoxOptions(ffo) |
| 717 | + * .build(); |
| 718 | + * |
| 719 | + * @param {!Capabilities} caps |
| 720 | + * @param {string} key |
| 721 | + * @param {function(new: Capabilities)} optionType |
| 722 | + * @param {string} setMethod |
| 723 | + * @throws {error.InvalidArgumentError} |
| 724 | + */ |
| 725 | +function checkOptions(caps, key, optionType, setMethod) { |
| 726 | + let val = caps.get(key); |
| 727 | + if (val instanceof optionType) { |
| 728 | + throw new error.InvalidArgumentError( |
| 729 | + 'Options class extends Capabilities and should not be set as key ' |
| 730 | + + `"${key}"; set browser-specific options with ` |
| 731 | + + `Builder.${setMethod}(). For more information, see the ` |
| 732 | + + 'documentation attached to the function that threw this error'); |
| 733 | + } |
| 734 | +} |
| 735 | + |
| 736 | + |
672 | 737 | // PUBLIC API
|
673 | 738 |
|
674 | 739 |
|
|
0 commit comments