How to stop Robot Framework test execution if first testcase FAIL?

后端 未结 3 1578
伪装坚强ぢ
伪装坚强ぢ 2020-12-31 20:47

As shown in below robot file, I have three testcases. I want to stop the test execution, if TESTCASE1 fails. TESTCASE2 should be executed only if TESTCASE1 passes.



        
相关标签:
3条回答
  • 2020-12-31 20:52

    There is a command line option for this, if you want the behavior that robot should stop running as soon as any test fails. This option is --exitonfailure. From the robot framework user guide, in a section titled Stopping when the first test fails:

    If option --exitonfailure is used, test execution stops immediately if any critical test fails. Also the remaining tests are marked as failed.

    You might also want to take a look at this answer to the question Automatic failing/non-execution of interdependent tests in Robot Framework, which shows how to write a keyword to implement dependencies between test cases.

    0 讨论(0)
  • 2020-12-31 20:57

    There are multiple ways to get the job done, each appropriate for different situations.

    --exitonfailure

    The command line option --exitonfailure aborts the test run after any testcase fails, unless it is marked noncritical.

    Fatal Error

    You might only want to abort if exactly TESTCASE1 fails. The Fatal Error keyword exist just for this purpose:

    TESTCASE1
        ${passed}=  Run Keyword And Return Status  boot device
        Run Keyword If  not ${passed}  Fatal Error
    

    If this seems clunky to you, you can throw fatal errors directly from Python/Java.

    Suite Setup

    These tools will get the job done, and are appropriate in some cases. Although in the asker's case, I observe:

    • The first testcase must pass for any other tests to run.
    • It runs a keyword called boot device.

    To me that is not a testcase. That is a setup. If you need a setup to run once before a suite of testcases, you should specify it as a Suite Setup.

    ***Settings***
        Suite Setup    boot device
    
    0 讨论(0)
  • 2020-12-31 21:14

    --pause_on_failure, this will stop the execution, whenever script hit the error. Script execution won't be resumed unless you explicitly start.

    0 讨论(0)
提交回复
热议问题