17.14. How to Create Automatic Screenshots on Test Failures and Errors

To make it easier to track down the causes of test failures and errors, it is possible to tell Squish to take a screenshot whenever a test fails or has errors. We can then view the screenshot of the complete desktop taken at the time the failure or error occurred. This is especially helpful when it comes to the debugging of test failures and errors that occur during unattended automated test runs.

To enable this feature, it is necessary to set the global settings object, testSettings Object (Section 18.3.15)'s logScreenshotOnFail and/or logScreenshotOnError properties to true (or True or 1 depending on your scripting language—see Equivalent Script API (Section 18.2).).

Once one or both of these properties are activated, all tests that result in failures or errors will produce a message text that contains the path to an image file that contains the saved screenshot.

In the Squish IDE the screenshots can be viewed by clicking them in the Test Suites view (Section 20.2.16)'s Test Case Resources list's VPs tab. (In addition, on some platforms, clicking or double-clicking a failed image will invoke a platform-specific image viewer showing the image.) If an image verification has failed we can see how it differs from the expected image using Squish's Screenshot Verification Point dialog (Section 20.3.12). This is done by running the test that produces the failed image to populate the Squish IDE's Test Results with the failures indicated by a “Fail” result if this hasn't been done already. Then right click any failed screenshot comparison to invoke the context menu and then click the View Screenshot Differences menu item to pop up the Screenshot Verification Point dialog (Section 20.3.12).