Collections库是RobotFramework用来处理列表和字典的库,官方文档是这样介绍的:A test library providing keywords for handling lists and dictionaries.

官方文档:http://robotframework.org/robotframework/latest/libraries/Collections.html

Keywords

Keyword Arguments Documentation
Append To List list_, *values

Adds values to the end of list.在list的后面增加值

Example:

=>

INFO : ${list} = [u'a', u'b']
 INFO : [u'a', u'b', u'1', u'2']

Combine Lists *lists

Combines the given lists together and returns the result.The given lists are not altered by this keyword.将给定的列表组合在一起并返回结果。此关键字不会更改给定的列表。

Example:

=>

20170718 17:14:49.280 : INFO : ${l1} = [u'a', u'b']
20170718 17:14:49.282 : INFO : ${l2} = [u'1', u'2']
20170718 17:14:49.283 : INFO : ${x} = [u'a', u'b', u'1', u'2']
20170718 17:14:49.284 : INFO : [u'a', u'b', u'1', u'2']

Convert To Dictionary item

Converts the given item to a Python dict type.

Mainly useful for converting other mappings to dictionaries. Use Create Dictionary from the BuiltIn library for constructing new dictionaries.New in Robot Framework 2.9.

将给定项目转换为Python dict类型。主要用于将其他映射转换为字典。 使用BuiltIn库中的“创建字典”来构建新的字典。

Convert To List item

Converts the given item to a Python list type.

Mainly useful for converting tuples(元组) and other iterable to lists. Use Create List from the BuiltIn library for constructing new lists.

Copy Dictionary dictionary

Returns a copy of the given dictionary.

The given dictionary is never altered by this keyword.

Copy List list_

Returns a copy of the given list.

The given list is never altered by this keyword.

Count Values In List list_, value, start=0, end=None

Returns the number of occurrences of the given value in list.

The search can be narrowed to the selected sublist by the start and end indexes having the same semantics as with Get Slice From List keyword. The given list is never altered by this keyword.

Example:

${x} = Count Values In List ${L3} b

=>

${x} = 1
${L3} is not changed
Dictionaries Should Be Equal dict1, dict2, msg=None,values=True

Fails if the given dictionaries are not equal.

First the equality of dictionaries' keys is checked and after that all the key value pairs. If there are differences between the values, those are listed in the error message. The types of the dictionaries do not need to be same.

See Lists Should Be Equal for more information about configuring the error message with msg and values arguments.

The given dictionaries are never altered by this keyword.

Dictionary Should Contain Item dictionary, key, value, msg=None

An item of key`/value must be found in a dictionary`.

Value is converted to unicode for comparison.

See Lists Should Be Equal for an explanation of msg. The given dictionary is never altered by this keyword.

Dictionary Should Contain Key dictionary, key, msg=None

Fails if key is not found from dictionary.

See List Should Contain Value for an explanation of msg.

The given dictionary is never altered by this keyword.

Dictionary Should Contain Sub Dictionary dict1, dict2, msg=None,values=True

Fails unless all items in dict2 are found from dict1.

See Lists Should Be Equal for more information about configuring the error message with msg and values arguments.

The given dictionaries are never altered by this keyword.

Dictionary Should Contain Value dictionary, value, msg=None

Fails if value is not found from dictionary.

See List Should Contain Value for an explanation of msg.

The given dictionary is never altered by this keyword.

Dictionary Should Not Contain Key dictionary, key, msg=None

Fails if key is found from dictionary.

See List Should Contain Value for an explanation of msg.

The given dictionary is never altered by this keyword.

Dictionary Should Not Contain Value dictionary, value, msg=None

Fails if value is found from dictionary.

See List Should Contain Value for an explanation of msg.

The given dictionary is never altered by this keyword.

Get Dictionary Items dictionary

Returns items of the given dictionary.

Items are returned sorted by keys. The given dictionary is not altered by this keyword.

Example:

${items} = Get Dictionary Items ${D3}

=>

${items} = ['a', 1, 'b', 2, 'c', 3]
Get Dictionary Keys dictionary

Returns keys of the given dictionary.

If keys are sortable, they are returned in sorted order. The given dictionary is never altered by this keyword.

Example:

${keys} = Get Dictionary Keys ${D3}

=>

${keys} = ['a', 'b', 'c']
Get Dictionary Values dictionary

Returns values of the given dictionary.

Values are returned sorted according to keys. The given dictionary is never altered by this keyword.

Example:

${values} = Get Dictionary Values ${D3}

=>

${values} = [1, 2, 3]
Get From Dictionary dictionary, key

Returns a value from the given dictionary based on the given key.

If the given key cannot be found from the dictionary, this keyword fails.

The given dictionary is never altered by this keyword.

Example:

${value} = Get From Dictionary ${D3} b

=>

${value} = 2
Get From List list_, index

Returns the value specified with an index from list.

The given list is never altered by this keyword.

Index 0 means the first position, 1 the second, and so on. Similarly, -1 is the last position, -2 the second last, and so on. Using an index that does not exist on the list causes an error. The index can be either an integer or a string that can be converted to an integer.

Examples (including Python equivalents in comments):

${x} = Get From List ${L5} 0 # L5[0]
${y} = Get From List ${L5} -2 # L5[-2]

=>

${x} = 'a'
${y} = 'd'
${L5} is not changed
Get Index From List list_, value, start=0, end=None

Returns the index of the first occurrence of the value on the list.

The search can be narrowed to the selected sublist by the start and end indexes having the same semantics as with Get Slice From List keyword. In case the value is not found, -1 is returned. The given list is never altered by this keyword.

Example:

${x} = Get Index From List ${L5} d

=>

${x} = 3
${L5} is not changed
Get Match Count list, pattern,case_insensitive=False,whitespace_insensitive=False

Returns the count of matches to pattern in list.

For more information on patterncase_insensitive, and whitespace_insensitive, see Should Contain Match.

Examples:

${count}= Get Match Count ${list} a* # ${count} will be the count of strings beginning with 'a'  
${count}= Get Match Count ${list} regexp=a.* # ${matches} will be the count of strings beginning with 'a' (regexp version)  
${count}= Get Match Count ${list} a* case_insensitive=${True} # ${matches} will be the count of strings beginning with 'a' or 'A'

New in Robot Framework 2.8.6.

Get Matches list, pattern,case_insensitive=False,whitespace_insensitive=False

Returns a list of matches to pattern in list.

For more information on patterncase_insensitive, and whitespace_insensitive, see Should Contain Match.

Examples:

${matches}= Get Matches ${list} a* # ${matches} will contain any string beginning with 'a'  
${matches}= Get Matches ${list} regexp=a.* # ${matches} will contain any string beginning with 'a' (regexp version)  
${matches}= Get Matches ${list} a* case_insensitive=${True} # ${matches} will contain any string beginning with 'a' or 'A'

New in Robot Framework 2.8.6.

Get Slice From List list_, start=0, end=None

Returns a slice of the given list between start and end indexes.

The given list is never altered by this keyword.

If both start and end are given, a sublist containing values from start to end is returned. This is the same as list[start:end] in Python. To get all items from the beginning, use 0 as the start value, and to get all items until and including the end, use None (default) as the end value.

Using start or end not found on the list is the same as using the largest (or smallest) available index.

Examples (incl. Python equivalents in comments):

${x} = Get Slice From List ${L5} 2 4 # L5[2:4]
${y} = Get Slice From List ${L5} 1   # L5[1:None]
${z} = Get Slice From List ${L5}   -2 # L5[0:-2]

=>

${x} = ['c', 'd']
${y} = ['b', 'c', 'd', 'e']
${z} = ['a', 'b', 'c']
${L5} is not changed
Insert Into List list_, index, value

Inserts value into list to the position specified with index.

Index 0 adds the value into the first position, 1 to the second, and so on. Inserting from right works with negative indices so that -1 is the second last position, -2third last, and so on. Use Append To List to add items to the end of the list.

If the absolute value of the index is greater than the length of the list, the value is added at the end (positive index) or the beginning (negative index). An index can be given either as an integer or a string that can be converted to an integer.

Example:

Insert Into List ${L1} 0 xxx
Insert Into List ${L2} ${-1} xxx

=>

${L1} = ['xxx', 'a']
${L2} = ['a', 'xxx', 'b']
Keep In Dictionary dictionary, *keys

Keeps the given keys in the dictionary and removes all other.

If the given key cannot be found from the dictionary, it is ignored.

Example:

Keep In Dictionary ${D5} b x d

=>

${D5} = {'b': 2, 'd': 4}
List Should Contain Sub List list1, list2, msg=None,values=True

Fails if not all of the elements in list2 are found in list1.

The order of values and the number of values are not taken into account.

See Lists Should Be Equal for more information about configuring the error message with msg and values arguments.

List Should Contain Value list_, value, msg=None

Fails if the value is not found from list.

If the keyword fails, the default error messages is <list> does not contain value '<value>'. A custom message can be given using the msg argument.

List Should Not Contain Duplicates list_, msg=None

Fails if any element in the list is found from it more than once.

The default error message lists all the elements that were found from the list multiple times, but it can be overridden by giving a custom msg. All multiple times found items and their counts are also logged.

This keyword works with all iterables that can be converted to a list. The original iterable is never altered.

List Should Not Contain Value list_, value, msg=None

Fails if the value is found from list.

See List Should Contain Value for an explanation of msg.

Lists Should Be Equal list1, list2, msg=None,values=True, names=None

Fails if given lists are unequal.

The keyword first verifies that the lists have equal lengths, and then it checks are all their values equal. Possible differences between the values are listed in the default error message like Index 4: ABC != Abc. The types of the lists do not need to be the same. For example, Python tuple and list with same content are considered equal.

The error message can be configured using msg and values arguments:

  • If msg is not given, the default error message is used.
  • If msg is given and values gets a value considered true (see Boolean arguments), the error message starts with the given msg followed by a newline and the default message.
  • If msg is given and values is not given a true value, the error message is just the given msg.

Optional names argument can be used for naming the indices shown in the default error message. It can either be a list of names matching the indices in the lists or a dictionary where keys are indices that need to be named. It is not necessary to name all of the indices. When using a dictionary, keys can be either integers or strings that can be converted to integers.

Examples:

${names} = Create List First Name Family Name Email
Lists Should Be Equal ${people1} ${people2} names=${names}  
${names} = Create Dictionary 0=First Name 2=Email  
Lists Should Be Equal ${people1} ${people2} names=${names}  

If the items in index 2 would differ in the above examples, the error message would contain a row like Index 2 (email): name@foo.com != name@bar.com.

Log Dictionary dictionary, level=INFO

Logs the size and contents of the dictionary using given level.

Valid levels are TRACE, DEBUG, INFO (default), and WARN.

If you only want to log the size, use keyword Get Length from the BuiltIn library.

Log List list_, level=INFO

Logs the length and contents of the list using given level.

Valid levels are TRACE, DEBUG, INFO (default), and WARN.

If you only want to the length, use keyword Get Length from the BuiltIn library.

Pop From Dictionary dictionary, key, default=

Pops the given key from the dictionary and returns its value.

By default the keyword fails if the given key cannot be found from the dictionary. If optional default value is given, it will be returned instead of failing.

Example:

${val}= Pop From Dictionary ${D3} b

=>

${val} = 2
${D3} = {'a': 1, 'c': 3}

New in Robot Framework 2.9.2.

Remove Duplicates list_

Returns a list without duplicates based on the given list.

Creates and returns a new list that contains all items in the given list so that one item can appear only once. Order of the items in the new list is the same as in the original except for missing duplicates. Number of the removed duplicates is logged.

New in Robot Framework 2.7.5.

Remove From Dictionary dictionary, *keys

Removes the given keys from the dictionary.

If the given key cannot be found from the dictionary, it is ignored.

Example:

Remove From Dictionary ${D3} b x y

=>

${D3} = {'a': 1, 'c': 3}
Remove From List list_, index

Removes and returns the value specified with an index from list.

Index 0 means the first position, 1 the second and so on. Similarly, -1 is the last position, -2 the second last, and so on. Using an index that does not exist on the list causes an error. The index can be either an integer or a string that can be converted to an integer.

Example:

${x} = Remove From List ${L2} 0

=>

${x} = 'a'
${L2} = ['b']
Remove Values From List list_, *values

Removes all occurrences of given values from list.

It is not an error if a value does not exist in the list at all.

Example:

Remove Values From List ${L4} a c e f

=>

${L4} = ['b', 'd']
Reverse List list_

Reverses the given list in place.

Note that the given list is changed and nothing is returned. Use Copy List first, if you need to keep also the original order.

Reverse List ${L3}

=>

${L3} = ['c', 'b', 'a']
Set List Value list_, index, value

Sets the value of list specified by index to the given value.

Index 0 means the first position, 1 the second and so on. Similarly, -1 is the last position, -2 second last, and so on. Using an index that does not exist on the list causes an error. The index can be either an integer or a string that can be converted to an integer.

Example:

Set List Value ${L3} 1 xxx
Set List Value ${L3} -1 yyy

=>

${L3} = ['a', 'xxx', 'yyy']
Set To Dictionary dictionary, *key_value_pairs,**items

Adds the given key_value_pairs and items to the dictionary.

Giving items as key_value_pairs means giving keys and values as separate arguments:

Set To Dictionary ${D1} key value second ${2}

=>

${D1} = {'a': 1, 'key': 'value', 'second': 2}

Starting from Robot Framework 2.8.1, items can also be given as kwargs using key=value syntax:

Set To Dictionary ${D1} key=value second=${2}

The latter syntax is typically more convenient to use, but it has a limitation that keys must be strings.

If given keys already exist in the dictionary, their values are updated.

Should Contain Match list, pattern, msg=None,case_insensitive=False,whitespace_insensitive=False

Fails if pattern is not found in list.

See List Should Contain Value for an explanation of msg.

By default, pattern matching is similar to matching files in a shell and is case-sensitive and whitespace-sensitive. In the pattern syntax, * matches to anything and ?matches to any single character. You can also prepend glob= to your pattern to explicitly use this pattern matching behavior.

If you prepend regexp= to your pattern, your pattern will be used according to the Python re module regular expression syntax. Important note: Backslashes are an escape character, and must be escaped with another backslash (e.g. regexp=\\d{6} to search for \d{6}). See BuiltIn.Should Match Regexp for more details.

If case_insensitive is given a true value (see Boolean arguments), the pattern matching will ignore case.

If whitespace_insensitive is given a true value (see Boolean arguments), the pattern matching will ignore whitespace.

Non-string values in lists are ignored when matching patterns.

The given list is never altered by this keyword.

See also Should Not Contain Match.

Examples:

Should Contain Match ${list} a*     # Match strings beginning with 'a'.
Should Contain Match ${list} regexp=a.*     # Same as the above but with regexp.
Should Contain Match ${list} regexp=\\d{6}     # Match strings containing six digits.
Should Contain Match ${list} a* case_insensitive=True   # Match strings beginning with 'a' or 'A'.
Should Contain Match ${list} ab* whitespace_insensitive=yes   # Match strings beginning with 'ab' with possible whitespace ignored.
Should Contain Match ${list} ab* whitespace_insensitive=true case_insensitive=true # Same as the above but also ignore case.

New in Robot Framework 2.8.6.

Should Not Contain Match list, pattern, msg=None,case_insensitive=False,whitespace_insensitive=False

Fails if pattern is found in list.

Exact opposite of Should Contain Match keyword. See that keyword for information about arguments and usage in general.

New in Robot Framework 2.8.6.

Sort List list_

Sorts the given list in place.

The strings are sorted alphabetically and the numbers numerically.

Note that the given list is changed and nothing is returned. Use Copy List first, if you need to keep also the original order.

${L} = [2,1,'a','c','b']

Sort List ${L}

=>

${L} = [1, 2, 'a', 'b', 'c']

robotframework的学习笔记(十五)----robotframework标准库Collections的更多相关文章

  1. python3.4学习笔记(十五) 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)

    python3.4学习笔记(十五) 字符串操作(string替换.删除.截取.复制.连接.比较.查找.包含.大小写转换.分割等) python print 不换行(在后面加上,end=''),prin ...

  2. (转载)西门子PLC学习笔记十五-(数据块及数据访问方式)

    一.数据块 数据块是在S7 CPU的存储器中定义的,用户可以定义多了数据块,但是CPU对数据块数量及数据总量是有限制的. 数据块与临时数据不同,当逻辑块执行结束或数据块关闭,数据块中的数据是会保留住的 ...

  3. (C/C++学习笔记) 十五. 构造数据类型

    十五. 构造数据类型 ● 构造数据类型概念 Structured data types 构造数据类型 结构体(structure), 联合体/共用体 (union), 枚举类型(enumeration ...

  4. JavaScript权威设计--JavaScript脚本化文档Document与CSS(简要学习笔记十五)

    1.Document与Element和TEXT是Node的子类. Document:树形的根部节点 Element:HTML元素的节点 TEXT:文本节点   >>HtmlElement与 ...

  5. python 学习笔记十五 web框架

    python Web程序 众所周知,对于所有的Web应用,本质上其实就是一个socket服务端,用户的浏览器其实就是一个socket客户端. Python的WEB框架分为两类: 自己写socket,自 ...

  6. Python学习笔记011_模块_标准库_第三方库的安装

    容器 -> 数据的封装 函数 -> 语句的封装 类 -> 方法和属性的封装 模块 -> 模块就是程序 , 保存每个.py文件 # 创建了一个hello.py的文件,它的内容如下 ...

  7. MySQL学习笔记十五:优化(2)

    一.数据库性能评测关键指标 1.IOPS:每秒处理的IO请求次数,这跟磁盘硬件相关,DBA不能左右,但推荐使用SSD. 2.QPS:每秒查询次数,可以使用show status或mysqladmin ...

  8. Java基础学习笔记十五 集合、迭代器、泛型

    Collection 集合,集合是java中提供的一种容器,可以用来存储多个数据. 在前面的学习中,我们知道数据多了,可以使用数组存放或者使用ArrayList集合进行存放数据.那么,集合和数组既然都 ...

  9. angular学习笔记(十五)-module里的'服务'

    本篇介绍angular中的模块:module 在笔记(二)http://www.cnblogs.com/liulangmao/p/3711047.html里已经讲到过模块,这篇主要讲模块的 '服务' ...

  10. Java学习笔记十五:Java中的成员变量和局部变量

    Java中的成员变量和局部变量 一:成员变量: 成员变量在类中定义,用来描述对象将要有什么 成员变量可以被本类的方法使用,也可以被其他类的方法使用,成员变量的作用域在整个类内部都是可见的 二:局部变量 ...

随机推荐

  1. 关于使用scrapy框架编写爬虫以及Ajax动态加载问题、反爬问题解决方案

    Python爬虫总结 总的来说,Python爬虫所做的事情分为两个部分,1:将网页的内容全部抓取下来,2:对抓取到的内容和进行解析,得到我们需要的信息. 目前公认比较好用的爬虫框架为Scrapy,而且 ...

  2. oracle和mysql几点差异对比

    Oracle与mysql差异性总结 之前有个项目是用oracle数据库进行开发,需要把数据库改成mysql,遇到了一些地方需要注意的,就简单记了下来. 备注: 再把oracle转成mysql的时候,表 ...

  3. oracle 数据库中的序列

    序列是什么,通俗点说,序列就是按照一定顺序进行排列,序列会自动给你递增,生成唯一的序列号: oracle数据库不同于sqlServer数据库,oracle数据库中是没有自增长列,使用的是sequenc ...

  4. JMeter接口测试系列-关联参数

    这里主要记录一下A接口的返回结果经过md5加密之后作为另外B接口的参数,这个问题困扰了很久,找了不少资料,现在把解决方法记录如下: 环境 ①JMeter 3.0 ②前置条件:将fastjson.jar ...

  5. 优先队列 poj3253 Fence Repair

    Fence Repair Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 51411   Accepted: 16879 De ...

  6. leetcode:程序猿面试技巧

    起因 写在开头,脑袋铁定秀逗了,历时20多天,刷完了leetcode上面151道题目(当然非常多是google的),感觉自己对算法和数据结构算是入门了,但仍然还有非常多不清楚的地方,于是有了对于每道题 ...

  7. Unity打包android的apk与数据包.obb分离和apk签名

    那么,通过以上图片.我相信大多数人已经知道怎么创建了,apk签名比較简单,假设之前没有签名文件.那么选择图中的Create New Keystore然后在以下两个password框中输入passwor ...

  8. 给新手--安装tomcat后username和password设置以及项目怎么部署在tomcatserver上

    安装后tomcatserver后.登陆首先就是让输入username和password.但是我们在安装tomcat的过程中好像没有让设置username和password,这时候可能有人就抓狂了.还有 ...

  9. 腾讯云开放云压测“黑科技“,产品上线从此不再“压力山大"

    商业转载请联系腾讯WeTest获得授权,非商业转载请注明出处. 能否解决"高并发"问题一直是检验一个产品后台是否稳定,架构是否合理,性能是否强大的核心标准.对于产品而言,多高的并发 ...

  10. 获取AJAX加载的内容

    1.有些网页内容使用AJAX加载,AJAX一般返回的是JSON,直接对AJAX地址进行post或get,就返回JSON数据了. 2.用抓包工具分析https://movie.douban.com/j/ ...