2

So I get that Robot has 3 types of variable Scalar which are like ${}, List Which are like @{} and Dictionary which are like &{} but I dont understand it completely how they get treated in framework. Like I created dictionary variable like

*** Variables ***
&{D}           A=a  'B'=b

And then can use it like

${new_D}=   Copy Dictionary ${D} 
${var}= Get From Dictionary ${New D}    MGMT_IP 

Since D and new_D are of dictionary type why they should not always be prefixed by &. Same goes for list.

1 Answer 1

4

The & prefix is used when creating the dictionary variable. Then you want to use the dict variable:

  • if you use $ prefix, then you access the dict as a whole. This is the most common way to use it, just like you do in your example.
  • if you use the &prefix, then you get the individual items of the dictionary (list of key:value).

This is best understood with an example (see the doc):

Assuming that a variable &{USER} has value {'name': 'robot', 'password': 'secret'}, the following two test cases are equivalent.

*** Test Cases ***
Constants
    Login    name=robot    password=secret

Dict Variable
    Login    &{USER}

But if you want to Copy Dictionary or Log the dict, then you access it with ${USER}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.