Re: Assigning a long string to a variable

2,398 views
Skip to first unread message

Tatu aalto

unread,
Jul 26, 2012, 3:10:49 AM7/26/12
to hoan...@openx.com, robotframe...@googlegroups.com

Ugh

I am able to store long and complex json objects in to a variable and re-use object in the variable later.

Could you describe more better what is your problem, perhaps with some example data. Also if you get some error messages, those would be important too.

-Tatu

On Jul 25, 2012 11:11 PM, "hoan" <hoan...@openx.com> wrote:

hoan

unread,
Jul 26, 2012, 12:58:39 PM7/26/12
to robotframe...@googlegroups.com, hoan...@openx.com
Below is an example of what I am trying to do. The JSON string can be several lines long. How would you do a line continuation?

${json_data}     Set Variable    [ { "key11": "value11", "key12": "value12", "key13": "value13", ... }, { "key21": "value21", "key22": "value22", "key23": "value23", ... }, ... ]

I am using space-separated text file for my tests.

Hoan
On Jul 25, 2012 11:11 PM, "hoan" wrote:

hoan

unread,
Jul 26, 2012, 6:56:19 PM7/26/12
to robotframe...@googlegroups.com, hoan...@openx.com
I found that I can use the Catenate keyword from the BuiltIn library to accomplish this. Maybe not elegant, but it gets it done.

   @{json_data}  Set Variable   
   ...  { "key1": ["value11", "value12"],
   ...    "key2": ["value21", "value22"]}

   ${json_str}     Catenate    @{json_data}
   Log  ${json_data}
   Log  ${json_str}


A big thanks go to the folks who created and maintained RF. This is a great tool. Most of everything that is needed is already there.

Hoan

Pekka Klärck

unread,
Jul 27, 2012, 6:00:17 PM7/27/12
to hoan...@openx.com, robotframe...@googlegroups.com
2012/7/27 hoan <hoan...@openx.com>:
> I found that I can use the Catenate keyword from the BuiltIn library to
> accomplish this. Maybe not elegant, but it gets it done.
>
> @{json_data} Set Variable
> ... { "key1": ["value11", "value12"],
> ... "key2": ["value21", "value22"]}
>
> ${json_str} Catenate @{json_data}
> Log ${json_data}
> Log ${json_str}

This is what I would have proposed. Although I would probably just use
Catenate directly without first creating temporary @{json_data}
variable:

${json_str} = Catenate
... { "key1": ["value11", "value12"],
... "key2": ["value21", "value22"]}

Hopefully it will be possible to wrap long values like this into
multiple lines also in the variable table:
http://code.google.com/p/robotframework/issues/detail?id=939

> A big thanks go to the folks who created and maintained RF. This is a great
> tool. Most of everything that is needed is already there.

Thanks!

Cheers,
.peke

PS: I've been on holiday lately and haven't had time to participate
discussion on this list too much. You can expect more activity next
week.
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org
Reply all
Reply to author
Forward
0 new messages