How to log exact mouse click positions within screenshot results

How to log exact mouse click positions within screenshot results

ClickHit-SquishAutomationWith screenshot verifications, a failed test run shows us the differences between the expected vs actual images, but in some cases, the actual image is missing, or is missing important information.



The option ‘testSettings.logScreenshotOnFail = True’, gives us a logged screenshot taken at the moment the fail happens, and this can be helpful, but these logged screenshots are ‘plain’ screenshots, showing the whole screen. These images do not always make clear where useful details may be located. Having more information here would be helpful, for finding out what could have gone wrong.

In this article I will show us how it’s possible to generate more detailed error/fail images which can be logged with the test results. In most cases, ‘useful information’ is information about ‘where’ a mouse click actually has hit some involved object.

One way to log mouse click coordinates, is to draw them into the image data which is logged with the results. I’ve written a small command line tool which can draw mouse click coordinates into our resulting screenshot images.

The tool can be installed into the Squish package you are using, which we call <SQUISHDIR>. To install it, just download the zip package, and extract to some folder. In there, find the sub-directory naming your platform, enter it, and call the install script:


(* An uninstall script also will by placed into the squish package, which will remove imageprocessor from the package again when called)


Included in the package is a small Python script, providing functions which can be used for overriding Squish’s regular interaction functions. For this example, I will override the Squish functions mouseClick() and clickLink() to use a function clickShotClick() which the image processing script provides.

This function generates and passes to the image processing tool, a command line from the given object and click position arguments. From this generated command, the image processor tool draws a ‘CrossHair’ marker to the plain screenshot image, which was generated by saveDesktopScreenshot() or logScreenshotOnPass and logScreenshotOnFail just before.

Once you override Squish’s regular mouseClick() or clickLink() with this function, recording scripts  produces screenshots containing a visual marker at the mouse position.

# just include the script containing the functions:

# and use it for overriding some of Squish's interaction functions:
SquishMouseClick = squish.mouseClick
SquishClickeLink = squish.clickLink
mouseClick = clickShotClick
clickLink = clickShotClick
# ..


(*Additionally, For getting more detailed information about overriding Squish’s pre-implemented interaction functions, I would suggest to read  blog article: Tip-Of-The-Week by Clemens Anuth: Overriding Squish functions.)

Now in the script, you can define scopes where recording and playback will make usage of the clickShotClick() function instead:

Enable automatic generation of mouse click position markers for any click recorded on a given canvas objects (or even whole browser window or image objects)

    # enable 'ClickShots' for some canvas view: 
    # ... do some recordings...


any regular recorded clicks in the given canvas view now will log ‘ClickShot’ images which should contain exact hit positions on the canvas.

To stop automatic click shot generation, call:

    # ... when finished testing on thie canvas:
    # ..



Result screenshots now looking as follows:

Images like these now are added to our test’s result outputs, which show actual click hit coordinates:

'ClickShot' hit cube at the corner


'ClickShot' hit cube's eye

Related links:

download package: example material (image tool & python script + example test suite )

Tip of the week: Overriding Squish functions (by Clemens Anuth)



Leave a reply

Your email address will not be published. Required fields are marked *