Appearance
Function: retry()
ts
function retry<T>(
ctx: Context,
fn: () => Promise<T>,
options?: RetryOptions): Promise<T>;Defined in: src/utils/retry.ts:50
Run a function and retry it on exception.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
ctx | Context | The context for automation. |
fn | () => Promise<T> | A function to retry on exception. |
options? | RetryOptions | Options for retry behavior. |
Returns
Promise<T>
The return value of the function.
Remarks
Run a function and retry it on exception up to maxTries times. After that limit, reject with the last thrown exception. Otherwise return the original result.
Include both the action and its success condition in the retry function. For example, check that a selector appears or that the response has no errors. Throw anywhere inside the function to trigger a retry.
This makes operations more resilient. Use it for clicking unresponsive UIs, calling unstable APIs, or retrying entire transactions.
Examples
ts
await retry(ctx, async () => {
await click(ctx, '.button');
await waitForSelector(ctx, '.success.notification', {timeout: 3000});
});ts
const value = await retry(ctx, async () => {
await click(ctx, '.button');
return getValue(ctx, '.result');
}, {
maxTries: 3,
retryDelay: 500,
});