Paul Tran
Paul Tran

Reputation: 45

Can I declare a list inside a dictionary in Robot Framework

Im new to robot framework

Could anyones help with this concern.

In python we can declare a dictionary that contain a list

dict = {"key1":[1,2,3,4,5], "key2":3, "key3":"string"}

I wonder if we can do the same thing in robot framework?

Upvotes: 1

Views: 2304

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 386020

You can do it via the Create List and Create Dictionary keywords:

*** Test Cases ***
Example 1
    ${key1}  Create list   ${1}  ${2}  ${3}  ${4}  ${5}   # coerce values to integers
    ${key2}  Set variable  ${3}  # coerce to integer
    ${key3}  Set variable  string
    ${dict}=  Create dictionary
    ...  key1=${key1}
    ...  key2=${key2}
    ...  key3=${key3}

Starting with robot framework 3.2 you can use inline evaluation by putting a python expression between ${{ and }}. For example:

*** Test Cases ***
Example 2
    ${dict}=  Set variable  ${{ {"key1":[1,2,3,4,5], "key2":3, "key3":"string"} }}

The nice thing about inline evaluation is that you can use it in the variables section:

*** Variables ***
${dict}   ${{ {"key1":[1,2,3,4,5], "key2":3, "key3":"string"} }}

Upvotes: 3

Related Questions