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

Method build

javascript/selenium-webdriver/index.js:601–730  ·  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

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

Tested by

no test coverage detected