Rerun failed robot tc in teardown

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

Hi,
Check this:
https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html?_ga=2.37241376.1827002870.1738130098-151480807.1700649855#toc-entry-514

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:

What option is available to you depends on which version of RobotFramework you are using.

1 Like

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:

  1. Install the Listener: Install the robotframework-retryfailed package using pip:

    pip install robotframework-retryfailed
    
  2. 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.

  3. Tagging Tests: Tag your test cases with test:retry(n) where n 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
    
  4. Run the Tests: Execute your tests with the listener. The listener will automatically retry the tests based on the tags.

1 Like

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.

1 Like

Thank you Francis, will try.

Thanks francis

Thanks rasjani… will try that

Thanks sami will try this