If you have to compare files when you're testing, you've probably come across TestComplete's File Compare checkpoint. This feature allows you to see if two files are identical at the binary level. However, you're probably also interested in seeing what specifically about those two files are different. To help with that, TestComplete allows you to integrate with a number of 3rd party diff tools. In this article, you'll learn how to integrate WinMerge with TestComplete.
WinMerge is a free open source file comparison utility, which can be downloaded from this location. http://winmerge.org/downloads/ Once you've downloaded and installed WinMerge, you're ready to connect it up to TestComplete. To do this, launch TestComplete and go to Tools>Options. In the Options dialog, expand the Engines node, and then select Stores. Under the Files Diff Utility heading:
- Check the Active box.
- In the Diff Name field, click the elipses button and browse to where you installed WinMerge. (Typically C:Program FilesWinMergeWinMergeU.exe)
- In the Command Line Options field, enter /e /x /s /u "%s" "%s" (Each option is explained below)
- Make sure the Wait Until Diff Closes box is unchecked.
- Click OK
Here's a brief description of what each of the command line options used in Step 3 do:
/e enables you to close WinMerge with a single Esc key press. This is useful when you use WinMerge as an external compare application: you can close WinMerge quickly, like a dialog. Without this parameter, you might have to press Esc multiple times to close all its windows.
/x closes WinMerge (after displaying an information dialog) when you start a comparison of identical files. The parameter has no effect after the comparison, for example if the files become identical as a result of merging or editing. This parameter is useful when you use WinMerge as an external compare application, or when you want to eliminate unnecessary steps by ignoring files that don't have any differences.
/s limits WinMerge windows to a single instance. For example, if WinMerge is already running, a new compare opens in the same instance. Without this parameter, multiple windows are allowed: depending on other settings, a new compare might open in the existing window or in a new window.
/u prevents WinMerge from adding either of the files being compared to the Most Recently Used (MRU) list.
"%s" represents the name & path of a files that will be used in the comparison.
Now, when a file checkpoint fails, TestComplete will automatically invoke WinMerge and perform a file comparison. Let's try it out. We'll create two files with slightly different content, and then create a file comparison checkpoint. To create the files that will be used in the comparison:
- Launch the sample Orders application that ships with TestComplete. This is typically located at C:Program FilesAutomated QATestComplete 6SamplesOpen AppsOrdersDemoC#binDebugOrders.exe.
- Click File>Open, and select C:Program FilesAutomated QATestComplete 6SamplesOpen AppsOrdersDemoMyTable.tbl.
- Click Report>Generate Customer List. A Save dialog appears. Save the file as custList1.txt and note its location for later.
- In the Orders application, right-click on the Charles Dodgeson entry and select Edit. In the dialog that appears, change the Customer Name to Lewis Carrol and click OK.
- Click Report>Generate Customer List. Save the file as custList2.txt and note its location for later.
- Close the Orders application. Do not save changes.
In TestComplete, click the Create File Checkpoint button. In the File 1 and File 2 fields, browse out to custList1.txt and custList2.txt, respectively. Accept the rest of the default values. Your code should look something like this:
When you right click inside this function and run it, TestComplete compares the two files, and then launches WinMerge, which highlights the differences between the files. The test log panel contains a line marked Files.Compare result. If you accidentally close WinMerge, you can click on the Files1.batx link in the Test Log's Link column, and TestComplete will redisplay WinMerge with the file differences highlighted.
So now you can quickly and easily see what's caused a file checkpoint to fail. Until next time, onward automation!