When testing applications, you may need to compare different files. This is often done to make sure that the tested application generates the same output data (for example, a list of orders) as in previous application runs. With TestComplete, you can verify files by using file checkpoints that perform a byte-to-byte comparison of the actual file contents and the baseline file stored in your project.
File checkpoints take the following parameters:
-
FileName - Specifies the name of the file to be verified.
-
AllowedDifference - Specifies the amount of dissimilarity between two files.
File checkpoints can operate in the following two modes:
-
Strict verification - Verification is successful only if the files are identical. To perform verification in the strict manner, assign 0 to the Allowed Difference parameter.
-
Verification with a permissible variation - This specific verification is successful if the files are identical or if one file differs from the other and this level of difference is allowed.
When the file is smaller than or equal to 50 Mb, TestComplete performs elaborate comparison (ignoring whitespaces, character displacement, and so on) and reports the first 200 000 lines in the log. When the file is larger than 50 Mb, TestComplete uses a more simplified comparison mechanism and reports only the first missmatch.
You can configure TestComplete to use a third-party diff utility for file verification:
-
Open the Options dialog and select Engines | Stores element in the tree on the left pane.
-
Select Active check box in the Files diff utility group of options.
-
In the Diff name box, specify the name along with the full path of the diff utility you want to use.
-
In the Command line box, specify command-line parameters to be passed to the utility.
When you run the test, the file checkpoint uses the specified diff utility for file verification.
Verifying Files in a Strict Manner
To perform verification in a strict manner, assign 0 to the AllowedDifference parameter. 0 will also be used by default if you omit the parameter in the file checkpoint call.
The following code demonstrates how you can use the file checkpoint to strictly verify a file with its baseline copy stored in the Stores | Files collection:
JavaScript, JScript
Python
Files.OrdersList_old.Check("C:\\Work\\OrdersList.txt");
VBScript
DelphiScript
C++Script, C#Script
If the AllowedDifference is 0, the file checkpoint is passed successfully and returns True only if the actual and the expected file contents are absolutely the same.
Verifying Files Taking into Account the Allowed Difference
There can be situations when the verified and the expected files are not absolutely identical, but they still should be considered equal. For example, this can be necessary when the application under test generates successful reports of two kinds. In this case, you can use a couple of simple verifications or specify a value of the allowed difference and verify the files.
To implement the second approach, use the AllowedDifference parameter of file checkpoints. Unlike the conventional allowed difference that is the “fingerprints” of a single file, the AllowedDifference parameter specifies the amount of dissimilarity between two files.
If the file verification fails, TestComplete calculates the number of bytes that are different in the actual and the expected files and posts it to the Details panel of the test log.
Use that value to specify the AllowedDifference parameter of the file checkpoint.
The following code snippet demonstrates how to use the parameter:
JavaScript, JScript
…
var PrecalculatedDifference = "Value_From_the_Additional_Information_Panel";
Files.OrdersList_old.Check("C:\\Work\\OrdersList.txt", PrecalculatedDifference);
…
Python
...
PrecalculatedDifference = "Value_From_the_Additional_Information_Panel"
Files.OrdersList_old.Check("C:\\Work\\OrdersList.txt", PrecalculatedDifference)
...
VBScript
…
PrecalculatedDifference = "Value_From_the_Additional_Information_Panel"
Files.OrdersList_old.Check "C:\Work\OrdersList.txt", PrecalculatedDifference
…
DelphiScript
var PrecalculatedDifference : integer;
begin
PrecalculatedDifference := 'Value_From_the_Additional_Information_Panel';
Files.OrdersList_old.Check('C:\Work\OrdersList.txt', PrecalculatedDifference);
end;
C++Script, C#Script
…
var PrecalculatedDifference = "Value_From_the_Additional_Information_Panel";
Files["OrdersList_old"]["Check"]("C:\\Work\\OrdersList.txt", PrecalculatedDifference);
…
See Also
File Checkpoints
About File Checkpoints
Verifying Files With Variable Parts
About Files Collection