0

假设我想及时点击新对话框中包含的按钮,这个对话框就会出现。我的事件处理程序应该是什么样子?

例子:

def handleMyNewDialogAppeared():
    mouseClick(waitForObject(":MyButtonOnNewDialog"), MouseButton.LeftButton)

def main():
    startApplication("myapp")
    installEventHandler("if dialog :MyNewDialog appeared", 
                        "handleMyNewDialogAppeared")
4

2 回答 2

0

有一个名为“DialogOpened”的特定事件,但它会挂钩每个对话框。然后,您可以检查处理程序是否是您需要的对话框,如下所示:

def handleMyNewDialogAppeared(Dialog):
    if str(Dialog.windowTitle) == "My Dialog's Title":  # whatever suits your needs
        mouseClick(waitForObject(":MyButtonOnNewDialog"), MouseButton.LeftButton)

def main():
    startApplication("myapp")
    installEventHandler("DialogOpened", "handleMyNewDialogAppeared")

但是,我只有 Qt 的 squish,所以我无法在 Windows 上验证这一点。

于 2015-11-05T11:37:07.097 回答
0

I've never user the eventHandler from Squish. Instead of this (my problems is that all my objects are dynamic) I've created a custom wait function of mine. It works for all objects, no matter of their form/type.

This functions waits until an object is true.

def whileObjectFalse(objectID, log = True):
    # functions enters in a while state, as long as expected object is FALSE, exiting when object is TRUE 
    # (default timeout of [20s])

    start = time.time()# START timer
    counter = 40
    object_exists = object.exists(objectID)
    while object_exists == False:
        object_exists = object.exists(objectID)
        snooze(0.5)
        counter -= 1
        if counter == 0:
            test.fail(" >> ERR: in finding the object [%s]. Default timeout of [20s] reached!" % objectID)
            return
    if log == True:
        elapsed = (time.time() - start)# STOP timer
        test.log("    (whileObjectFalse(): waited [%s] after object [%s])" % (elapsed, objectID))
    snooze(0.5)

So basicaly, your code will be like this:

def whileObjectFalse(objectID, log = True):
        start = time.time()# START timer
        counter = 40
        object_exists = object.exists(objectID)
        while object_exists == False:
            object_exists = object.exists(objectID)
            snooze(0.5)
            counter -= 1
            if counter == 0:
                test.fail(" >> ERR: in finding the object [%s]. Default timeout of [20s] reached!" % objectID)
                return
        if log == True:
            elapsed = (time.time() - start)# STOP timer
            test.log("    (whileObjectFalse(): waited [%s] after object [%s])" % (elapsed, objectID))
        snooze(0.5)


def main():
    startApplication("myapp")
    whileObjectFalse("NewDialog")
    mouseClick(waitForObject(":MyButtonOnNewDialog"), MouseButton.LeftButton)
于 2015-09-11T11:15:46.373 回答