robotframeworkteardown

robot framework stop teardown execution in failure


I'm using robot framework to test my application

I use teardown in my test.

It works as expected, if my test ends or fails, teardown starts the execution. My problem starts when the teardown execution fails, then I want it to stop.

*** Test Cases ***
Test new data import
   Setup test case
   Run test case
   [Teardown]  TearDown test case

Teardown test case
   Insert name in filter
   Delete user

The scenarios is when "Insert name in filter" fails, I want it to stop running, but it executes the "Delete user" keyword.

Is it possible to prevent?


Solution

  • I finally do some research and see why the use of --exitonfailure (suggested in other answer) didn't work for me,it's because it misses the teardown workflow.

    https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#id689 that teardown execution can be stopped

    Teardown -> Also they are executed fully even if some of their keywords fail.

    So, what I did to solve was use Run Keyword and return Status and Run Keyword if to solve:

    *** Test Cases ***
    Test new data import
      Setup test case
      Run test case
      [Teardown]  TearDown test case
    
    Teardown test case
      ${filterStatus}  Run keyword and return status  Insert name in filter
      Run keyword if  ${filterStatus}  Delete user
      ... ELSE  fail  Filter filter by name failed