Home > Mobile >  How to add a dictionary to a list in robot framework
How to add a dictionary to a list in robot framework

Time:12-29

Say I have a list:

contacts: []

Now, I want to add a dictionary to this list, through a Robot Framework keyword. The Key of this dictionary is email_address, and its value is passed as an argument. This is the keyword:

Test keyword
[Arguments]      ${email}      #[email protected]
Append to list   ${contacts}   {"email_address":"$email"}

But this doesn't work. I want the final result to be like this:

contacts: [{"email_address":"[email protected]"}]

How can I do that?

CodePudding user response:

You have to create the dictionary first:

Test keyword
    [Arguments]      ${email}      #[email protected]
    &{dictionary}=    Create Dictionary    email_address=${email}
    Append to list   ${contacts}   ${dictionary}
  • Related