0

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

我在测试中使用了拆卸。

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

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

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

可以预防吗?

4

2 回答 2

2

我终于做了一些研究,看看为什么使用 --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
于 2019-11-15T10:21:01.820 回答
1

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

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

--exitonfailure -x

例子:robot --exitonfailure 01_robot_test.robot

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

于 2019-11-11T16:25:08.973 回答