如果第一个测试用例失败,如何停止 Robot Framework 测试执行?

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

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

*** Settings ***

Library         pythonLib


*** Test cases ***

TESTCASE1
    boot device

TESTCASE2
    configure device

TESTCASE3
    restart device  

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

如果您希望机器人在任何测试失败时立即停止 运行 的行为,则有一个命令行选项。这个选项是--exitonfailure。来自机器人框架用户指南,在标题为 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.

您可能还想看看 this answer to the question Automatic failing/non-execution of interdependent tests in Robot Framework,它展示了如何编写关键字来实现测试用例之间的依赖关系。

--pause_on_failure,每当脚本遇到错误时,这将停止执行。除非您明确开始,否则不会恢复脚本执行。

有多种方法可以完成工作,每种方法适用于不同的情况。

--退出失败

命令行选项--exitonfailure任何测试用例失败后中止测试运行,除非它被标记为noncritical

致命错误

您可能只想在恰好 TESTCASE1 失败时中止。 Fatal Error 关键字就是为了这个目的而存在的:

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

如果你觉得这很笨拙,你可以抛出致命错误 directly from Python/Java

套件设置

这些工具可以完成工作,并且在某些情况下是合适的。尽管在提问者的情况下,我观​​察到:

  • 第一个测试用例必须通过 运行 的任何其他测试。
  • 它 运行 是一个名为 boot device 的关键字。

对我来说这不是测试用例。那是一个设置。如果您需要在一组测试用例之前设置一次 运行,则应将其指定为 Suite Setup.

***Settings***
    Suite Setup    boot device