Skip to content

Commit ad953e9

Browse files
committed
improve retry logic
1 parent 8ea9d37 commit ad953e9

File tree

5 files changed

+54
-15
lines changed

5 files changed

+54
-15
lines changed

packages/selenium-ide/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "selenium-ide",
3-
"version": "4.0.1-alpha.91",
3+
"version": "4.0.1-alpha.93",
44
"private": false,
55
"description": "Selenium IDE electron app",
66
"author": "Todd <[email protected]>",
@@ -124,7 +124,7 @@
124124
"@seleniumhq/side-api": "^4.0.0-alpha.46",
125125
"@seleniumhq/side-commons": "^4.0.0-alpha.2",
126126
"@seleniumhq/side-model": "^4.0.0-alpha.5",
127-
"@seleniumhq/side-runtime": "^4.0.0-alpha.38",
127+
"@seleniumhq/side-runtime": "^4.0.0-alpha.39",
128128
"dnd-core": "^16.0.1",
129129
"electron-chromedriver": "^28.0.0",
130130
"electron-log": "^5.1.0",

packages/side-runner/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "selenium-side-runner",
3-
"version": "4.0.0-alpha.66",
3+
"version": "4.0.0-alpha.67",
44
"private": false,
55
"description": "Run Selenium IDE projects in cli",
66
"repository": "https://github.com/SeleniumHQ/selenium-ide",
@@ -24,7 +24,7 @@
2424
"license": "Apache-2.0",
2525
"dependencies": {
2626
"@seleniumhq/side-model": "^4.0.0-alpha.5",
27-
"@seleniumhq/side-runtime": "^4.0.0-alpha.38",
27+
"@seleniumhq/side-runtime": "^4.0.0-alpha.39",
2828
"commander": "^11.0.0",
2929
"glob": "^10.3.1",
3030
"jest": "^29.6.0",

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.38",
3+
"version": "4.0.0-alpha.39",
44
"private": false,
55
"description": "Selenium IDE playback and execution",
66
"author": "Tomer <[email protected]>",

packages/side-runtime/src/playback-tree/command-node.ts

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,59 @@ export class CommandNode {
127127
? () => customCommand.execute(command, commandExecutor)
128128
: // @ts-expect-error webdriver is too kludged by here
129129
() => commandExecutor[existingCommandName](target, value, command)
130-
try {
130+
const cmdList = [
131+
'click',
132+
'check',
133+
'select',
134+
'type',
135+
'sendKeys',
136+
'uncheck',
137+
]
138+
const ignoreRetry = !cmdList.includes(commandName)
139+
if (ignoreRetry) {
131140
return executor()
132-
} catch (e) {
133-
const err = e as Error
134-
err.message += ` (cmd: ${commandName}|${target}|${value})`
135-
throw err
136141
}
142+
return this.retryCommand(
143+
executor,
144+
Date.now() + commandExecutor.implicitWait
145+
)
137146
}
138147
}
139148

140149
async pauseTimeout(timeout?: number): Promise<void> {
141150
return new Promise((resolve) => setTimeout(resolve, timeout))
142151
}
143152

153+
retryCommand(
154+
execute: () => Promise<unknown>,
155+
timeout: number
156+
): Promise<unknown> {
157+
return new Promise((res, rej) => {
158+
const timeLimit = timeout - Date.now()
159+
const expirationTimer = setTimeout(() => {
160+
rej(
161+
new Error(
162+
`Operation timed out running command ${this.command.command}:${this.command.target}:${this.command.value}`
163+
)
164+
)
165+
}, timeLimit)
166+
execute()
167+
.catch((e) => {
168+
clearTimeout(expirationTimer)
169+
try {
170+
this.handleTransientError(e, timeout)
171+
this.retryCommand(execute, timeout)
172+
} catch (e) {
173+
rej(e)
174+
}
175+
})
176+
.then((result) => {
177+
clearTimeout(expirationTimer)
178+
res(result)
179+
})
180+
})
181+
}
182+
144183
_executionResult(result: CommandExecutionResult = {}) {
145184
this._incrementTimesVisited()
146185
return {

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)