* Creates a new WebDriver client based on this builder's current * configuration. * * This method will return a plain ThenableWebDriver instance, allowing * users to issue commands directly without calling `then()`. The returned * thenable wraps a promise that will resolve to a
()
| 582 | * @throws {Error} If the current configuration is invalid. |
| 583 | */ |
| 584 | build() { |
| 585 | // Create a copy for any changes we may need to make based on the current |
| 586 | // environment. |
| 587 | const capabilities = new Capabilities(this.capabilities_) |
| 588 | |
| 589 | let browser |
| 590 | if (!this.ignoreEnv_ && process.env.SELENIUM_BROWSER) { |
| 591 | this.log_.fine(`SELENIUM_BROWSER=${process.env.SELENIUM_BROWSER}`) |
| 592 | browser = process.env.SELENIUM_BROWSER.split(/:/, 3) |
| 593 | capabilities.setBrowserName(browser[0]) |
| 594 | |
| 595 | browser[1] && capabilities.setBrowserVersion(browser[1]) |
| 596 | browser[2] && capabilities.setPlatform(browser[2]) |
| 597 | } |
| 598 | |
| 599 | browser = capabilities.get(Capability.BROWSER_NAME) |
| 600 | |
| 601 | /** |
| 602 | * If browser is not defined in forBrowser, check if browserOptions are defined to pick the browserName |
| 603 | */ |
| 604 | if (!browser) { |
| 605 | const options = |
| 606 | this.chromeOptions_ || this.firefoxOptions_ || this.ieOptions_ || this.safariOptions_ || this.edgeOptions_ |
| 607 | if (options) { |
| 608 | browser = options['map_'].get(Capability.BROWSER_NAME) |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | if (typeof browser !== 'string') { |
| 613 | throw TypeError( |
| 614 | `Target browser must be a string, but is <${typeof browser}>;` + ' did you forget to call forBrowser()?', |
| 615 | ) |
| 616 | } |
| 617 | |
| 618 | if (browser === 'ie') { |
| 619 | browser = Browser.INTERNET_EXPLORER |
| 620 | } |
| 621 | |
| 622 | // Apply browser specific overrides. |
| 623 | if (browser === Browser.CHROME && this.chromeOptions_) { |
| 624 | capabilities.merge(this.chromeOptions_) |
| 625 | } else if (browser === Browser.FIREFOX && this.firefoxOptions_) { |
| 626 | capabilities.merge(this.firefoxOptions_) |
| 627 | } else if (browser === Browser.INTERNET_EXPLORER && this.ieOptions_) { |
| 628 | capabilities.merge(this.ieOptions_) |
| 629 | } else if (browser === Browser.SAFARI && this.safariOptions_) { |
| 630 | capabilities.merge(this.safariOptions_) |
| 631 | } else if (browser === Browser.EDGE && this.edgeOptions_) { |
| 632 | capabilities.merge(this.edgeOptions_) |
| 633 | } |
| 634 | |
| 635 | checkOptions(capabilities, 'chromeOptions', chrome.Options, 'setChromeOptions') |
| 636 | checkOptions(capabilities, 'moz:firefoxOptions', firefox.Options, 'setFirefoxOptions') |
| 637 | checkOptions(capabilities, 'safari.options', safari.Options, 'setSafariOptions') |
| 638 | |
| 639 | // Check for a remote browser. |
| 640 | let url = this.url_ |
| 641 | if (!this.ignoreEnv_) { |
no test coverage detected