【问题标题】:robot framework stop teardown execution in failure机器人框架在失败中停止拆卸执行
【发布时间】:2019-11-15 18:21:01
【问题描述】:

我正在使用机器人框架来测试我的应用程序

我在测试中使用了拆解。

它按预期工作,如果我的测试结束或失败,teardown 将开始执行。当拆解执行失败时,我的问题就开始了,然后我希望它停止。

*** 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

场景是“在过滤器中插入名称”失败,我希望它停止运行,但它执行“删除用户”关键字。

可以预防吗?

【问题讨论】:

    标签: robotframework teardown


    【解决方案1】:

    我终于做了一些研究,看看为什么使用 --exitonfailure (在其他答案中建议)对我不起作用,这是因为它错过了拆卸工作流程。

    https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#id689表示可以停止拆卸执行

    Teardown -> 即使某些关键字失败,它们也会完全执行。

    所以,我解决的方法是使用 Run Keyword 并返回 Status 和 Run Keyword if 来解决:

    *** 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
    

    【讨论】:

      【解决方案2】:

      尝试这样做以防止在调用 exitonfailure 时执行“删除用户”关键字:http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#stopping-when-first-test-case-fails

      用法:使用选项时,必须始终在运行器脚本和数据源之间给出它们

      --exitonfailure -x
      

      例如:robot --exitonfailure 01_robot_test.robot

      如果使用选项 --exitonfailure (-X),如果任何关键测试失败,测试执行将立即停止。剩余的测试被标记为失败,但没有实际执行。

      【讨论】:

      • 对不起,但我无法使用此标志,我看到它们退出,但无法使它们运行,如果我使用 Delete user --exitonfailure -x 并运行我有一个错误“预期 0 个参数,得到 1 个”。应该怎么用?
      • 我认为您应该专门针对您的问题使用--skipteardownonexit
      • 如果你从终端运行你的测试用例:robot --exitonfailure testfile.robot试试这个@cucuru
      • 请评论结果如何@cucuru
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-05
      • 2018-10-18
      • 2021-07-17
      • 2019-01-14
      • 2015-02-18
      • 2017-08-06
      • 2019-12-30
      相关资源
      最近更新 更多