Posted September 20, 2006
TestComplete Tip: How to take a screenshot of every failed test
Would you rather type two pages describing a failed test or just show someone a picture of the problem?
A screenshot is often the best way to describe a failed test. Here's how to configure your TestComplete project to add a screenshot to the test log every time an error is logged.
1.In TestComplete, open your project tree in the Project Explorer and confirm that the Events node is listed.
2. Double click on the GeneralEvents node to display the General Events panel in the Workspace.
3. Click on Event Handlers button next to the Type Library button at the bottom of the GeneralEvents panel to display a list of events.
4. Double-click the OnLogError row to display the New Routine dialog.
Click the OK button to accept the default event name and file. You could also create a new file or select a different file unit if you like. I recommended you leave the routine name the same.
5. TestComplete will add a new event to your unit and configure the project so the new event will be called every time an error is logged. The Workspace will display the editor window for the unit containing the event function, GeneralEvents_OnLogError.
6. The new event function needs something to do. Paste a Log.Picture line into the function so that it looks like this:
Log.Picture(Sys.Desktop, "Error screenshot");
7. Run your test and now every time an error is logged, TestComplete will add a full screen screenshot to the log. Since the event is called just before the error is added to the log, the screenshot will be listed just before the error message in the log.
- If the Events node is missing, right-click on the project name and select Add | New Item to add Events to your project.
- If the GeneralEvents node is missing, delete the Events node and add it again to create a new GeneralEvents node.