how to: converting string to list?

7,914 views
Skip to first unread message

Daniel

unread,
Aug 5, 2010, 4:04:14 PM8/5/10
to robotframework-users
Hi,

How can we convert a string output into a list?

Example:
-------------
${ALL_Reports} || Run || grep "<Report" ${Report_DIR}/*.report | awk -
F "id=" '{print $2}' | sed 's/">//' | sed 's/"//'
@{ALL_Reports} || convert to list || ${ALL_Reports}

Current output is:
-------------------------
~20:30:25.987 INFO ${ALL_Reports} = Report006
Report007
Report008
Report009
Report010
Report011
Report012
Report014
Report015
Report016
Report018
Report019
Report021
Report022
Report023
Report024
Report025
Report027
Report028
Report029
...
-
+
KEYWORD: @{ALL_Reports} = Collections.Convert To List ${ALL_Reports}
Documentation: Converts the given `item` to a list.
Start / End / Elapsed: 20100805 20:30:25.989 / 20100805
20:30:25.992 / 00:00:00.003
20:30:25.992 INFO @{ALL_Reports} = [ R | e | p | o | r | t | 0 | 0 |
6 |
| R | e | p | o | r | t | 0 | 0 | 7 |
| R | e | p | o | r | t | 0 | 0 | 8 |
| R | e | p | o | r | t | 0 | 0 | 9 |
| R | e | p | o | r | t | 0 | 1 | 0 |
...


We would like something like:
-------------------------------------------
@{ALL_Reports} = [ Report006 | Report007 | Report008 | .....


Thanks,
Daniel

Pekka Klärck

unread,
Aug 5, 2010, 5:16:44 PM8/5/10
to danielsi...@gmail.com, robotframework-users
2010/8/5 Daniel <danielsi...@gmail.com>:

>
> How can we convert a string output into a list?

The `Split String` keyword in the String library ought to work for you:
http://code.google.com/p/robotframework/wiki/StringLibrary

The `Convert To List` keyword you used is meant for converting
non-list iterables to lists so that other Collections library keywords
can be used with them.

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

Andrea Fantini

unread,
Feb 27, 2015, 2:47:59 AM2/27/15
to robotframe...@googlegroups.com, danielsi...@gmail.com


On Thursday, 5 August 2010 23:16:44 UTC+2, Pekka Klärck wrote:
2010/8/5 Daniel <danielsi...@gmail.com>:
>
> How can we convert a string output into a list?

The `Split String` keyword in the String library ought to work for you:
http://code.google.com/p/robotframework/wiki/StringLibrary


Hi,
I have a somewhat similar problem, with my string being ${pippo} = [ {....}, {...} ] 
The problem is  that my string is not made up of lines, but rather by json objects, comma separated, so I cannot use Split String. 
Even using comma (,) as a separator to Split String does not work, as the json objects contain several commas. 

I would like to be able to access each "element" using something like
${pippo}[0], ${pippo}[1] etc

I can quickly implement a python function and be done with it but I was wondering if there is any keyword already done in robot framework which would to the magic.
Cheers
/Andrea

Ed Manlove

unread,
Feb 27, 2015, 6:39:43 AM2/27/15
to robotframe...@googlegroups.com
Are you using any of the soap/webservice libraries along side what you are doing with this json object?

    sudslbrary - https://github.com/ombre42/robotframework-sudslibrary#readme
    HTTPLibrary (Requests) - https://github.com/bulkan/robotframework-requests/#readme

I know there are functions that help here in the requests library (example ${resp.json()) returns a dictionary of the json object in the http response). Also there is the xml library where there might be some tools (haven't looked at it in a while)

    XML - http://robotframework.org/robotframework/#standard-libraries

Ed
--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages