Using breakpoints to pause script execution

To pause automated test execution at a specific point, the breakpoints are applied. In this recipe we will learn to work with the breakpoints in TestComplete.

Getting ready

Create the following function:

function testBreakpoints()
{
  for(var i = 0; i < 10; i++)
  {
    Log.Message("Iteration #" + i);
  }
}

This function will simply output the messages 10 consecutive times.

How to do it...

To demonstrate working with the breakpoints, perform the following steps:

  1. Click on the line with the Log.Message method call and press the F9 key (or click on the column with the numbers to the left of the editor, opposite the previous line). In the result, the line will be highlighted in red against its background, and in the column to the left, a red circle will appear, as shown in the following screenshot:
    How to do it...
  2. Launch the function for execution. The function execution will pause at the first breakpoint in the script.
  3. Stop the script execution (for example, by pressing the buttons combination: Shift + F2). Make sure the log contains only the error message Script execution was interrupted., since we have stopped the script without ever executing the Log.Message line.
  4. Right-click on the red circle of the breakpoint and select the Properties menu item.
  5. In the opened Breakpoint Properties window, input the value of i == 4 in the Condition field and click on the OK button:
    How to do it...
  6. Pay attention that the icon of the breakpoint has changed, and now contains the f symbol:
    How to do it...
  7. Launch the function again and break its execution as soon as the script execution has been paused.
  8. Pay attention that besides the error message in the log, there are several messages with the following text: Iteration #N.

How it works...

In the first instance we have used a simple breakpoint. It fires as soon as script execution reaches the given code line and pauses the execution, pending further action from the user.

In the second instance, we have used a conditional breakpoint, which allows pausing the execution only in case a certain condition is met (in our case, the variable i should be equal to 4).

Conditional breakpoints are very convenient in those cases when we have a loop, which is executable in part by pausing the execution under conditions specified.

Besides a condition of the kind, one can make use of another condition of Pass Count. In this field, it is possible to assign the number of loops of the script, after which the breakpoint should fire (for example, in our case, we could simply set the value to 4 in the Pass Count field).

There's more...

There also exists another method for setting a conditional pause into the script execution, namely that of the Runner.Pause method. The result of this is analogous to the workings of the breakpoint.

If you have a breakpoint, which is of use from time to time (for example, a non-stable script, often requiring debugging), we can simply disable the breakpoint instead of completely removing it. To this end, it is necessary to right-click on it and select the Enable menu item.

See also

  • The examples of the situations when we need breakpoints are also available in the Viewing variables' values and Debugging tests step by step recipes
..................Content has been hidden....................

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