fix(webdriverio): fix initializing session manager after attaching to new session (#14183)

* fix(webdriverio): fix initializing session manager after attaching to new session

* fix test
This commit is contained in:
Christian Bromann 2025-02-14 09:48:18 -08:00 committed by GitHub
parent 9c98ae9775
commit 20b23fe8d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 2 deletions

View file

@ -38,6 +38,12 @@ test('allow to attach to an existing session', async () => {
const newContextTree = await otherBrowser.browsingContextGetTree({ maxDepth: 1 })
expect(origContextTree.contexts[0].context).toBe(newContextTree.contexts[0].context)
/**
* can open other pages which requires e.g. network manager to be reinitialized correctly
*/
await otherBrowser.url('https://guinea-pig.webdriver.io/two.html')
expect(await otherBrowser.getTitle()).toBe('two')
await otherBrowser.deleteSession()
/**

View file

@ -3,7 +3,7 @@ import logger from '@wdio/logger'
import WebDriver, { DEFAULTS } from 'webdriver'
import { validateConfig } from '@wdio/config'
import { enableFileLogging, wrapCommand } from '@wdio/utils'
import { enableFileLogging, wrapCommand, isBidi } from '@wdio/utils'
import type { Options, Capabilities } from '@wdio/types'
import type * as WebDriverTypes from 'webdriver'
@ -104,8 +104,14 @@ export const attach = async function (attachOptions: AttachOptions): Promise<Web
prototype,
wrapCommand
) as WebdriverIO.Browser
driver.addLocatorStrategy = addLocatorStrategyHandler(driver)
/**
* Wait for the Bidi handler to be connected before registering the session manager
*/
if (isBidi(driver.capabilities) && '_bidiHandler' in driver) {
await (driver['_bidiHandler'] as WebDriverTypes.BidiHandler).waitForConnected()
}
await registerSessionManager(driver)
return driver
}