Skip to content

Commit

Permalink
improve retry logic
Browse files Browse the repository at this point in the history
  • Loading branch information
toddtarsi committed Jan 29, 2024
1 parent 8ea9d37 commit ad953e9
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/selenium-ide/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "selenium-ide",
"version": "4.0.1-alpha.91",
"version": "4.0.1-alpha.93",
"private": false,
"description": "Selenium IDE electron app",
"author": "Todd <[email protected]>",
Expand Down Expand Up @@ -124,7 +124,7 @@
"@seleniumhq/side-api": "^4.0.0-alpha.46",
"@seleniumhq/side-commons": "^4.0.0-alpha.2",
"@seleniumhq/side-model": "^4.0.0-alpha.5",
"@seleniumhq/side-runtime": "^4.0.0-alpha.38",
"@seleniumhq/side-runtime": "^4.0.0-alpha.39",
"dnd-core": "^16.0.1",
"electron-chromedriver": "^28.0.0",
"electron-log": "^5.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/side-runner/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "selenium-side-runner",
"version": "4.0.0-alpha.66",
"version": "4.0.0-alpha.67",
"private": false,
"description": "Run Selenium IDE projects in cli",
"repository": "https://github.com/SeleniumHQ/selenium-ide",
Expand All @@ -24,7 +24,7 @@
"license": "Apache-2.0",
"dependencies": {
"@seleniumhq/side-model": "^4.0.0-alpha.5",
"@seleniumhq/side-runtime": "^4.0.0-alpha.38",
"@seleniumhq/side-runtime": "^4.0.0-alpha.39",
"commander": "^11.0.0",
"glob": "^10.3.1",
"jest": "^29.6.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/side-runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@seleniumhq/side-runtime",
"version": "4.0.0-alpha.38",
"version": "4.0.0-alpha.39",
"private": false,
"description": "Selenium IDE playback and execution",
"author": "Tomer <[email protected]>",
Expand Down
49 changes: 44 additions & 5 deletions packages/side-runtime/src/playback-tree/command-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,59 @@ export class CommandNode {
? () => customCommand.execute(command, commandExecutor)
: // @ts-expect-error webdriver is too kludged by here
() => commandExecutor[existingCommandName](target, value, command)
try {
const cmdList = [
'click',
'check',
'select',
'type',
'sendKeys',
'uncheck',
]
const ignoreRetry = !cmdList.includes(commandName)
if (ignoreRetry) {
return executor()
} catch (e) {
const err = e as Error
err.message += ` (cmd: ${commandName}|${target}|${value})`
throw err
}
return this.retryCommand(
executor,
Date.now() + commandExecutor.implicitWait
)
}
}

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

retryCommand(
execute: () => Promise<unknown>,
timeout: number
): Promise<unknown> {
return new Promise((res, rej) => {
const timeLimit = timeout - Date.now()
const expirationTimer = setTimeout(() => {
rej(
new Error(
`Operation timed out running command ${this.command.command}:${this.command.target}:${this.command.value}`
)
)
}, timeLimit)
execute()
.catch((e) => {
clearTimeout(expirationTimer)
try {
this.handleTransientError(e, timeout)
this.retryCommand(execute, timeout)
} catch (e) {
rej(e)
}
})
.then((result) => {
clearTimeout(expirationTimer)
res(result)
})
})
}

_executionResult(result: CommandExecutionResult = {}) {
this._incrementTimesVisited()
return {
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ad953e9

Please sign in to comment.