For loop using robot framework with 2 parameters

I have two list variables @{vinrange} and @{sg} both with same dimensions of 4 enter image description here

I want to print into the LOG using the scalar ${VAR1} for each value from the list variable @{vinrange} and print using a second scalar ${VAR2} for each value from the list variable @{sg}

I have to assign both of them into the same loop, the ${VAR1}[1] has worked for the @{vinrange}, however, I don't know how to do for the second list variable @{sg}.

enter image description here

Upvotes: 3

Views: 7192

Answers (3)

Todor Minakov
Todor Minakov

Reputation: 20067

There is a FOR construct version precisely for this situation - to iterate over two lists simultaneously - that is with IN ZIP, link to the documentation .
It expects two or more iterables (like lists), and on every iteration returns the values of each at the same index.

Note that it will stop at the shorter one's last element (e.g. if their lengths are different, it won't raise an exception, nor it will fully exhaust the longer list). So for your case:

FOR    ${vinrange_element}    ${sg element}    IN ZIP     ${vinrange}       ${sg}
     Log      ${vinrange element} 
     Log      ${sg element}
END

Upvotes: 6

Humble_PrOgRaMeR
Humble_PrOgRaMeR

Reputation: 741

A Generic Context of For Loop in robot framework is

FOR    ${item}    IN    @{ITEMS}
    ${item}    Arg2
END

Example-

FOR    ${index}    IN RANGE    42
    1st arg    ${index}
END

Upvotes: 0

Sidara KEO
Sidara KEO

Reputation: 1709

Try to count your list by use Get Count than FOR LOOP and log by using Iterator ${i}. Here sample for you

${length}=   Get Count   ${vinrange}
FOR    ${i}    IN RANGE     1       ${length}
     Log      ${vinrange}[${i}]
     Log      ${sg}[${i}]
END

Upvotes: 3

Related Questions