3

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 =\

1
  • Is this in a keyword, or in a variable file? Commented Apr 13, 2015 at 10:45

1 Answer 1

6

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.