0

I need to iterate for loop till certain condition meets in Robot Framework.

${counter}=  Set Variable  1

    :FOR    ${item}    IN RANGE    ${counter}
    \    Check condition
    \    ${counter} = ${counter} + 1

Is it possible to increase the ${counter} variable value here?

enter image description here

Laurent Bristiel
  • 6,819
  • 34
  • 52
Looking Forward
  • 3,579
  • 8
  • 45
  • 65
  • What you want to use is a while loop, robot framework has not implemented this yet. See: https://stackoverflow.com/questions/36328595/how-to-write-a-loop-while-in-robot-framework Apparently there is a workaround: https://github.com/robotframework/robotframework/issues/3235 – Ryan Mar 04 '20 at 22:51

2 Answers2

2

Yes.

${counter}=    Set Variable     1
FOR    ${item}    IN RANGE    1     20
    ${counter}=     Evaluate     ${counter} + 1
    Log To Console    ${counter}
    Exit For Loop If     ${counter} == 10
END

And FOR loops can be exited using Exit For Loop or Exit For Loop If keywords. Keywords documentation.

EDIT after comments.

asprtrmp
  • 1,034
  • 5
  • 14
0

You're asking about a while loop. Robot doesn't have a while loop. There's simply no support for it, and robot probably won't support it until at least 2021. The only looping construct is a for loop.

You seem to have an aversion to setting a limit of 20, but there must be a practical limit to the number of iterations, whether it's 1,000, 10,000, or 1 million or more. Just use a FOR loop that has a huge upper limit, and for all intents and purposes you've created a while loop.

FOR    ${item}    IN RANGE    1000000
    Exit FOR loop if  <some condition>
    ${counter}=  evaluate  $counter + 1
END

While it doesn't look quite as pretty as While <some condition>, the end result will be the same, assuming your condition becomes true at some point before one million iterations.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Thanks @Bryan. Yes, I know that Robot doesn't have while loop mechanism. That's why I was trying to use for loop iteration till certain condition meets. I thought of implementing logic in python (.py file) also but for my project work, it was not feasible. Nevertheless, Thank you. – Looking Forward Mar 05 '20 at 06:54