需要注意,如果搜索的container是一个list,item需要严格匹配container里的每个item项。如果是string类型的,那就是字串的包含,这个的判断要宽松一些。
def should_contain_x_times(self, container, item, count, msg=None,
ignore_case=False, strip_spaces=False,
collapse_spaces=False):
"""Fails if ``container`` does not contain ``item`` ``count`` times.
Works with strings, lists and all objects that `Get Count` works
with. The default error message can be overridden with ``msg`` and
the actual count is always logged.
If ``ignore_case`` is given a true value (see `Boolean arguments`) and
compared items are strings, it indicates that comparison should be
case-insensitive. If the ``container`` is a list-like object, string
items in it are compared case-insensitively.
If ``strip_spaces`` is given a true value (see `Boolean arguments`)
and both arguments are strings, the comparison is done without leading
and trailing spaces. If ``strip_spaces`` is given a string value
``LEADING`` or ``TRAILING`` (case-insensitive), the comparison is done
without leading or trailing spaces, respectively.
If ``collapse_spaces`` is given a true value (see `Boolean arguments`) and both
arguments are strings, the comparison is done with all white spaces replaced by a single space character.
Examples:
| Should Contain X Times | ${
output} | hello | 2 |
| Should Contain X Times | ${
some list} | value | 3 | ignore_case=True |
``strip_spaces`` is new in Robot Framework 4.0 and ``collapse_spaces`` is new
in Robot Framework 4.1.
"""