← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #188776]: Can't keep error handler from running

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
I am not really sure about your intention using observe, but these are
the problems:

--- specifying observe handler

this is the rule and recommendation for an inline observation (script
waits at observe):

def handler(event):
    event&region.stopObserver()

onAppear(img, handler)
observe(FOREVER)

You have:
SeaTowArea.onAppear(WeatherAlert, weatherAlertHandler(WeatherAlert))

this calls weatherAlertHandler every time the script processes
onAppear() (not your intention i guess). The second parameter has to be
a reference to a function (so only its name !).

so if your intention is to wait for the event at every setUp() (which is
processed before every test case in that class), the code has to be like
this:


import unittest

def weatherAlertHandler(event):
    event.region.stopObserver() # here we stop the observer
    if exists(WeatherAlertNoBtn):
       click(getLastMatch())
    else:
       print("In weatherAlertHandler")
       assert exists(WeatherAlertNoBtn)

class SeaTowTests(unittest.TestCase):

    def setUp(self):
        print("setting things up")
        SeaTowArea = find(SeaTowSim)
        SeaTowArea.highlight(3)
        SeaTowArea.onAppear(WeatherAlert, weatherAlertHandler)
        SeaTowArea.observe(FOREVER) # here the script waits FOREVER for the event

    def testX(self):
         assert True

#     a bunch of tests...

    def tearDown(self):
        print("tearing things down")
        if exists(BackDayBtn):
            click(getLastMatch())
        elif exists(BackNightBtn):
            click(getLastMatch())

BTW:        SeaTowArea.stopObserver()
in tearDown() will never work, since SeaTowArea is a local variable in setUp() and thus undefined in tearDown()

Since I do not know your intention, I stop here for now.

Come back if you need more help.

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