MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / build

Method build

javascript/selenium-webdriver/index.js:592–721  ·  view source on GitHub ↗

* 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

()

Source from the content-addressed store, hash-verified

590 * @throws {Error} If the current configuration is invalid.
591 */
592 build() {
593 // Create a copy for any changes we may need to make based on the current
594 // environment.
595 const capabilities = new Capabilities(this.capabilities_)
596
597 let browser
598 if (!this.ignoreEnv_ && process.env.SELENIUM_BROWSER) {
599 this.log_.fine(`SELENIUM_BROWSER=${process.env.SELENIUM_BROWSER}`)
600 browser = process.env.SELENIUM_BROWSER.split(/:/, 3)
601 capabilities.setBrowserName(browser[0])
602
603 browser[1] && capabilities.setBrowserVersion(browser[1])
604 browser[2] && capabilities.setPlatform(browser[2])
605 }
606
607 browser = capabilities.get(Capability.BROWSER_NAME)
608
609 /**
610 * If browser is not defined in forBrowser, check if browserOptions are defined to pick the browserName
611 */
612 if (!browser) {
613 const options =
614 this.chromeOptions_ || this.firefoxOptions_ || this.ieOptions_ || this.safariOptions_ || this.edgeOptions_
615 if (options) {
616 browser = options['map_'].get(Capability.BROWSER_NAME)
617 }
618 }
619
620 if (typeof browser !== 'string') {
621 throw TypeError(
622 `Target browser must be a string, but is <${typeof browser}>;` + ' did you forget to call forBrowser()?',
623 )
624 }
625
626 if (browser === 'ie') {
627 browser = Browser.INTERNET_EXPLORER
628 }
629
630 // Apply browser specific overrides.
631 if (browser === Browser.CHROME && this.chromeOptions_) {
632 capabilities.merge(this.chromeOptions_)
633 } else if (browser === Browser.FIREFOX && this.firefoxOptions_) {
634 capabilities.merge(this.firefoxOptions_)
635 } else if (browser === Browser.INTERNET_EXPLORER && this.ieOptions_) {
636 capabilities.merge(this.ieOptions_)
637 } else if (browser === Browser.SAFARI && this.safariOptions_) {
638 capabilities.merge(this.safariOptions_)
639 } else if (browser === Browser.EDGE && this.edgeOptions_) {
640 capabilities.merge(this.edgeOptions_)
641 }
642
643 checkOptions(capabilities, 'chromeOptions', chrome.Options, 'setChromeOptions')
644 checkOptions(capabilities, 'moz:firefoxOptions', firefox.Options, 'setFirefoxOptions')
645 checkOptions(capabilities, 'safari.options', safari.Options, 'setSafariOptions')
646
647 // Check for a remote browser.
648 let url = this.url_
649 if (!this.ignoreEnv_) {

Callers

nothing calls this directly

Calls 15

setBrowserNameMethod · 0.95
setBrowserVersionMethod · 0.95
setPlatformMethod · 0.95
getMethod · 0.95
mergeMethod · 0.95
setMethod · 0.95
checkOptionsFunction · 0.85
startSeleniumServerFunction · 0.85
fineMethod · 0.80
splitMethod · 0.80
resolveMethod · 0.80

Tested by

no test coverage detected