I have a robot test case, in teardown I need to check if the test case failed, I need to rerun the entire test case… how to do it in robot framework
Br,
Sami
What teardown are you talking about? Test teardown or suite teardown?
There is a built-in feature to rerun failed tests only, but this is based on rerunning the whole robot command, with the --rerunfailed output.xml
where output.xml is the result of the previous run.
If this is not what you are looking for (since you are mentioning teardown) a solution could be to put all your test logic into a keyword, monitor if the keyword fails and rerun it accordingly.
However, I would suggest doing that in the body of the test rather than in the teardown, since teardown have a default behaviour of “recursive-continuing-on-failure” which is probably not appropriate to your test case.
See here:
The test teardown is special in two ways. First of all, it is executed also when a test case fails, so it can be used for clean-up activities that must be done regardless of the test case status. In addition, all the keywords in the teardown are also executed even if one of them fails. This continue on failure functionality can be used also with normal keywords, but inside teardowns it is on by default.
On the topic of how to rerun a keyword (eg. if you put all your test case into a single keyword, for rerunning purpose), there are multiple ways to proceed:
- using keywords like Wait Until Keyword Succeeds or Run Keyword And Return Status
- using the TRY/EXCEPT syntax
- using a WHILE loop which condition would be to loop until the keyword status is successful and use the settings
limit
(eg. 2 or 2min),on_limit
(eg. fail) andon_limit_message
(eg. TC failed on retries too.) to define the number of retries and the error message.
What option is available to you depends on which version of RobotFramework you are using.
To rerun a test case in Robot Framework if it fails, you can use the RetryFailed Listener. This listener automatically retries tests or tasks based on tags. Here’s how you can set it up:
-
Install the Listener: Install the
robotframework-retryfailed
package using pip:pip install robotframework-retryfailed
-
Add the Listener: Add the listener to your Robot Framework execution. You can specify the number of retries for each test case using tags.
robot --listener RetryFailed:2 your_robot_suite.robot
This will retry each failing test case twice.
-
Tagging Tests: Tag your test cases with
test:retry(n)
wheren
is the number of retries you want.*** Test Cases *** Test Case [Tags] test:retry(2) Log This test will be retried 2 times if it fails
-
Run the Tests: Execute your tests with the listener. The listener will automatically retry the tests based on the tags.
It also seems possible to do using listener.
I am running GUI Testcases, If one the testcase fails, i have created Test Teardown, where i check the test execution status, if the test case failed, i need to re-run the test case, so that next it passes. I am not looking for re-run failed testcase at the end of exeuction
there’s also this; GitHub - MarketSquare/robotframework-retryfailed: A listener to automatically retry tests or tasks based on tags.
but i’d guess its based on same principle as to what @FrancisG suggested.
Thank you Francis, will try.
Thanks francis
Thanks rasjani… will try that
Thanks sami will try this