@@ -171,7 +171,7 @@ When a variable is used as a scalar like `${EXAMPLE}`, its value will be
171
171
used as-is. If a variable value is a list or list-like, it is also possible
172
172
to use as a list variable like `@{EXAMPLE} `. In this case individual list
173
173
items are passed in as arguments separately. This is easiest to explain with
174
- an example. Assuming that a variable `@{USER} ` has value `['robot','secret'] `,
174
+ an example. Assuming that a variable `@{USER} ` has value `['robot', 'secret'] `,
175
175
the following two test cases are equivalent:
176
176
177
177
.. sourcecode :: robotframework
@@ -228,7 +228,7 @@ similarly as scalar variables.
228
228
229
229
*** Test Cases * **
230
230
List Variable Item
231
- Login @{USER}
231
+ Login @{USER}[0] @{USER}[1]
232
232
Title Should Be Welcome @{USER}[0]!
233
233
234
234
Negative Index
@@ -313,19 +313,27 @@ Accessing individual dictionary items
313
313
It is possible to access a certain value of a dictionary variable
314
314
with the syntax `&{NAME}[key] `, where `key ` is the name of the
315
315
selected value. Keys are considered to be strings, but non-strings
316
- keys can be used as variables. Dictionary items accessed in this
317
- manner can be used similarly as scalar variables:
316
+ keys can be used as variables. Dictionary values accessed in this
317
+ manner can be used similarly as scalar variables.
318
+
319
+ If a key is a string, it is possible to access its value also using
320
+ attribute access syntax `${NAME.key} `. See `Creating dictionary variables `_
321
+ for more details about this syntax.
318
322
319
323
.. sourcecode :: robotframework
320
324
321
325
*** Test Cases * **
322
326
Dict Variable Item
323
- Login &{USER}
327
+ Login &{USER}[name] &{USER}[password]
324
328
Title Should Be Welcome &{USER}[name]!
325
329
326
- Variable Key
330
+ Key As Variable
327
331
Log Many &{DICT}[${KEY}] &{DICT}[${42}]
328
332
333
+ Attribute Access
334
+ Login ${USER.name} ${USER.password}
335
+ Title Should Be Welcome ${USER.name}!
336
+
329
337
Using dictionary variables with settings
330
338
''''''''''''''''''''''''''''''''''''''''
331
339
@@ -464,7 +472,7 @@ Dictionary variables can be created in the variable table similarly as
464
472
list variables. The difference is that items need to be created using
465
473
`name=value ` syntax or existing dictionary variables. If there are multiple
466
474
items with same name, the last value has precedence. If a name contains
467
- an equal sign, it can be escaped __ with a backslash like `\= `.
475
+ a literal equal sign, it can be escaped __ with a backslash like `\= `.
468
476
469
477
.. sourcecode :: robotframework
470
478
@@ -475,16 +483,16 @@ an equal sign, it can be escaped__ with a backslash like `\=`.
475
483
&{EVEN MORE} &{MANY} first=override empty=
476
484
... =empty key\= here=value
477
485
478
- Dictionary variables created in variable table have two extra properties
486
+ Dictionary variables have two extra properties
479
487
compared to normal Python dictionaries. First of all, values of these
480
488
dictionaries can be accessed like attributes, which means that it is possible
481
489
to use `extended variable syntax `_ like `${VAR.key} `. This only works if the
482
490
key is a valid attribute name and does not match any normal attribute
483
491
Python dictionaries have. For example, individual value `&{USER}[name] ` can
484
492
also be accessed like `${USER.name} ` (notice that `$ ` is needed in this
485
- context), but ` &{MANY}[${3}] ` does not work as ` ${MANY.3} ` .
493
+ context), but using ` ${MANY.3} ` is not possible .
486
494
487
- Another special property of dictionaries created in the variable table is
495
+ Another special property of dictionary variables is
488
496
that they are ordered. This means that if these dictionaries are iterated,
489
497
their items always come in the order they are defined. This can be useful
490
498
if dictionaries are used as `list variables `_ with `for loops `_ or otherwise.
@@ -568,7 +576,7 @@ Assigning scalar variables
568
576
''''''''''''''''''''''''''
569
577
570
578
Any value returned by a keyword can be assigned to a `scalar variable `_.
571
- As illustrated by the example below, the required syntax is very simple.
579
+ As illustrated by the example below, the required syntax is very simple:
572
580
573
581
.. sourcecode :: robotframework
574
582
@@ -599,7 +607,7 @@ Assigning list variables
599
607
''''''''''''''''''''''''
600
608
601
609
If a keyword returns a list or any list-like object, it is possible to
602
- assign it to a `list variable `_.
610
+ assign it to a `list variable `_:
603
611
604
612
.. sourcecode :: robotframework
605
613
@@ -609,7 +617,7 @@ assign it to a `list variable`_.
609
617
Length Should Be ${list} 3
610
618
Log Many @{list}
611
619
612
- Because all Robot Framework variables are stored in same namespace, there is
620
+ Because all Robot Framework variables are stored in the same namespace, there is
613
621
not much difference between assigning a value to a scalar variable or a list
614
622
variable. This can be seen by comparing the last two examples above. The main
615
623
differences are that when creating a list variable, Robot Framework
@@ -622,7 +630,7 @@ Assigning dictionary variables
622
630
''''''''''''''''''''''''''''''
623
631
624
632
If a keyword returns a dictionary or any dictionary-like object, it is possible
625
- to assign it to a `dictionary variable `_.
633
+ to assign it to a `dictionary variable `_:
626
634
627
635
.. sourcecode :: robotframework
628
636
@@ -633,16 +641,18 @@ to assign it to a `dictionary variable`_.
633
641
Do Something &{dict}
634
642
Log ${dict.first}
635
643
636
- Because all Robot Framework variables are stored in same namespace, it would
644
+ Because all Robot Framework variables are stored in the same namespace, it would
637
645
also be possible to assign a dictionary into a scalar variable and use it
638
646
later as a dictionary when needed. There are, however, some actual benefits
639
647
in creating a dictionary variable explicitly. First of all, Robot Framework
640
648
verifies that the returned value is a dictionary or dictionary-like similarly
641
649
as it verifies that list variables can only get a list-like value.
642
- Another benefit is that Robot Framework converts the value into a special
643
- dictionary it uses also when `creating dictionary variables `_ in the variable
644
- table. These dictionaries are sortable and their values can be accessed using
645
- attribute access like `${dict.first} ` in the above example.
650
+
651
+ A bigger benefit is that the value is converted into a special dictionary
652
+ that it uses also when `creating dictionary variables `_ in the variable table.
653
+ Values in these dictionaries can be accessed using attribute access like
654
+ `${dict.first} ` in the above example. These dictionaries are also ordered, but
655
+ if the original dictionary was not ordered, the resulting order is arbitrary.
646
656
647
657
Assigning multiple variables
648
658
''''''''''''''''''''''''''''
0 commit comments