事件处理程序,用于使用python在压缩时出现新的特定对象



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

的例子:

def handleMyNewDialogAppeared():
    mouseClick(waitForObject(":MyButtonOnNewDialog"), MouseButton.LeftButton)
def main():
    startApplication("myapp")
    installEventHandler("if dialog :MyNewDialog appeared", 
                        "handleMyNewDialogAppeared")

我从来没有使用过Squish的eventandler。而不是这样(我的问题是我所有的对象都是动态的),我创建了一个自定义的等待函数。它适用于所有对象,无论其形式/类型如何。

该函数等待对象为真。

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)

基本上,你的代码是这样的:

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)

有一个名为"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的压缩,所以我不能验证这对于windows。

相关内容

  • 没有找到相关文章