Iterating over 2-dimensional list

909 views
Skip to first unread message

prinzdezibel

unread,
Jan 23, 2012, 12:36:20 PM1/23/12
to robotframework-users
Hi,

I'm trying to define a 2-dimensional list in a resources *** Variables
*** section. After that I want to iterate over this list in a test
case. I'm can't figure out how to accomplish this. What I've tried:

In a separate resource file I'd like to create a two dimensional
array:

*** Variables ***
@{app1} Application One None 00897-0000 True False
@{app2} Application Two   None 06455-0000 True False
@{applications} @{app1} @{app2}


In a test file I'm looping over the 2-dimensional array:
A simple test
:FOR ${app} IN @{applications}
\ Log ApplicationName: @{app}[0]


What happens is that the array seems not to be 2-dimensional, but
instead all the individual item values are concatenated to one string.
What am I doing wrong?


Thank you,
prinz

Ing. Guillermo Zapata

unread,
Jan 23, 2012, 7:42:22 PM1/23/12
to robotframework-users
Hi,

On Mon, Jan 23, 2012 at 11:36 AM, prinzdezibel <prinzd...@googlemail.com> wrote:

I'm trying to define a 2-dimensional list in a resources *** Variables
*** section. After that I want to iterate over this list in a test
case. I'm can't figure out how to accomplish this. What I've tried:

In a separate resource file I'd like to create a two dimensional
array:

*** Variables ***
@{app1}  Application One   None  00897-0000  True  False
@{app2}  Application Two   None  06455-0000  True  False
@{applications}   @{app1}   @{app2}

At this point I believe you end up with a list variable that looks like this:
@{applications}   Application One   None  00897-0000  True  False  Application Two   None  06455-0000  True  False


In a test file I'm looping over the 2-dimensional array:
A simple test
   :FOR  ${app}  IN  @{applications}
   \   Log  ApplicationName: @{app}[0]

So when you use it in your for loop, scalar variable ${app} will have value "Application One", and then in the next iterarion, "None", and so on.


Maybe you want to check User Guide in section "Using several loop variables" (In section 2.8.3) [1]. This would work if your use case is an heterogeneous bi-dimensional list (each sub-list have the same length). I.e @{app1}, @{app2}, and @{appN} have same number of elements.




[1] - http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html?r=2.6.2#using-several-loop-variables
Reply all
Reply to author
Forward
0 new messages