Skip to content

Commit 58ded52

Browse files
smildlzjtoddtarsi
authored andcommitted
fix:waitForNewWindow with timeout
1 parent 74d563f commit 58ded52

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

packages/selenium-ide/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
"@seleniumhq/side-api": "^4.0.0-alpha.16",
111111
"@seleniumhq/side-model": "^4.0.0-alpha.2",
112112
"@seleniumhq/side-plugin-example": "^4.0.0-alpha.1",
113-
"@seleniumhq/side-runtime": "^4.0.0-alpha.16",
113+
"@seleniumhq/side-runtime": "^4.0.0-alpha.17",
114114
"dnd-core": "16.0.1",
115115
"electron-chromedriver": "^18.0.0",
116116
"electron-log": "^4.4.8",

packages/side-runtime/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@seleniumhq/side-runtime",
3-
"version": "4.0.0-alpha.16",
3+
"version": "4.0.0-alpha.17",
44
"description": "Selenium IDE playback and execution",
55
"author": "Tomer <[email protected]>",
66
"homepage": "http://github.com/SeleniumHQ/selenium-ide",

packages/side-runtime/src/webdriver.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,7 @@ export default class WebDriverExecutor {
257257
async afterCommand(commandObject: CommandShape) {
258258
this.cancellable = undefined
259259
if (commandObject.opensWindow) {
260-
const handle = await this.wait<string | undefined>(
261-
this.waitForNewWindow(),
262-
commandObject.windowTimeout
263-
)
260+
const handle = await this.waitForNewWindow(commandObject.windowTimeout)
264261
this.variables.set(commandObject.windowHandleName as string, handle)
265262

266263
await this.executeHook('onWindowAppeared', {
@@ -273,11 +270,31 @@ export default class WebDriverExecutor {
273270
await this.executeHook('onAfterCommand', { command: commandObject })
274271
}
275272

276-
async waitForNewWindow() {
277-
const currentHandles = await this.driver.getAllWindowHandles()
278-
return currentHandles.find(
279-
(handle) => !this[state].openedWindows.includes(handle)
280-
)
273+
async waitForNewWindow(timeout: number = 2000) {
274+
const finder = new Promise<string | undefined>((resolve) => {
275+
const start = Date.now()
276+
const findHandle = async () => {
277+
if (Date.now() - start > timeout) {
278+
resolve(undefined)
279+
return
280+
}
281+
282+
const currentHandles = await this.driver.getAllWindowHandles()
283+
const newHandle = currentHandles.find(
284+
(handle) => !this[state].openedWindows.includes(handle)
285+
)
286+
if (newHandle) {
287+
resolve(newHandle)
288+
return
289+
}
290+
// cant find, wait next time.
291+
setTimeout(findHandle, 200)
292+
}
293+
294+
findHandle()
295+
})
296+
297+
return this.wait(finder, timeout)
281298
}
282299

283300
registerCommand(commandName: string, fn: Fn) {

pnpm-lock.yaml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)