Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set variable name in loop in Robot framework

Broken with following task: i want to set the name of variable in loop, like:

for i in 10:
    ${i}line = some value

How this can be done in Robot framework and if this is possible?
Thank you.
P.S. Sorry for dummy questions =\

like image 746
AndriiZ Avatar asked Jul 11 '26 14:07

AndriiZ


1 Answers

FOR / IN Scenario:

FOR/IN statement is used as a loop for items in f.e. lists. The example below has these steps:

@{list}=    Create List    Var1    Var2    Var3
${index}    Evaluate    1
${line}    Set Variable    line
:FOR    ${i}    IN    @{list}
        Set Test Variable    ${${index}${line}}    ${i}
        ${index}    Evaluate    ${index}+1
  1. Create list with some variables

  2. Run loop through the list

  3. Set dynamic test variable by catenating the ${index} value with ${line} string. This test variable holds the ${i} value looped from @{list}.

  4. Evaluate index value by 1

Results:

${1line} = Var1
${2line} = Var2
${3line} = Var3

FOR / IN RANGE Scenario:

However, we can use range loop if the scenario requires running loop for certain number of times.

${line}    Set Variable    line
:FOR    ${i}    IN RANGE    10
        Set Test Variable    ${${i}${line}}    ${i}

${i} variable is raised by one each time we use loop until the range 10 is reached.

Results:

${1line} = 1
${2line} = 2
....
${10line} = 10
like image 50
Tomas Chudjak Avatar answered Jul 14 '26 19:07

Tomas Chudjak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!