Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 463
grandecalvo Avatar asked Mar 31 '16 08:03

grandecalvo


People also ask

Can we use while loop in Robot Framework?

A common need in programming is repeating one or more operations until a condition is met. In Robot Framework and Python, this can be done with a while loop. The native WHILE loop is supported starting from Robot Framework version 5.

How do you write if condition in robot framework?

END Use Run Keyword If in Robot Framework Run Keyword If ${True} Log This line IS executed. Run Keyword If ${False} Log This line is NOT executed. Use Run Keyword Unless in Robot Framework Run Keyword Unless ${True} Log This line is NOT executed. Run Keyword Unless ${False} Log This line IS executed.

How do you run a test case multiple times in Robot Framework?

For example, if you are running tests on the current folder, you can pass "." as many times as you want the test to run. Ex: robot -t "*My test*" . . . This command will run all tests that match the expression 3 times, and the report will contain all 3 executions and results.


2 Answers

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
like image 129
Pekka Avatar answered Sep 18 '22 07:09

Pekka


You might be looking for the Wait Until Keyword Succeeds keyword, which enables you to do a similar construction to a while loop. It is much more readable than FOR cycles with conditional exiting.

You then use your custom keyword, which fails when you need to end the "loop".

like image 25
ojinmor Avatar answered Sep 21 '22 07:09

ojinmor