In Robot framework any keyword for while and do-while operations?

10,511 views
Skip to first unread message

Ramakrishna kolli

unread,
Jul 23, 2014, 11:39:44 PM7/23/14
to robotframe...@googlegroups.com
Hi all,

im looking for infinite loop or loop with some conditions , so please comment if any keywords works like while and do-while operations.

Thank you.......

Laurent Bristiel

unread,
Jul 24, 2014, 5:29:34 AM7/24/14
to robotframe...@googlegroups.com
Robot doest not provide infinit loop and loop with condition.
But you should be able to do most of what you need with the basic syntax (:FOR ${var} IN RANGE x)
and using "Exit For Loop" to exit the loop in some condition (Run Keyword If    exit_condition    Exit For Loop)

HTH,
Laurent Bristiel

Aman Kashyap

unread,
Sep 30, 2014, 7:34:44 AM9/30/14
to robotframe...@googlegroups.com
HI Laurent Bristiel,

I am also looking for infinite loop.

Could you please help me with the condition to use in the :FOR loop to make it infinite loop?

Thanks,
Aman

Aman Kashyap

unread,
Sep 30, 2014, 8:39:35 AM9/30/14
to robotframe...@googlegroups.com
I am also looking for the same.....did you get the answer?

Kevin O.

unread,
Sep 30, 2014, 9:12:38 AM9/30/14
to robotframe...@googlegroups.com
What Laurent is saying is you could do something similar to:
:FOR    ${i}    IN RANGE    9999999999
    ${condition}=    Do Something
    Exit For Loop If    ${condition}

You would run out of memory before you hit the loop counter limit, so its essentially a do-while loop.

Sajjad Malang

unread,
Sep 30, 2014, 10:28:43 AM9/30/14
to ombre42, robotframe...@googlegroups.com



you can use "Wait Until Keyword Succeeds" by making the content of the loop into a keyword

http://robotframework.googlecode.com/hg/doc/libraries/BuiltIn.html#Wait%20Until%20Keyword%20Succeeds

Wait Until Keyword Succeeds timeout, retry_interval, name, *args

Waits until the specified keyword succeeds or the given timeout expires.

name and args define the keyword that is executed similarly as with Run Keyword. If the specified keyword does not succeed within timeout, this keyword fails. retry_interval is the time to wait before trying to run the keyword again after the previous run has failed.

Both timeout and retry_interval must be given in Robot Framework's time format (e.g. '1 minute', '2 min 3 s', '4.5').

If the executed keyword passes, returns its return value.

Examples:

Wait Until Keyword Succeeds 2 min 5 sec My keyword argument
${result} = Wait Until Keyword Succeeds 30 s 1 s My keyword

Errors caused by invalid syntax, test or keyword timeouts, or fatal exceptions are not caught by this keyword.

Running the same keyword multiple times inside this keyword can create lots of output and considerably increase the size of the generated output files. Starting from Robot Framework 2.7, it is possible to remove unnecessary keywords from the outputs using --RemoveKeywords WUKS command line option.





--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.



--
Regards,
\Sajjad.

Tatu Aalto

unread,
Sep 30, 2014, 2:43:18 PM9/30/14
to sajjad...@gmail.com, ombre42, robotframe...@googlegroups.com
Ugh

And as Pekka likes to say: It is best to put complex logic in a library keyword. And I totally agree with him. When I have urge to do long(ish) for loop (and sometimes I have that urge) in robot test data, the result are, well, at best not good and definitely not maintainable/readable. No matter how much documentation and comments I put in the keyword, I after a week, I have no idea why I did, how I can fix it (because quite soon, I have to fix it) and I have no idea what the heck the keyword is trying to do in that point.

So that said, if you really want to make while loop that executes a a keyword, in below is a simple and naive example how one can do it.

Please remember, that this will explode the memory consumption and the logs too. Some examples demonstrates the problem better, I did run my examples on pybot and Python 2.7.8. Running that loop 10 000 times did took on my PC about 12seconds, memory consumption was minimal and log sizes where less than 2Mb. Running loop 100 000 times did took about 2mins and other 3mins to generate the logs. The output.xml is almost 100Mb and log.html over 16Mb. To generate the log it did consume 350 - 400Mb of memory. I did not dare to run the loop 1 000 000 times.

So instead putting the complex logic in a keyword, build a library keyword and put the complex logic in there.

========== example.robot ===========
*** Settings ***
Library    example.py

*** Test Cases ***
example
    Set Test Variable
    ...    ${VALUE}
    ...    1
    Do While Loop    Foobar

*** Keywords ***
Foobar
    ${VALUE}    Evaluate    ${VALUE} + 1
    Set Test Variable    ${VALUE}
    [Return]    ${VALUE}
========== example.py ===========
from robot.libraries.BuiltIn import BuiltIn
from robot.api import logger


def do_while_loop(keyword):
    other_value = 0
    while other_value < 10:
        other_value = BuiltIn().run_keyword(keyword)
        logger.info(other_value)
===================

-Tatu
Reply all
Reply to author
Forward
0 new messages