How to Create, Rename and Delete Variables and Specify Variable Values

Applies to TestComplete 15.63, last modified on April 23, 2024

The object-driven testing (ODT) functionality is deprecated. Do not use it to create new tests. It will be removed from the product in one of the future releases. As an alternative, you can create custom classes in your scripts. For more information, see Alternatives to the ODT functionality.

To create a new variable

  1. Below the ODT | Data item in the ODT editor or below the Data item in the Data editor, right-click the data group to which a variable should be added.
  2. Select New Item from the context menu.
  3. TestComplete will create a new variable and name it NewVariable1. You can then rename the variable as you wish.

Since variables are held in data groups, you should create at least one group to be able to create a new variable.

Names of variables are used to refer to these variables in scripts and keyword tests. That is why these names must consist of the A..Z, a..z, 0..9 and _ characters only (that is, they must be valid identifiers in the scripting language you use). The variable names are case-sensitive in JScript, C++Script and C#Script scripts, and case-insensitive in VBScript and DelphiScript scripts.

To rename a variable

  1. In the ODT or Data editor, select the desired variable in the tree view.
  2. Right-click the chosen variable and select Rename from context menu, or press F2. TestComplete will activate an in-place editor.
  3. Enter the desired name for the variable.
  4. To apply changes, press Enter or click somewhere outside of the in-place editor. To cancel changes, press Esc.

To modify the variable value

  1. In the ODT or Data editor, select the desired variable in the tree view.
  2. Right-click the chosen variable and select Edit from context menu, or simply click the value field of the desired variable.
  3. In the Value column, specify the variable value. Variables can store an ordinary value (integer, string, date, etc.), an array or an object:
    • To create an object, select the class name from the dropdown list of the Value column. TestComplete will automatically create a new object and display its properties as child nodes of the object's node. To indicate that the property holds a reference to an object, TestComplete displays the object's class name in parenthesis (for example, (MyClass)). If you enclose that name in quotes, TestComplete will treat the property value as a string (for instance, "(MyClass)").
    • To create a new array, select (Array) from the dropdown list of the Value column. Then you can add items to the array by right-clicking the array node and selecting New Item from the context menu. If you need to specify a value holding the (Array) string, enclose that string in quotes (that is, "(Array)").
    • To store a boolean value, type true or false. If you want to specify a string value holding the true or false string, enclose that string in quotes (that is, "true" or "false").
Note: A variable can store an object. This can be an object created in the ODT or Data editor, one of TestComplete programming objects or any other OLE object you created in your test (for instance, it can be a Word.Application object). If a variable stores an OLE object that has not been created via the ODT or Data editor, TestComplete displays (OleObject) as a variable value. You can see this value in the ODT or Data editor during the test run.

To copy and paste a variable

To copy a variable to the clipboard:

  • Right-click the desired variable in the ODT or Data editor and choose Copy from the context menu.

To paste a variable from the clipboard:

  • In the editor select the parent group for the new variable, right-click on it and choose Paste from the context menu.
Note: To paste a variable that stores an object from another project, you should declare the object’s class first. See How to Create, Rename and Delete Classes for instructions on this.

To change the variable’s position

  • Right-click the variable name in the editor and choose Move Up or Move Down from the context menu to move it in the corresponding direction.

To delete a variable

  • Right-click the variable you want to delete and select Delete from the context menu.
  • TestComplete will display a message box asking you if you want to delete the selected variable. Click OK to delete the variable, or Cancel to cancel the deletion.

See Also

Object-Driven Testing
ODT Editor
Data Editor

Highlight search results