Python 检查响应是否包含Robot框架中的值列表?
我是机器人新手,如果这是一个愚蠢的问题,我深表歉意,但我正在寻找将列表传递给内置方法的方法,该方法应包含:Python 检查响应是否包含Robot框架中的值列表?,python,selenium,robotframework,Python,Selenium,Robotframework,我是机器人新手,如果这是一个愚蠢的问题,我深表歉意,但我正在寻找将列表传递给内置方法的方法,该方法应包含: def should_contain(self, item1, item2, msg=None, values=True): """Fails if `item1` does not contain `item2` one or more times. Works with strings, lists, and anything that supports Python
def should_contain(self, item1, item2, msg=None, values=True):
"""Fails if `item1` does not contain `item2` one or more times.
Works with strings, lists, and anything that supports Python's `in`
keyword. See `Should Be Equal` for an explanation on how to override
the default error message with `msg` and `values`.
Examples:
| Should Contain | ${output} | PASS |
| Should Contain | ${some_list} | value |
"""
msg = self._get_string_msg(item1, item2, msg, values, 'does not contain')
asserts.fail_unless(item2 in item1, msg)
首先是测试用例中的简单方法,我知道这种语法是错误的,但是否可以执行类似的操作:
Should Contain ${RESPONSE} "hello","world",250
我尝试使用一个列表变量并将其传入,这似乎有效,但在更深入的调查中,它似乎只是比较元素计数,而不是实际的元素值,这令人失望
为了解决这个问题,我刚才做的应该包含我所关心的价值观。问题是我重复的是,应该在几行中包含不同的数据,这显然不是好的做法
Should Contain ${RESPONSE} "Hello"
Should Contain ${RESPONSE} "World"
Should Contain ${RESPONSE} 250
有人能提供一些指导或改进的方法来实现我的目标吗?我正在考虑创建一个新方法,允许它进入自定义库,但我认为必须有一个更简单的方法。我不关心项目的顺序。应该包含关键字,不接受列表类型变量作为第二个参数。您可以通过使用FOR循环解析列表来解决此问题:
*** Variables ***
${Response} "250 hello world foobar"
*** Test Cases ***
Stackoverflow
@{list} = Create List hello world 250
:FOR ${item} in @{list}
\ Should Contain ${RESPONSE} ${item}
收藏库有你想要的
Library Collections
List Should Contain Sub List ${list1} ${list2}
如果在列表1中未找到列表2中的所有元素,则失败。请参阅