Search code examples
automated-testsrobotframework

How to write a loop while in Robot Framework


I make my first simple test case, and I have one problem.

Is it possible write a loop in Robot Framework?

I want to retrieve the value from the address and the address of the modified variable "i". I want to perform until such an address exists, because it is a row in the table.

${f1}       A
${f_temp}   B

While   ${f1} != ${f_temp}
or
While element xpath=//${i} is visible


\  ${F_temp}                Get Text     xpath=//${i}
\  ${i}                     ${i}+1
\  Run Keyword And Continue On Failure   Should be equal  ${f_temp}  ${f1}

Any ideas?


Solution

  • I'm updating my answer because modern Robot Framework does have a while loop.

    The old answer, do not use this: Robot Framework does not have a while loop. You must use the FOR-loop and "exit for loop if" keywords to exit. It will run in a finite time, but if you select a large enough number in range, it is close enough for practical purposes.

    *** Test Cases ***
    For Test
        FOR    ${i}    IN RANGE    999999
               Exit For Loop If    ${i} == 9
               Log    ${i}
        END
        Log    Exited