Povilas Kamarauskas
Povilas Kamarauskas

Reputation: 21

How to run one test case if another specifically fails

my problem is that I made two test cases which are perfectly fine and working nicely, however I need to run second one only if first one fails. How can I do that? I'm using RIDE Robotframework and working on IE, because of legacy app.

Upvotes: 0

Views: 847

Answers (3)

Pekka
Pekka

Reputation: 2270

You could use Pass Execution If keyword with suite variables. This is not perfect solution because Test B is still logged as passed.

*** Test Cases ***
Test A
    Set Suite Variable    ${a_passed}      ${FALSE}
    Fail                  This case failed
    Set Suite Variable    ${a_passed}      ${TRUE}

Test B
    Pass Execution If     ${a_passed}      A passed so skipping B
    Log To Console        Running Test B

Upvotes: 0

Bryan Oakley
Bryan Oakley

Reputation: 385970

You can't do what you want. At least, not directly. Robot provides no way to add additional tests after the tests have started running.

However, if instead of "run second one" you say "run a special keyword", you can move the functionality to a keyword and call it in a test teardown using Run keyword if test failed

*** Keywords ***
On test teardown
    run keyword if test failed
    ...  log  BUMMER!  WARN

*** Test Cases ***
Passing test
    [Teardown]  On test teardown
    log  hello, world

Failing test
    [Teardown]  On test teardown
    fail  this test has failed.

Upvotes: 2

Muhamed Keta
Muhamed Keta

Reputation: 185

What you can do is make tests:

  • Test A passes.
  • Test A fails.
  • Test A fails and runs test B.

However I'd prefer you wouldn't do that. Usually tests should be logically separate. If you could you would run all of them on parallel.

If a test fails you shouldn't be concerned with testing other stuff at that point. You should fix the first test. Otherwise you will go in a rabbit hole of tests.

Upvotes: 2

Related Questions