This Library provides keywords for handling Lists and Dictionaries.
To use list keywords with a list variable (e.g. @{list}), convert it first
to a scalar variable (e.g. ${list}). A scalar variable containing a list can
also be converted to a list variable.
Examples:
Keyword |
Arguments |
Documentation |
Append To List |
L, *values |
Adds 'values' to the end of L.
Example:
Append To List |
${L1} |
xxx |
|
|
Append To List |
${L2} |
x |
y |
z |
=>
${L1} == ['a', 'xxx']
${L2} == ['a', 'b', 'x', 'y', 'z'] |
Combine Lists |
*lists |
Combines the given 'lists' together and returns the result.
The given lists are never altered by this keyword.
Example:
${x} = |
Combine List |
${L1} |
${L2} |
|
${y} = |
Combine List |
${L1} |
${L2} |
${L1} |
=>
${x} == ['a', 'a', 'b']
${y} == ['a', 'a', 'b', 'a']
${L1} and ${L2} are not changed. |
Convert To List |
item |
Converts the given 'item' to a list.
Mainly useful for converting tuples 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 |
L |
Returns a copy of the given list.
The given list is never altered by this keyword. |
Count Values In List |
L, value, start=0, end=None |
Returns the number of occurrences of the given value in L.
The given list is never altered by this keyword.
The search can be narrowed to the selected sublist by the 'start' and
'end' indexes having the same semantics as in the 'Get Slice From List'
keyword.
${x} = |
Count Values In List |
${L3} |
b |
=>
${x} == 1
${L3} is not changed. |
Create Dictionary |
*key_value_pairs |
Creates and returns a dictionary from the given 'key_value_pairs'.
Examples:
${x} = |
Create Dictionary |
name |
value |
|
|
${y} = |
Create Dictionary |
a |
1 |
b |
2 |
${z} = |
Create Dictionary |
a |
${1} |
b |
${2} |
=>
${x} == {'name': 'value'}
${y} == {'a':'1', 'b':'2'}
${z} == {'a':1, 'b':2} |
Dictionaries Should Be Equal |
dict1, dict2, msg=None, values=True |
Fails if the given lists are unequal.
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 an error message, e.g. with dictionaries
${D1} = {'a':1, 'b':2, 'c':3} and ${D2} = {'a':1, 'b':4, 'c':6}.
Dictionaries are different:
key, dict1 value, dict2 value
b, 2, 4
c, 3, 6
See 'List Should Be Equal' for an explanation of 'msg'.
The given dictionaries are 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 if not all key, value pairs in 'dict2' are found from 'dict1.'
See 'Lists Should Be Equal' for an explanation of 'msg'.
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.
The given dictionary is never 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.
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.
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 |
L, index |
Returns the value specified with an index from L.
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} == 'c'
${L1} and ${L2} are not changed. |
Get Index From List |
L, value, start=0, end=None |
Returns the index of the first occurrence of the value on the list.
In case the value is not found, -1 is returned.
The given list is never altered by this keyword.
The search can be narrowed to the selected sublist by the 'start' and
'end' indexes having the same semantics as in the 'Get Slice From List'
keyword.
${x} = |
Get Index From List |
${L5} |
d |
=>
${x} == 3
${L5} is not changed. |
Get Slice From List |
L, start=0, end=None |
Returns the part of the given list specified with 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 'L[start:end]' in
Python. To get all items from the beginning, use 0 as the start value,
and to get all items until the end, use 'None' as the end value. 'None'
is also a default value, so in this case, it is enough to give only
'start'. If only 'end' is given, 'start' gets the value 0.
Using 'start' or 'end' not found on the list is the same as using the
largest (or smallest) available index.
Examples (incl. Python equivelants 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} |
|
-1 |
# L5[0:-2] |
=>
${x} == ['c', 'd']
${y} == ['b', 'c', 'd', 'e']
${z} == ['a', 'b', 'c']
${L5} is not changed. |
Insert Into List |
L, index, value |
Inserts 'value' into 'L' to the position specified with 'index'.
Index '0' adds the value into the first position, '1' to the second, and
so on. Similarly, '-1' is the last position, '-2' second last, and so on.
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 |
L1, L2, msg=None, values=True |
Fails if not all of the elements in L2 are found in L1.
The order of values and the number of values are not taken into acount.
See the use of 'msg' and 'values' from the 'List Should Be Equal'
keyword. |
List Should Contain Value |
L, value, msg=None |
Fails if the value is not found from L.
If 'msg' is not given, the default error message "['a', 'b', 'c'] does
not contain the value 'x'" is shown in case of a failure. Otherwise, the
given 'msg' is used in case of a failure. |
List Should Not Contain Value |
L, value, msg=None |
Fails if the value is not found from L.
See 'List Should Contain Value' for an explanation of 'msg'. |
Lists Should Be Equal |
L1, L2, msg=None, values=True |
Fail if given lists are unequal.
The first equality of lists' length is checked, and after that all
values. If there are differences between the values, those are listed in
an error message, e.g. with lists
${L1} = [1, 2, 3] and ${L2} = [0, 2, 4].
Lists are different:
index, L1 value, L2 value
0, 1, 0
2, 3, 4
- If 'msg' is not given, the possible error message is the default.
- If 'msg' is given and 'values' is either Boolean False or a string
'False' or 'No Values', the error message is simply 'msg'.
- Otherwise the error message is 'msg' + 'new line' + default. |
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 |
L, index |
Removes and returns the value specified with an index from L.
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 |
L, *values |
Removes all occurences of given value(s) from L.
Example:
Remove Values From List |
${L4} |
a |
c |
e |
f |
=>
${L4} == ['b', 'd'] |
Reverse List |
L |
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.
=>
${L3} == ['c', 'b', 'a'] |
Set List Value |
L, index, value |
Sets the value of 'L' 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 |
=>
${L3} == ['a', 'xxx', 'c'] |
Set To Dictionary |
dictionary, *key_value_pairs |
Adds the given 'key_value_pairs' to the dictionary.
Example:
Set To Dictionary |
${D1} |
key |
value |
=>
${D1} == {'a':1, 'key':'value'} |
Sort List |
L |
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']
=>
${L} == [1, 2, 'a', 'b', 'c'] |