Invoking mouseover, mouseout, etc.

Last edited on

Overview

Squish does not record onmouseover/onmouseout activities, which causes replay to fail because the objects being shown, because the mouse does not hover over the area or object in the web page.

Solution #1: Record mouse click instead, and consider mouseMove()

One workaround to this can be to record a mouse click on the respective area/object, as this will usually trigger onmouseover/onmouseout events.

Most of the time it is then also possible to change the recorded mouseClick()/clickLink(), etc. command to the mouseMove() command, so that the mouse gets moved over the desired object to trigger the onmouseover action.

So change...

def main():
    ...

    clickLink(waitForObject(names.Something_A))

    ...

...to...

def main():
    ...

    #clickLink(waitForObject(names.Something_A))
    mouseMove(waitForObject(names.Something_A), 5, 5)

    ...

Solution #2: Execute JavaScript via evalJS()

It may be possible to execute the respective JavaScript that would be executed upon hovering the mouse over the target object:

def main():
    startBrowser("http://www.cs.runet.edu/~pac/mouseover/")

    test.log("Execute same code as onmouseover/out declaration in HTML via evalJS()")
    for i in range(5):
        # Executing same code as onmouseover:
        evalJS("document.myimage.src='pic1.jpg'")
        snooze(1)

        # Executing same code as onmouseout:
        evalJS("document.myimage.src='pic2.jpg'")
        snooze(1)
test.py

Solution #3: Executing event handlers via invoke()

It may be possible to execute the desired event handlers of the target object yourself:

def main():
    startBrowser("http://www.cs.runet.edu/~pac/mouseover/")

    # Initially recorded for a mouse click:
    #
    #   clickLink(waitForObject(names.myimage_A))
    #
    # We use the real name for names.myimage_A instead to keep
    # this script reusable without the respective object
    # map entry:
    o = waitForObject({"img_name": "myimage", "tagName": "A"})

    test.log("Invoking mouseover/out handlers via invoke()")
    for i in range(5):
        o.invoke("onmouseover")
        snooze(1)

        o.invoke("onmouseout")
        snooze(1)
test.py

Solution #4: Executing event handlers via sendEvent()

It may be possible to execute the desired event handlers of the target object yourself:

def main():
    startBrowser("http://www.cs.runet.edu/~pac/mouseover/")

    # Initially recorded for a mouse click:
    #
    #   clickLink(waitForObject(names.myimage_A))
    #
    # We use the real name for myimage_A instead to keep
    # this script reusable without the respective object
    # map entry:
    o = waitForObject({"img_name": "myimage", "tagName": "A"})

    test.log("Invoking mouseover/out handlers via sendEvent()")
    for i in range(5):
        sendEvent("mouseover", o, 1, 1, 0, 0)
        snooze(1)

        sendEvent("mouseout", o, 1, 1, 0, 0)
        snooze(1)
test.py

evalJS()

HTML_Object.invoke()

sendEvent()