← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #257314]: How to handle network lag when UI script is invoked on systems with different hardware configuration

 

Question #257314 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/257314

    Status: Open => Answered

Eugene S proposed the following answer:
Hi,

Theoretically, there are 2 types of waits that can be used for automation:
- Implicit
- Explicit 

What you have just demonstrated - is an implicit waits. It waits for a
certain amount of time when trying to find an if they are not
immediately available. This approach is prone to errors, just like it
happens in your case, when you will get a timeout before the pattern
appeared in the screen. Setting a longer wait time is not always a good
idea since it will slow down the whole script even if that's not needed.

What you should do - is to implement an explicit wait. That means that
you have to wait for a condition rather than just wait for a predefined
period if time. So try to find something on the screen that indicates
the fact that your previous action was completed. For example, if you
click a button and it takes you to another screen, wait for an element
that appears on that screen. Keep in mind that you still have to set
some kind of timeout to avoid waiting forever.

For example:

retries = 10

for i in range (retries):
    try:
        find(object)
        print "Object found!"
        break
    except:
        print "Object was NOT found, retrying..."
        time.sleep(1)

Such script will wait for "object" to appear on the screen for 10 OR
LESS seconds.


Eugene

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.