Changing Variables During Debugging

Applies to TestComplete 15.70, last modified on December 17, 2024

You can change variable values during debugging of script and keyword tests. To do this, pause the script or test at the desired point and then use one of the ways described below.

For JavaScript users: Currently, you cannot modify local variables during debugging.
To pause the test execution

To pause the test run, do one of the following:

  • Set a breakpoint on the desired script line or keyword test operation.

  • Set the cursor to the desired script line or operation and then run the script or test to the cursor. See Running to the Cursor.

  • Press Pause on the Debug toolbar (if the toolbar is hidden, right-click somewhere in the toolbar area and choose Debug from the ensuing context menu).

    If you are running a keyword test, you can also pause the test execution by right-clicking within the Keyword Test editor and choosing Pause from the context menu.

  • Call the Runner.Pause method (TestComplete will pause the execution on the next script line after the line holding the method call or on the next keyword test operation after the operation that calls the method).

Once the test execution is paused, you can change the variables.

To change a variable

You can change a variable in the Evaluate dialog or in the Watch List panel.

  • The Evaluate dialog:

    • To invoke the dialog, press the Call the Evaluate Dialog button on the Debug toolbar, or press the Ctrl+F12 shortcut (this is the default shortcut. You can change it any time. See Key Mapping).

    • In the dialog, type the desired variable name in the Expression box and click Evaluate or press Enter. The dialog will display the current variable(s) value in the Result box.

      Note: The specified variable must be available at the current execution point.

      You should specify the variable name as if the variable is addressed from script code. Script variables are addressed by their names. To specify a keyword test variable, use the syntax KeywordTests.KeywordTest_Name.Variables.Variable_Name.

    • To set a new value, type it in the New Value box and press Enter to confirm the input. TestComplete will assign the specified value to the variable and display it in the Result box. If the assignment is not possible, an error message will be shown.

      For information on specifying the value, see below.

  • The Watch List panel:

    • Switch to the Watch List panel. By default, it is shown at the bottom of the TestComplete window. If the panel is hidden, you can show it by selecting View > Debug > Watch List from the TestComplete main menu.

    • Add the desired variable to the panel. You can do this, for instance, by right-clicking within the panel and selecting New Item from the context menu. This will invoke the Watch Properties dialog.

      Type the variable name in the dialog’s Expression box and press OK. The variable will be added to the Watch List panel.

      Note: The specified variable must be available at the current execution point.

      Specify the variable name as if the variable is addressed from script code. To specify a script variable, use its name. To specify a keyword test variable, use the syntax KeywordTests.KeywordTest_Name.Variables.Variable_Name.

    • To assign a new value to the variable, select the Value cell and press F2 or simply click the Value cell twice (not a double-click). This will activate the in-place editor. Type the desired value into the editor and press Enter to confirm the input. Press Esc to cancel the changes.

      For information on specifying the value, see below.

Note: You can specify not only the variables, to which new values will be assigned, but also array elements. For instance, if the arrItems variable is an array, you can specify arrItems(1) to refer the second element of the array.
About the assigned value

The new value to be assigned to a variable can be a constant or a script expression:

  • To specify a value you can use an integer, boolean or string constant. For instance, you can specify 2, 12.01, true, "my string".

    When specifying a string, use quotes (JavaScript, JScript, Python, VBScript, C#Script and C++Script) or apostrophes (DelphiScript). Else, TestComplete will treat the entered text as an expression and will try to execute it.

    You cannot assign an object to the variable. That is, the assignment is possible only if the specified expression evaluates to a non-object value (integer, string, boolean, date and so on) or an array.

    Some versions of the JScript engine support assignment of objects, so you may be able to assign object references to variables when debugging your JScript, C#Script and C++Script projects on some workstations. However, there is no guarantee that this functionality will work on any computer.

  • The specified value can be a valid script expression. It may contain another variable, array item, arithmetic operations and calls to functions and properties. TestComplete executes the expression and assigns it result to the specified variable.

    The expression syntax must match the syntax of your project’s language. The variables, properties and method mentioned in the expression must be available at the current execution point.

    Below are some examples of expressions:

    Sample Description
    myStrVar + "my other str" myStrVar is a local variable. Its value is concatenated with the string constant my other str.
    i + 2 i is a local variable. We sum it with 2.
    arrItems(2) arrItems is an array. We use the value of its third element (the element’s index is 2). In Python and DelphiScript, enclose the index using the square brackets, that is, arrItems[2].
    IsNumeric(i) AND j > 2 IsNumeric is a function, i and j are local variables. AND is a logical operator in VBScript and DelphiScript. In JavaScript, JScript, C#Script and C++Script you should use &&. In Python, use and.
    Sys.ChildCount Assigns the value of the Sys.ChildCount property.
    Cos(i) + 1.2 Cos is a function (it is provided by the VBScript engine), i is a local variable. The function is executed and its results are added to the float constant 1.2.

See Also

Debugging Tests
Evaluate Dialog
About Watch List Panel

Highlight search results