Description
The behavior of this method depends on whether the update feature is enabled and AllowedDifference is specified.
Usually, the Check
method performs a byte-by-byte comparison of the specified Stores item and an external file. If the files are identical, the method returns True. If the files differ, it returns False.
During the comparison, a special value that indicates the difference between the two files is calculated. After that, this value is compared with the value of the AllowedDifference parameter. If the calculated value equals zero or AllowedDifference, the compared files are considered identical. See How File Verification Works for a detailed description and examples.
Note: | Instead of the File string, you must enter the name of the needed Stores item, for example:
JavaScript, JScript Files.MyFile_txt.Check("D:\\MyDocuments\\MyFile.txt", 100);
Python
VBScript Call Files.MyFile_txt.Check("D:\MyDocuments\MyFile.txt", 100)
DelphiScript Files.MyFile_txt.Check('D:\MyDocuments\MyFile.txt', 100);
C++Script, C#Script Files["MyFile_txt"]["Check"]("D:\\MyDocuments\\MyFile.txt", 100);
|
However, if the update feature is enabled (that is, if both the global Update files option and the stored file’s Update option are checked), the method updates the specified stored file during the script execution. In this case, the Check
method replaces the stored file with the file specified as a parameter of the method, posts a message reporting that the file was updated to the test log and always returns True.
Declaration
FileObj.Check(FileName, AllowedDifference)
FileObj | An expression, variable or parameter that specifies a reference to a File object | |||
FileName | [in] | Required | String | |
AllowedDifference | [in] | Optional | Integer | Default value: 0 |
Result | Boolean |
Applies To
The method is applied to the following object:
Parameters
The method has the following parameters:
FileName
Specifies the fully-qualified name of the file to be compared.
AllowedDifference
This parameter is used during the comparison with permissible variations. It specifies the reference value of the allowed difference between the files in bytes (0 means that the files are physically identical). The Check
method calculates the value of the actual difference between the files and compares it with the value passed as AllowedDifference. If these values coincide, the method assumes that the files are identical. Otherwise, the method fails, TestComplete posts an error message to the test log, and the Details panel displays the actual value of the difference. You can use this value in future comparisons.
For more information, see File Checkpoints and How File Verification Works.
Do not obtain the value of the difference every time when you are going to perform a file comparison. You should calculate the difference once and then use this value in future comparisons. Otherwise, if you calculate the value of the difference right before performing a comparison and then use it in the Check method, the comparison will always be successful even if the compared files are not identical. |
Result Value
In comparison mode, if the comparison procedure reports that the files are identical, the method returns True and posts a checkpoint message () to the test log. Otherwise, the method returns False and posts an error message () and a checkpoint message to the test log.
In update mode, the method always returns True.
Remarks
If the Check
method returns False, TestComplete posts an error message and a checkpoint message to the test log. The Details panel contains the total number of differences between the Stores item and the specified file. To obtain detailed comparison results, click the Details link that is shown in the Link column of the test log. TestComplete opens the File Comparison Result panel that shows differences between the baseline and compared files. For more information on this, see Analyzing File Verification Results.
If the method uses a third-party Diff utility for file comparison (the utility and its launch parameters are specified by the Files diff utility options) and the compared files are not equal, the method also posts an informative message to the test log. The message holds a link to the file comparison report generated by the utility. To view the report, click the Details link in the Link column of this message.
By default, if the Check
method cannot find or access the file to be compared, or the file does not match its baseline copy, the method will wait for the file to become accessible and for the comparison to complete successfully for the period the Tools > Current Project Properties > Playback > Auto-wait timeout setting specifies. If the method fails to access the file, or if the file does not match its baseline copy within this period, the comparison will fail.
To compare two files or update a file stored in the Files collection, you can also use the Files.Compare
method.
Example
The following code snippet demonstrates how you can compare a stored item (a baseline copy) with an actual file.
JavaScript, JScript
if (!Files.OrdersList_old.Check("C:\\Work\\OrdersList.txt"))
Log.Warning("List of orders was changed");
Python
if not Files.OrdersList_old.Check("C:\\Work\\OrdersList.txt"):
Log.Warning("List of orders was changed")
VBScript
If Not Files.OrdersList_old.Check("C:\Work\OrdersList.txt") Then
Log.Warning("List of orders was changed")
End If
DelphiScript
if not Files.OrdersList_old.Check('C:\Work\OrdersList.txt') then
Log.Warning('List of orders was changed');
C++Script, C#Script
if (!Files["OrdersList_old"]["Check"]("C:\\Work\\OrdersList.txt"))
Log["Warning"]("List of orders was changed");
See Also
About File Checkpoints
How File Verification Works
Compare Method