Project And Project Suite Variables - Overview

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

Project and project suite variables are shared among a current project or a project suite and are used to store data between the test runs.

The following sections provide detailed information about project and project suite variables.

Basic Concepts and Fields of Applications

Project and project suite variables are used to store values specific to project and project suites. You create and modify these variables on the Variables page of the project or project suite editors.

Project variables only work for the current project. You can use them to share data between tests of various types included in your project, for instance, between scripts and keyword tests.

Project variables are specific to the workstation on which the project is opened, that is, they store information that is specific to the workstation and their values may differ from other computer to another. An example of this data is file paths. They are specific to the computer, on which the project is opened. Let’s suppose you have a test that exports data to a file on your hard disk. If this test were run on several machines, it would be nice if the file path were specific to each computer where the test is run. You can create a global script variable and change its value in the source code before running the test on each computer. With the projects variables feature you can perform this task in a more convenient way: you can create and modify the variable visually.

Project variables can store their values between test runs. This functionality is not applied to the Object, Table and DB Table variable types (see below), but can be used for variables of other types. In order for a variable to store its values between test runs, you must create it in the Persistent Variables section of the Variables page of the project or project suite editor. If the variable is created in this section, then after the test run is over, TestComplete will save the variable value to the .tcLS file that corresponds to your project and uses the stored value next time you run the test. This feature lets you use project variables to share data between test sessions. But do this carefully, because a variable will have the stored value rather than the initial value before the next run and this may cause the test to fail.

Project suite variables are similar to project variables. They store values that are specific to workstation and they can store their values between the test runs. The only difference is that their values are shared with all projects belonging to the project suite. That is, a project suite variable is available in any project that belongs to the suite while project variables are available only within the project to which they belong. If a project changes a project suite variable, the projects that run after it in the suite will use the changed value. From this point of view project suite variables are very useful for exchanging data between projects.

Creating Project and Project Suite Variables

To create these variables use the Variables pages of the Project and ProjectSuite editors. To view this page, do the following:

  • Select the Project or ProjectSuite item in the Project Explorer panel and choose Edit from the context menu, or simply double-click this project item.

  • In the resulting Project or ProjectSuite editor of the Workspace panel, switch to the Variables page.

Types of Project and Project Suite Variables

Project and project suite variables can store values of the following types:

  • String - Use this type for variables that will store strings and individual characters.

  • Integer - Use this type for variables that will store integer numerical values.

  • Double - Use this type for variables that will store floating-point numeric values and dates.

  • Boolean - Use this type for variables that will store True or False.

  • Password - Use this type for variables that will store strings with sensitive information, such as passwords.

  • Object - Use this type for variables that will store object references.

  • Table - Use this type for variables that will store two-dimensional arrays.

  • DB Table - Use this type for variables that will provide access to an external data storage, such as a database, an Excel or CSV file.

String, Integer, Double and Boolean variables preserve their values between test runs. You can use these variables to store dynamically calculated values that you are going to reuse in subsequent test runs.

Object, Table and DB Table variables, on the other hand, are automatically reset to their original state after a test run. Any changes made to these variables during a test run are discarded once the test is finished.

Working With Project and Project Suite Variables in Scripts and Keyword Tests

Project and project suite variables can be used in scripts and keyword tests.

Working in Scripts

To access this variables from scripts, use the construction Project.Variables.variable_name or ProjectSuite.Variables.variable_name, for example:

JavaScript, JScript

Project.Variables.MyVariable1 = 10;
ProjectSuite.Variables.MyVariable2 = "My string value";

Python

Project.Variables.MyVariable1 = 10
ProjectSuite.Variables.MyVariable2 = "My string value"

VBScript

Project.Variables.MyVariable1 = 10
ProjectSuite.Variables.MyVariable2 = "My string value"

DelphiScript

Project.Variables.MyVariable1 := 10;
ProjectSuite.Variables.MyVariable2 := 'My string value';

C++Script, C#Script

Project["Variables"]["MyVariable1"] = 10;
ProjectSuite["Variables"]["MyVariable2"] = "My string value";

The variable name must comply with the naming rules of the scripting language you are using.

You can also create and remove variables from scripts. For complete information about this, see Working With Project and Project Suite Variables in Scripts.

Working in Keyword Tests

You can use project and project suite variables to specify parameters of keyword test operations. You do this in the Operation Parameters dialog that is used to view and modify the operation parameters. For detailed information about this, see Specifying Operation Parameters.

To assign a value to a project or project suite variable from a keyword test, use the Set Variable Value operation. In the Operation Parameters dialog you can specify the desired variable and the value to be assigned.

To set the value of a project or project suite variable, you can also use the Run Code Snippet operation and execute the script code described above in the Working in Scripts section.

Note:

In VBScript projects, the Run Code Snippet operation treats the equals sign (=) as a comparison operator by default. To treat it as an assignment operator, put the assignment code into the Execute statement:

VBScript

Execute("Project.Variables.myVariable1 = 10")

See Also

Using Variables
Project And Project Suite Variables
Working With Project and Project Suite Variables in Scripts

Highlight search results