About Project And Project Suite Variables

Applies to TestComplete 14.71, 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.

Basic concepts and fields of applications

You can use project and project suite variables to store values specific to your entire project or project suite. For example, you can use them to share data between tests included in your project or to store values you use to configure project items.

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. Project suite variables are available in any project that belongs to the same project suite. If during a test run, a project modifies a project suite variable, all other projects will use the modified value. This way, you can use project suite variables to share data between projects.

You can use project and project suite variables:

Project and project suite variables are specific to the workstation on which the project or project suite is opened. They store information that is specific to the workstation and their values may differ from one 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 project variables feature you can perform this task in a more convenient way: you can create and modify the variable visually.

Project and project suite variables can be temporary and persistent. You create them in the appropriate sections of the Variables page of the project or project suite editor. Persistent variables store their values between test runs. This way, you can share data between test sessions. Variables of the Object, Table, and DBTable types cannot be persistent.

Note: Use persistent variables carefully. When a test run starts, the variable will have the value stored during the preceding test run rather than its initial value and this may cause your test to fail.

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.

Using project and project suite variables in tests

Project and project suite variables can be used in scripts and keyword tests. Also, you can pass variable values to tests via the command line.

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.

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")

Via the command line

You can pass values of project or project suite variables to your test via the command line. For these purposes, use the PrjVar and PSVar command-line arguments.

Variable values you pass via the command line are temporary. At the beginning of the test run, they overwrite the initial value of appropriate variables of your project or project suite. After the test run is over, the variable values are restored to their initial state.
If the variable you set via the command line does not exist in your project or project suite, it will be created at the beginning of the test run and removed after the test run is complete.
If you run several projects that have a project variable with the same name, the command will set the variable value in all executed projects.

For complete information, see Passing Variables via Command Line.

See Also

Using Variables
Project And Project Suite Variables
Working With Project and Project Suite Variables in Scripts
Passing Variables via Command Line

Highlight search results