MCPcopy Create free account
hub / github.com/webdriverio/webdriverio / startWebDriverSession

Function startWebDriverSession

packages/webdriver/src/utils.ts:60–174  ·  view source on GitHub ↗
(params: RemoteConfig)

Source from the content-addressed store, hash-verified

58 * start browser session with WebDriver protocol
59 */
60export async function startWebDriverSession (params: RemoteConfig): Promise<{ sessionId: string, capabilities: WebdriverIO.Capabilities }> {
61 /**
62 * the user could have passed in either w3c style or jsonwp style caps
63 * and we want to pass both styles to the server, which means we need
64 * to check what style the user sent in so we know how to construct the
65 * object for the other style
66 */
67 const capabilities = params.capabilities && 'alwaysMatch' in params.capabilities
68 /**
69 * in case W3C compliant capabilities are provided
70 */
71 ? params.capabilities
72 /**
73 * otherwise assume they passed in jsonwp-style caps (flat object)
74 */
75 : { alwaysMatch: params.capabilities, firstMatch: [{}] }
76
77 /**
78 * automatically opt-into WebDriver Bidi (@ref https://w3c.github.io/webdriver-bidi/)
79 */
80 if (
81 /**
82 * except, if user does not want to opt-in
83 */
84 !capabilities.alwaysMatch['wdio:enforceWebDriverClassic'] &&
85 /**
86 * or user requests a Safari session which does not support Bidi
87 */
88 typeof capabilities.alwaysMatch.browserName === 'string' &&
89 capabilities.alwaysMatch.browserName.toLowerCase() !== 'safari'
90 ) {
91 /**
92 * opt-into WebDriver Bidi
93 */
94 capabilities.alwaysMatch.webSocketUrl = true
95 /**
96 * allow WebdriverIO to handle alerts
97 */
98 capabilities.alwaysMatch.unhandledPromptBehavior = 'ignore'
99 }
100
101 validateCapabilities(capabilities.alwaysMatch)
102
103 /**
104 * remove overlapping keys in firstMatch that are already defined in alwaysMatch
105 * to avoid errors in Selenium Grid
106 */
107 const keysToNormalize = new Set(Object.keys(capabilities.alwaysMatch))
108 if (capabilities.firstMatch) {
109 capabilities.firstMatch.forEach((match) => {
110 Object.keys(match).forEach((key) => keysToNormalize.add(key))
111 })
112
113 for (const key of keysToNormalize) {
114 const alwaysVal = (capabilities.alwaysMatch as Record<string, unknown>)[key]
115
116 /**
117 * if the key is not in alwaysMatch, we don't need to do anything

Callers 3

newSessionMethod · 0.85
reloadSessionMethod · 0.85
utils.test.tsFile · 0.85

Calls 5

validateCapabilitiesFunction · 0.85
deepEqualFunction · 0.85
getSessionErrorFunction · 0.85
addMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…