File Operations

The folder TBox Automation Tools->File Operations in the Standard subset contains the following Modules:

TBox Image Compare

The Module TBox Image Compare allows you to verify pixel-accurate image files in the following formats: BMP, JPG, and GIF.

It has the following attributes:

ModuleAttribute

Description

FirstImageFilePath

Path and file name of the first image file.

SecondImageFile

Path and file name of the image file that you want to compare to the first image file.

In this example, you compare the image file logo_new.jpg to the image file logo.jpg.

Compare two image files

TBox File Existence

This Module allows you to verify whether a file exists in a specific directory.

It has the following attributes:

ModuleAttribute

Description

Directory

Path to the file.

File

Name of the file whose existence you want to verify. You can use ActionModes Verify or WaitOn.

To verify that a specified file does not exist, put the negation symbol ! in front of the file name.

This example verifies whether the file test01.xml exists in the directory D:\.

Verify the existence of a file

The screenshot below shows how to verify that the file doesn't exist:

Verify that a file doesn't exist

TBox File Compare

This Module allows you to compare the content of two files. After execution, you can view the result in the Loginfo column of the ExecutionEntry.

The Module TBox File Compare has the following ModuleAttributes:

ModuleAttribute

Description

FirstFilePath

Path and file name of the first file.

SecondFilePath

Path and file name of the second file.

In this example, you compare the file data_new.xml to the file data.xml.

Compare two files

TBox Copy File

Use this Module to copy and paste files within the Microsoft Windows® file system. If you want to paste a file to a different directory, this directory must already exist at run-time.

The Module TBox File Operations has the following attributes:

ModuleAttribute

Description

Source

Path and file name of the file that you want to copy.

Target Directory

Directory to which you want to paste the file.

Target Filename

If you want to rename the file, specify the new file name.

Overwrite

By default, Tricentis Tosca doesn't overwrite existing files. If you want to overwrite the existing file, set the value True.

The TestStep in this example performs the following actions:

  • Copies the file report_new.xml from the directory C:\Reports to C:\Sales Reports

  • Renames the file to report.xml

  • Overwrites the existing file in the target directory

Copy and paste a file to another directory

TBox Delete File

This Module removes a file from a specific directory.

The Module TBox Delete File has the following ModuleAttributes:

ModuleAttribute

Description

Directory

Path to the file that you want to delete.

File

Name of the file that you want to delete.

If the system can't locate the file, the execution result shows the following description: The file <file name> does not exist.

The test result is positive.

In this example, you delete the file test.xml from the directory C:\Temp.

Delete a file

TBox Read/Create File

This Module allows you to perform the following actions:

  • Create a text file.

  • Write text to a text file.

  • Verify or buffer text in the file.

  • Wait on text in the text file.

The Module TBox Read/Create File has the following ModuleAttributes:

ModuleAttribute

Description

Directory

Path of the file that you want to create or read.

File

Name of the file, including the file extension.

Text

Text that you want to write, verify, buffer, or wait on.

Use ActionMode Input, Verify, Buffer, or WaitOn, respectively.

Encoding

.NET character encoding of the file that you want to create. This is optional.

Example: UTF-8

Overwrite

If you want to overwrite the target file, set the value to True and use ActionMode Input.

The TestStep in this example performs the following actions:

  • Creates a new text file named test.txt in the directory C:\Temp

  • Adds the file content This is text in the file

  • Uses character encoding UTF-8

  • Overwrites the existing file in the target directory

Create a new file

This example verifies whether the file test.txt in the directory C:\Temp contains the text This is text in the file.

Verify text in a file

TBox Append File

This Module is available if you install Tricentis Tosca Version 13.1 Patch 05.

The TBox Append File Module appends the Text ModuleAttribute to the defined file. If you define a file that doesn't yet exist, Tricentis Tosca creates it for you.

The Module has the following ModuleAttributes:

ModuleAttribute

Description

Filepath

The full file path where the file is located.

Text

The text you want to append.

End with Newline

Set the value to True if you want the text to be appended with Newline at the end. This is optional.

In this example, you append text to a file in the directory C:\Temp.

Append a file