一旦机器人开始运行,就无法根据某种条件跳过测试。我认为这是机器人的弱点之一,但设计人员似乎真的不喜欢跳过测试的概念。而且,没有一种内置方法可以使一个测试依赖另一个。一本非常有特点的请求被拒绝。
但是,robot具有非常强的可扩展性,并且2.8.5版中引入的一项功能可以轻松编写一个关键字,如果另一个测试失败,该关键字将会失败。此功能是库可以充当侦听器的功能。这样,库可以跟踪每个测试的通过/失败状态。有了这些知识,您可以创建一个关键字,如果某个其他测试失败,该关键字将立即失败。
基本思想是,在每次测试完成时(通过特殊
_end_test方法)缓存通过/失败状态。然后,使用此值确定是否立即失败。
这是如何使用这样的关键字的示例:
*** Settings ***| Library | /path/to/DependencyLibrary.py*** Test Cases ***| Example of a failing test| | fail | this test has failed| Example of a dependent test| | [Setup] | Require test case | Example of a failing test| | log | hello, world
这是库的定义:
from robot.libraries.BuiltIn import BuiltInclass DependencyLibrary(object): ROBOT_LISTENER_API_VERSION = 2 ROBOT_LIBRARY_SCOPE = "GLOBAL" def __init__(self): self.ROBOT_LIBRARY_LISTENER = self self.test_status = {} def require_test_case(self, name): key = name.lower() if (key not in self.test_status): BuiltIn().fail("required test case can't be found: '%s'" % name) if (self.test_status[key] != "PASS"): BuiltIn().fail("required test case failed: '%s'" % name) return True def _end_test(self, name, attrs): self.test_status[name.lower()] = attrs["status"]


