How to handle task failures in Robot Framework RPA robots
What should I do if my task fails occasionally?
You may run into situations where a task will occasionally complete in the expected amount of time, or certain parts of it take longer and could potentially cause the run to fail. For example, a web page may load up in less than half a second sometimes or up to three seconds other times. Luckily Robot Framework has options for creating retry logic to make task runs less brittle. These options are found in the BuiltIn library that is already installed with it.
Wait Until Keyword Succeeds
Wait Until Keyword Succeeds
retries keywords multiple times:
TRY
/ EXCEPT
/ FINALLY
You can use TRY
, EXCEPT
, and FINALLY
to catch and handle errors or exceptions. This is similar to handling exceptions in Python. See the TRY / EXCEPT / FINALLY exception catching and handling in Robot Framework article for more information.
Manage exception and failures with Work data management and Work items
Examples of deterministic retry logic for browser and HTTP tasks
The following example utilizes the Wait Until Keyword Succeeds
keyword in browser and HTTP tasks. This will demonstrate deterministic retry logic that will move forward quickly with the rest of the task when an attempt is successful, or fail with a useful console message after the expected global amount of retries have been used up.
The ${GLOBAL_RETRY_AMOUNT}
variable will control the amount of retries for each of the tasks, you can use amount of iterations (for example, 3x
) or a timeout duration (for example, 3s
). The ${GLOBAL_RETRY_INTERVAL}
variable will control how quickly each retry is triggered.
Take note of how the Wait Until Keyword Succeeds
is used in the HTTP and browser keywords. These are the retry mechanisms that will prevent both of these tasks from failing immediately. There are also Log To Console
and Log
examples that assist with capturing more details of the HTTP task.