Variables Object

Applies to TestComplete 15.47, last modified on January 20, 2023

Description

The Variables object provides access to a collection of project, project suite, or keyword test variables:

Project Suite Variables

Project Suite variables

Click the image to enlarge it.

Project Variables

Project variables

Click the image to enlarge it.

Keyword Test Variables

Keyword Test variables

Click the image to enlarge it.

To get the Variables object in tests, use the following syntax (depending on the variable type you want to get):

ProjectSuite.Variables.Variable_Name
Project.Variables.Variable_Name
KeywordTests.KeywordTest_Name.Variables.Variable_Name

  • ProjectSuite is the predefined name of the top-level object that provides access to your project suite. The object is available by default.

  • Project is the predefined name of the top-level object that provides access to your project. The object is available by default.

  • KeywordTests is the predefined name of the top-level object that provides access to a collection of keyword tests. To access the object, you must have the Keyword Tests collection added to your project. See Adding and Removing Project Items and Their Child Elements.

    KeywordTest_Name is the name of the keyword test that is added to the Keyword Tests collection of your project and whose variables you want to get. You can view the name in the Project Explorer panel.

  • Variables is the property you use to get the collection of variables of the appropriate object.

  • Variable_Name is the name of the needed variable of the specified variable collection. To access the variable, use its name as it is specified on the Variables page of the appropriate collection.

    Note: A variable name cannot coincide with the name of the object’s methods and properties (that is, you cannot name a variable AddVariable, VariableCount, VariableExists and so on).

Members

Example

The following example modifies an existing variable Var1 defined in the current project.

JavaScript, JScript

if (Project.Variables.VariableExists("Var1"))
  Project.Variables.Var1 = "New test";

Python

if (Project.Variables.VariableExists("Var1")):
  Project.Variables.Var1 = "New test"

VBScript

If Project.Variables.VariableExists("Var1") Then
  Project.Variables.Var1 = "New test"
End If

DelphiScript

if Project.Variables.VariableExists('Var1') then
  Project.Variables.Var1 := 'New test';

C++Script, C#Script

if (Project["Variables"]["VariableExists"]("Var1"))
  Project["Variables"]["Var1"] = "New test";

See Also

ProjectSuite.Variables
Project.Variables
Variables Property
Variables Page
Network Suite Variables

Highlight search results