contiously checking for error message while running test

Asked by shaihulud

While running a test on a application there is a risk that a specific warning will popup at many different places.
Im wondering if it possible to continously check for this warning so sikuli will click "ok" button when it appears.

Currently I need to call a Check() function after almost every action/line of code in sikuli just to be safe. (as the test is inteded to be running over night)

Check():
    if exists(warningpic):
        click(okpic)

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
obiwan-92
Solved:
Last query:
Last reply:
Revision history for this message
Eugene S (shragovich) said :
#1

Hi there,

I was wondering about the same issue myself however it seems like there is no straightforward solution to that.
The only thing I could think about is just trying to speed up things a bit. For example:

 - if you only want to check, wether an image is there or not without waiting for it the default of 3 secs you can try:
   exists(image, 0)

 - Since sikuli searches for an image on a whole screen, it might be quicker if a maller area is specified.

If there is a better practice I'll be happy to know about it.

Cheers,
Eugene

Revision history for this message
obiwan-92 (obiwan-92) said :
#2

Hello,

The answer is in this page : http://doc.sikuli.org/region.html
You have to see the observe function.

Have a nice day.
Reagrds.

Revision history for this message
shaihulud (cal-a) said :
#3

wow that looks interesting! I have tried to understand the doc you linked, plus other observe()related questions but am not able to make it work. So far I have written:

def hnd():
     click(Patternlocation)
onAppear(Patternlocation, hnd)
observe(background = True)

#the test (ie click this, click that etc)

stopObserver

What am I doing wrong?

Revision history for this message
Best obiwan-92 (obiwan-92) said :
#4

Hello,

Try this one :
r = Region(Screen(0).getBounds())
print "Region : ", r
def changed(event):
    print "Event : ", event
    for ch in event.changes:
        print "Changes : ", ch
        ch.highlight(3) # highlight all changes for 3 sec.
r.onChange(50, changed)
r.observe(10, background=False)

Regards.

Revision history for this message
shaihulud (cal-a) said :
#5

Interesting piece of code you´ve got there!
I changed it into what I thought would work for me:

r = Region(Screen(0).getBounds())
print "Region : ", r
def changed(event):
     click(PatternLocation)
r.onAppear(PatternLocation, changed)
r.observe(10, background=False)
#the test

What happened was that sikuli spent 10 seconds looking for the image to appear, then ran the test. (the rest of the code)
I want it to run the test while it´s looking for the image to appear.

Revision history for this message
obiwan-92 (obiwan-92) said :
#6

Replace the line r.observe(10, background=False) by r.observe(FOREVER, background=True)
Remember to call stopObserver() when you finish your test.

It should be work. ;)

Regards.

Revision history for this message
shaihulud (cal-a) said :
#7

unfortunately it still doesnt seem to work.
With the code:
r.observe(3, background=True)
And I have the image in which is to be observed in the background when I start the test it observes the image as it should. But with the code:
r.observe(FOREVER, background=True)
It doesn´t observe the image, even when it is visible when i start the test, and the test wait(3) before continuing.

Revision history for this message
RaiMan (raimund-hocke) said :
#8

A bug with FOREVER

... use a large value instead

Revision history for this message
shaihulud (cal-a) said :
#9

Its working yippie! :)

Revision history for this message
shaihulud (cal-a) said :
#10

Thanks obiwan-92, that solved my question.