Viewing variables' values

During the script debugging, there often arises a need to look at the current values of the variables used in the script.

In this recipe we will deal with several methods of doing this.

Getting ready

Launch a standard Windows Notepad application (C:Windows otepad.exe).

How to do it...

In order to familiarize ourselves with the lookup possibility of the variable values, we will need to write a small script with the use of different variable types.

  1. Write the following function:
    function testDebug1()
    {
      var pNotepad = Sys.Process("notepad");
      var num = 15.8;
      var str = "string value";
      var bool = true;
      Log.Message("Dummy message");
    }
  2. Set the breakpoint on the last line, where the Log.Message method call takes place (set the cursor on the line and press F9 button).
  3. Launch the function. In the result, the function execution will pause on the line with the breakpoint and we will be able to look up the values of all the created variables.
  4. In the lower part of the TestComplete window, open the Watch List tab.
  5. Right-click on the empty list and select the New Item menu item.
  6. In the Expression field of the opened Watch Properties window, enter the name of the pNotepad variable and click on OK. The variable will show up in the list of those being tracked.
  7. Similarly, add all the other variables (num, str, bool, and so on).

    As a result, all the variables will appear on the list. One can also look up their values and types there (if TestComplete can determine the value for the given variable type).

    How to do it...

How it works...

To the Watch List list we can add any variables and even entire expressions for the lookup of their current values. For example, if we enter num+str as an expression, the values of the same will be tantamount to 15.8 string value, since TestComplete will automatically transmute the number to the string and join two string-type expressions together.

If we are working with the objects (pNotepad, in our instance), we can also look up their values via the uncollapsed view of the tree of the sibling objects, as shown in the previous screenshot.

Values on Watch List are updated automatically, and this is why usage of the list is especially handy when using loops, when it's required to track the variable value at each iteration.

There's more...

For quick lookup of the values of a given variable, it is not necessary to add it to Watch List, as it's enough to hover the mouse cursor over the name of the variable at any place of the script and TestComplete will show the tool tip with the value of the variable at hand.

Another method to quickly view the values of the variables is the Locals listing, in which all the local variables are shown (that is, the variables from the current function). The Locals list can be found on the same panel where Watch List is located.

See also

  • The Evaluating expressions recipe
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.144.194