Function retry

  • Runs a function and retries it on exception.

    Type Parameters

    • T

    Parameters

    • ctx: Context

      The context for automation.

    • fn: (() => Promise<T>)

      A function that should be retried on exception.

        • (): Promise<T>
        • Returns Promise<T>

    • Optional options: RetryOptions

      Options for retry.

    Returns Promise<T>

    The return value of the function.

    Remarks

    Runs a function and retries it on exception up to maxTries times, after which it will reject with the last thrown exception, and otherwise return the original result.

    Most often, the retry function should contain not only the action that can fail, but also its success condition (eg. a particular selector appears, or the response does not contain errors) which checks if the action should be repeated. To cause a retry, simply throw anywhere from the retry function.

    This makes certain operations more resilient, like clicking on unresponsive user interfaces, making navigation or API requests to unstable systems, or retrying entire transactions.

    Example

    await retry(ctx, async () => {
    await click(ctx, '.button');
    await waitForSelector(ctx, '.success.notification', {timeout: 3000});
    });

    Example

    const value = await retry(ctx, async () => {
    await click(ctx, '.button');
    return getValue(ctx, '.result');
    }, {
    maxTries: 3,
    retryDelay: 500,
    });

Generated using TypeDoc