Files Object

Applies to TestComplete 15.42, last modified on September 08, 2022

Description

The Files > Stores collection of TestComplete projects stores files of any type (text, graphic, HTML, PDF, and so on) that you can use for file comparison and verification in your tests. This can be useful when checking your tested application's output.

Use the Files object to manage and process the files stored in the Stores > Files collection of your project. For example, you can add a file to the collection, compare two files, update the file and so on.

The properties of the Files object correspond to the files added to the Stores > Files collection. Each property returns a File object that corresponds to the appropriate file. For instance, the following code provides access to the TextFile1 element:

JavaScript, JScript

var FileObj1 = Files.TextFile1;

Python

FileObj1 = Files.TextFile1

VBScript

Set FileObj1 = Files.TextFile1

DelphiScript

var
  FileObj1 : OleVariant;
begin
  FileObj1 := Files.TextFile1;
end;

C++Script, C#Script

var FileObj1 = Files["TextFile1"];

Note: When calling the Files object’s methods, you can address the files added to the collection by their collection name rather than by using their fully-qualified path.

Requirements

The Files object is available only if your project contains the Stores > Files collection.

Members

Example

The following example shows how to calculate the difference (in bytes) between two files, and then use the resulting value for file comparison:

JavaScript, JScript

var PrecalculatedDifference;

  PrecalculatedDifference = Files.CalculateHashValue("C:\\Work\\OrdersList_Var1.txt", "C:\\Work\\OrdersList_Var2.txt");
  ...
  if (!Files.Compare("C:\\Work\\OrdersList_Var1.txt", "C:\\Work\\OrdersList.txt", PrecalculatedDifference))
    Log.Warning("List of orders was changed");

Python

PrecalculatedDifference = Files.CalculateHashValue("C:\\Work\\OrdersList_Var1.txt", "C:\\Work\\OrdersList_Var2.txt")
# ...
if not Files.Compare("C:\\Work\\OrdersList_Var1.txt", "C:\\Work\\OrdersList.txt", PrecalculatedDifference):
  Log.Warning("List of orders was changed")

VBScript

  PrecalculatedDifference = Files.CalculateHashValue("C:\Work\OrdersList_Var1.txt", "C:\Work\OrdersList_Var2.txt")
  ...
  If (Not Files.Compare("C:\Work\OrdersList_Var1.txt", "C:\Work\OrdersList.txt", PrecalculatedDifference)) Then 
    Log.Warning("List of orders was changed")
  End If 

DelphiScript

var PrecalculatedDifference : integer;
begin 
  PrecalculatedDifference := Files.CalculateHashValue('C:\Work\OrdersList_Var1.txt', 'C:\Work\OrdersList_Var2.txt');
  ...
  if (not Files.Compare('C:\Work\OrdersList_Var1.txt', 'C:\Work\OrdersList.txt', PrecalculatedDifference))
    then Log.Warning('List of orders was changed');
end;

C++Script, C#Script

var PrecalculatedDifference;

  PrecalculatedDifference = Files["CalculateHashValue"]("C:\\Work\\OrdersList_Var1.txt", "C:\\Work\\OrdersList_Var2.txt");
  ...
  if (!Files["Compare"]("C:\\Work\\OrdersList_Var1.txt", "C:\\Work\\OrdersList.txt", PrecalculatedDifference))
    Log["Warning"]("List of orders was changed");

See Also

Regions Object
Objects Object
Stores
Files Editor
Working With Files From Scripts

Highlight search results