Adding Files to the Files Collection

Applies to TestComplete 14.50, last modified on April 22, 2021

The Stores > Files collection stores files in various formats – text, PDF, XML, and others – that your tests use for comparison and verification. You can add files to this collection in several ways:

Requirements

You add files to the collection as they are. TestComplete doesn’t have any specific requirements for this.

For PDF documents, it offers extended support - you can add them as binary files or as recognized text. To do the latter:

  • You need an active license of the Intelligent Quality add-on.

  • The PDF to Text plugin must be enabled in TestComplete.

If you want to add PDF files as binary documents, there are no special requirements.

During Test Recording

When you are recording a test and adding a File or PDF checkpoint to it, the appropriate baseline file is added to the collection automatically.

From TestComplete UI

  1. If your project does not include the Stores > Files collection, add it:

    Add Files collection to a TestComplete project

    Click the image to enlarge it.

  2. Right-click the Stores > Files node in the Project Explorer and then click Add > Add File:

    Adding a file to the Files collection in the TestComplete project

    Click the image to enlarge it.

    – or –

    Open the collection, right-click anywhere in the file list and then click New Item:

    Adding a file to the Files collection in the TestComplete project

    Click the image to enlarge it.

  3. Browse for the needed file in the resulting Add File dialog.

  4. If you add a PDF file, specify whether you want to add it as a binary file or as a text file. In the latter case, TestComplete will recognize the selected file’s text contents, create a text file to store it and add the created text file to the collection. See also Creating PDF Checkpoints.

From Tests

In your test, call the Files.Add method.

For example, the code below adds the OrderList.txt file to the project’s Files collection:

JavaScript, JScript

if (!Files.Add("C:\\MyApplication\\OrdersList.txt", "OrdersList"))
  Log.Message(Files.LastError);

Python

if not Files.Add("C:\\MyApplication\\OrdersList.txt", "OrdersList"):
  Log.Message(Files.LastError)

VBScript

If Not Files.Add("C:\MyApplication\OrdersList.txt", "OrdersList") Then
  Log.Message(Files.LastError)
End If

DelphiScript

if not Files.Add('C:\MyApplication\OrdersList.txt', 'OrdersList') then
  Log.Message(Files.LastError);

C++Script, C#Script

if (!Files["Add"]("C:\\MyApplication\\OrdersList.txt", "OrdersList"))
  Log["Message"](Files["LastError"]);

To call the Files.Add method from your keyword test, use the Call Object Method, Run Code Snippet or Run Script Routine operation.

This method always adds PDF files as binary files. It does not allow recognizing and adding their text content. To add a file that you want to use as a baseline for a PDF checkpoint, create a text file that would store the expected text and add it to the collection.

Remarks

When you add a file to the Files collection, TestComplete gives the added item a name based on the file name and converts it to the format that can be used in script. For example, if you add a file named 1.bat to the collection, the appropriate File item will be called A_bat, which is valid and can be used in scripts.

See Also

Files
Files Object
Files Editor
Modifying Stored Files

Highlight search results