Troubles using Region -> On Vanish

Asked by Razvan

Hello,

I am new to Sikuli and am still struggling to fully understand the depths of the commands.

I am trying to create a script that tests the display of a CAD program when viewing a CAD 3D model, by pressing the " top" ,"isometric" , " fit to screen " , " front " views buttons .
I am comparing for the same sample model. Therefore, I have made screenshots of the desired views and am comparing them to the screenshots automatically taken by Sikuli . I am using Region On Vanish function to issue a warning in case pressing one of the views buttons does not result in the desired view.
The problem is that the screenshot that is taken by the region to compare with my images is taken before pressing each of the buttons . In the first two buttons , I don't get a warning , because the image is the same before and after pressing each of the fit and isometric buttons . But after I press " Top " , the region takes a screenshot of before the click and compares it with the image of the top view . Therefore I get a warning . This repeats for the next buttons .

I find Sikuli a very interesing and useful tool and would really want to understand this issue to get over to the next level with it :)

My code is the following :

App.open('the CAD software')
click("open icon")

type(Region(1517,369,121,12),'path to file')
click(Region(1568,791,96,15))
type('cad file') #click on the region to write the path to the model's file and then type the file's name
click("Open.png")
click("1439209406111.png") #open and load the model
def warning(event):
    switchApp("C:\\Program Files (x86)\\Sikuli X\Sikuli-IDE.exe")
    print("warning")
    stopObserver()

wait(7)

click("Fit.png")
wait(3)

with Region(Region(275,167,1031,791)):
    onVanish("1439365790828.png",warning) #if the desired image is not found in the region, issue a warning
    observe(3)
    stopObserver()
wait(3)

click("lsometric.png")
wait(3)
with Region(Region(275,167,1031,791)):
    wait(3)
    onVanish("1439365790828.png",warning)
    observe(3)
    stopObserver()
    wait(3) #the same . in these first two instances , I don't get a warning , as I explained in the beginning of my post

click("Top.png")
with Region(Region(276,166,1220,795)):

    onVanish("1439365822091.png",warning)
    observe(3)
    stopObserver()
    wait(3) #here I get a warning , because the screenshot that the region takes and compares it to
                                                                          my image is before clicking on the top button, even though the command to click on the
                                                                          button comes before the region selector.

with Region(Region(276,166,1220,795)):
    click("Front.png")
    wait(3)
    onVanish("front desired view",warning)
    observe(3)
    stopObserver() #same issue here.

wait(5)
click("exit.png")

I tried to include the next region capture in the previous region actions ( with TAB ) , but this didn't work too. I tried introducing another event , another intermediary region defined-action ,delays , etc , but nothing seemed to work .

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

you should try to solve your problem without using observe:
use wait() or exists() instead.

If you want to use observe, you should switch to the latest version: http://sikulix.com

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

instead of onVanish() you could use:

while exists(image,0):
    wait(1) # look again after 1 second
# continue after the image is no longer there

Revision history for this message
Razvan (razvan-c-2006) said :
#3

Thanks RaiMan, that solved my question.