Variables Property

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

Description

The Variables property returns the collection of variables defined in the keyword test, to which KeywordTestObj corresponds. You create these variables on the Variables page of the Keyword Test editor or by using the Add Variable wizard:

Keyword Test variables

After you obtain scripting access to variables, you can check their values or modify them.

Declaration

KeywordTestObj.Variables

Read-Only Property A Variables object
KeywordTestObj An expression, variable or parameter that specifies a reference to a KeywordTest object

Applies To

The property is applied to the following object:

Property Value

A Variables object that represents the collection of variables that belong to the keyword test.

Remarks

You can assign values to keyword test variables from scripts. However, when TestComplete runs a keyword test, it initializes all the test variables with their initial values (you can view those values in the Default Value column of your keyword test). Therefore, working with keyword test variables from scripts makes sense only if you run your script from within the keyword test.

That is, you first run the keyword test, and then call a script expression that works with the keyword test variables.

Example

The code below checks whether the specified keyword test variable exists in a test.

JavaScript, JScript

function KDTvar()
{
  // Obtains information about a keyword test
  var kdTest = KeywordTests.Test1;
  // Obtains the test's variables
  var kdVars = kdTest.Variables;
  // Specifies the name of the variable to be checked
  var VarName = "Var_Name";
  
  // Checks whether the variable exists in the keyword test
  if ( kdVars.VariableExists(VarName) )
    Log.Message("The variable exists.")
  else
    Log.Message("The variable doesn't exist.");
}

Python

def KDTvar():
  # Obtains information about a keyword test
  kdTest = KeywordTests.Test1
  # Obtains the test's variables
  kdVars = kdTest.Variables
  # Specifies the name of the variable to be checked
  VarName = "Var_Name";
  # Checks whether the variable exists in the keyword test
  if kdVars.VariableExists(VarName):
    Log.Message("The variable exists.")
  else:
    Log.Message("The variable doesn't exist.")

VBScript

Sub KDTvar()

  ' Obtains information about a keyword test
  Set kdTest = KeywordTests.Test1
  ' Obtains the test's variables
  Set kdVars = kdTest.Variables
  ' Specifies the name of the variable to be checked
  VarName = "Var_Name"
  
  ' Checks whether the variable exists in the keyword test
  If kdVars.VariableExists(VarName) Then
    Log.Message("The variable exists.")
  Else
    Log.Message("The variable doesn't exist.")
  End If
  
End Sub

DelphiScript

function KDTvar;
var kdTest, kdVars, VarName;
begin

  // Obtains information about a keyword test
  kdTest := KeywordTests.Test1;
  // Obtains the test's variables
  kdVars := kdTest.Variables;
  // Specifies the name of the variable to be checked
  VarName := 'Var_Name';
  
  // Checks whether the variable exists in the keyword test
  if ( kdVars.VariableExists(VarName) ) then
    Log.Message('The variable exists.')
  else
    Log.Message('The variable doesn''t exist.');

end;

C++Script, C#Script

function KDTvar()
{
  // Obtains information about a keyword test
  var kdTest = KeywordTests["Test1"];
  // Obtains the test's variables
  var kdVars = kdTest["Variables"];
  // Specifies the name of the variable to be checked
  var VarName = "Var_Name";
  
  // Checks whether the variable exists in the keyword test
  if ( kdVars["VariableExists"](VarName) )
    Log["Message"]("The variable exists.")
  else
    Log["Message"]("The variable doesn't exist.");
}

See Also

Keyword Test Variables
Keyword Tests
About Keyword Testing

Highlight search results