Updating Stored Files

Applies to TestComplete 12.60, last modified on September 17, 2018

The Files collection contains files that can be used in tests (for example, for comparison purposes).

In some cases, you may need to update a file stored in the collection. For example, you may need to update a stored file used by a file checkpoint in order for the checkpoint to pass.

TestComplete lets you update the content of files stored in the Files collection automatically from your tests and from the test log.

Note: If you need to make some minor changes to a file’s contents, you can do this manually. For information on how to do this, see Modifying Stored Files.

Updating Files From Tests

In order to be able to update a file, you need to enable the update feature of the desired file:

  • Enable the Update files option in the Stores settings.

  • Select the Update check box of the desired file in the Files editor.

To update stored files from tests, you can use --

Usually, these methods and file checkpoints are used to compare the contents of two files, but when the file update feature is enabled, they replace the contents of the stored file with the contents of the specified file instead of comparing them.

The following code demonstrates how to use the Compare method in your scripts to update a stored file:

JavaScript, JScript

var StoredFile = Files.NameByFileName("C:\\Work\\OrdersList.txt");
// Replaces the contents of the OrdersList.txt file with the contents of the OrdersList_new.txt file
Files.Compare (StoredFile, "C:\\Work\\OrdersList_new.txt");

Python

StoredFile = Files.NameByFileName("C:\\Work\\OrdersList.txt")
# Replaces the contents of the OrdersList.txt file with the contents of the OrdersList_new.txt file
Files.Compare (StoredFile, "C:\\Work\\OrdersList_new.txt")

VBScript

StoredFile = Files.NameByFileName("C:\Work\OrdersList.txt")
' Replaces the contents of the OrdersList.txt file with the contents of the OrdersList_new.txt file
Files.Compare StoredFile, "C:\Work\OrdersList_new.txt"

DelphiScript

var StoredFile : String;

StoredFile := Files.NameByFileName('C:\Work\OrdersList.txt');
// Replaces the contents of the OrdersList.txt file with the contents of the OrdersList_new.txt file
Files.Compare (StoredFile, 'C:\Work\OrdersList_new.txt');

C++Script, C#Script

var StoredFile = Files["NameByFileName"]("C:\\Work\\OrdersList.txt");
// Replaces the contents of the OrdersList.txt file with the contents of the OrdersList_new.txt file
Files["Compare"](StoredFile, "C:\\Work\\OrdersList_new.txt");

The following code demonstrates how to use the Check method in your scripts to update a stored file:

JavaScript, JScript

var StoredFile = Files.NameByFileName("C:\\Work\\OrdersList.txt");
// Replaces the contents of the OrdersList.txt file with the contents of the OrdersList_new.txt file
StoredFile.Check ("C:\\Work\\OrdersList_new.txt");

Python

StoredFile = Files.NameByFileName("C:\\Work\\OrdersList.txt")
# Replaces the contents of the OrdersList.txt file with the contents of the OrdersList_new.txt file
StoredFile.Check ("C:\\Work\\OrdersList_new.txt")

VBScript

StoredFile = Files.NameByFileName("C:\Work\OrdersList.txt")
' Replaces the contents of the OrdersList.txt file with the contents of the OrdersList_new.txt file
StoredFile.Check ("C:\Work\OrdersList_new.txt")

DelphiScript

var StoredFile : String;

StoredFile := Files.NameByFileName('C:\Work\OrdersList.txt');
// Replaces the contents of the OrdersList.txt file with the contents of the OrdersList_new.txt file
StoredFile.Check ('C:\Work\OrdersList_new.txt');

C++Script, C#Script

var StoredFile = Files["NameByFileName"]("C:\\Work\\OrdersList.txt");
// Replaces the contents of the OrdersList.txt file with the contents of the OrdersList_new.txt file
StoredFiles["Check"]("C:\\Work\\OrdersList_new.txt");

To update files form keyword tests, use the File Checkpoint operation or call the Files.Compare or File.Check method by using the Call Object Method, Run Code Snippet or Run Script Routine operation.

Updating Files From Logs

As it has been said, you can also update a stored file from the test log. For information on how to do this, see Updating File Checkpoints.

See Also

About Files Collection
Editing File Properties
Modifying Stored Files

Highlight search results