cucuru
cucuru

Reputation: 3698

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?

Upvotes: 0

Views: 4447

Answers (2)

cucuru
cucuru

Reputation: 3698

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

Upvotes: 2

ponkape
ponkape

Reputation: 487

Try this to prevent to executing "Delete user" keyword when calling exitonfailure: http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#stopping-when-first-test-case-fails

Usage: When options are used, they must always be given between the runner script and the data sources

--exitonfailure -x

Example: robot --exitonfailure 01_robot_test.robot

If option --exitonfailure (-X) is used, test execution stops immediately if any critical test fails. The remaining tests are marked as failed without actually executing them.

Upvotes: 1

Related Questions