如果第一个测试用例失败,如何停止机器人框架测试执行?

如果第一个测试用例失败,如何停止机器人框架测试执行?

问题描述:

如下面的机器人文件所示,我有三个测试用例.如果 TESTCASE1 失败,我想停止测试执行.只有在 TESTCASE1 通过时才应执行 TESTCASE2.

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.

*** Settings ***

Library         pythonLib


*** Test cases ***

TESTCASE1
    boot device

TESTCASE2
    configure device

TESTCASE3
    restart device  

是否有任何关键字或自定义方法可以做到这一点?

Is there any keyword or custom way to do this ?

如果您希望机器人在任何测试失败后立即停止运行,则有一个命令行选项.这个选项是--exitonfailure.来自机器人框架用户指南,在标题为 的部分中第一次测试失败时停止:

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:

如果选项 --exitonfailure 被使用,测试执行立即停止,如果任何关键测试都失败了.其余的测试也被标记为失败.

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

您可能还想查看此答案Robot Framework 中相互依赖测试的自动失败/不执行,展示了如何编写关键字来实现测试用例之间的依赖关系.

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.