Runner.Halt Method

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

Description

The Halt method stops the script execution and posts an error string specified by ErrorMsg to the test log.

The methods stops the entire test run, that is, for instance, if you are executing a project or project suite test, the method will stop the entire project or project suite run.

Declaration

Runner.Halt(ErrorMsg)

ErrorMsg [in]    Optional    String    
Result None

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

ErrorMsg

Specifies the error message to be posted to the log. If ErrorMsg is omitted, Halt posts the "Script (Test) was interrupted" error message.

Result Value

None.

Remarks

  • TestComplete generates the OnStopTest event when you stop the test run using the Runner.Halt method. You can create a handling routine for this event to perform specific actions when the test stops.

  • If the Halt method is executed at the end of a keyword test, then TestComplete may be unable to post the error message specified by the ErrorMsg parameter. This happens because the method is called asynchronously and the log may have already been “closed” by the moment of message posting.

  • In test projects that use DelphiScript as a scripting language, you can also terminate the test execution using the built-in DelphiScript Halt routine. However, unlike Runner.Halt, this routine does not allow you to customize the text of the error message.

Example

The following example demonstrates how to use the Runner.Halt method to stop the project suite execution if an error occurs during the test.

JavaScript

function Test()
{

  try
  {
    // Performs testing actions
    …
  }
  catch(e)
  {
    // Stops the test execution and posts an exception message to the test log
    Runner.Halt(e.message);
  }
  finally
  {
    // Performs finalization actions
    …
  }
}

JScript

function Test()
{

  try
  {
    // Performs testing actions
    …
  }
  catch(e)
  {
    // Stops the test execution and posts an exception message to the test log
    Runner.Halt(e.description);
  }
  finally
  {
    // Performs finalization actions
    …
  }
}

Python

def Test():
  try:
    # ...
    # Performs testing actions
    Log.Message("Running...")
    # ...
  except Exception as e:
    # Stops the test execution and posts an exception message to the test log
    Runner.Halt(e.description)
  finally:
    # Performs finalization actions
    # ...
    Log.Message("Sample text")

VBScript

Sub Test

  Err.Clear
  On Error Resume Next

  ' Performs testing actions
  …

  If Err.Number <> 0 Then
    ' Stops the test execution and posts an exception message to the test log
    Runner.Halt Err.Description

  Else
    ' Performs finalization actions
    …
  End If

End Sub

DelphiScript

procedure Test();
begin
  try
    // Performs testing actions
    …
  except
    // Stops the test execution and posts an exception message to the test log
    Runner.Halt(ExceptionMessage);
  end;
end;

C++Script, C#Script

function Test()
{

  try
  {
    // Performs testing actions
    …
  }
  catch(e)
  {
    // Stops the test execution and posts an exception message to the test log
    Runner["Halt"](e["description"]);
  }
  finally
  {
    // Performs finalization actions
    …
  }
}

See Also

Stop Method
Stop Execution Operation
Halt Procedure

Highlight search results