Terminate Method

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

Description

The TestedApp.Terminate tries to terminate all instances of the given application that were launched by TestComplete. Use this method as a last resort, when the TestedApp.Close method cannot stop the application. Terminate tries to close the application and returns True if the application actually closes within the time period specified by the Auto-wait timeout project option, otherwise it returns False.

To close any existing process in the system, you can also use Process.Close or Process.Terminate.

Declaration

ProgObj.Terminate()

ProgObj An expression, variable or parameter that specifies a reference to one of the objects listed in the Applies To section
Result Boolean

Applies To

The method is applied to the following objects:

Result Value

True if all the running application instances were closed successfully and False otherwise.

Example

The following code snippet launches the tested application and then uses the Close method to close it. If the tested application cannot be closed successfully, the application is terminated.

JavaScript, JScript

function Test()
{

  var TestApp, TestAppName;
  // Obtains the tested application
  TestApp = TestedApps.Items(0);
  TestAppName = TestApp.ItemName;

  // Launches the tested application
  TestApp.Run();

  

  // Closes the tested application and checks whether it was closed successfully
  if (! TestApp.Close() )
    {
    Log.Warning("The " + TestAppName + " application was not closed successfully and will be terminated.");
    // Terminates the tested application
    TestApp.Terminate();
    }

}

Python

def Test():
  # Obtains the tested application
  TestApp = TestedApps.Items[0]
  TestAppName = TestApp.ItemName
  # Launches the tested application
  TestApp.Run()
  # ...
  # Closes the tested application and checks whether it was closed successfully
  if not TestApp.Close():
    Log.Warning("The " + TestAppName + " application was not closed successfully and will be terminated.")
    # Terminates the tested application
    TestApp.Terminate()

VBScript

Sub Test

  Dim TestApp, TestAppName
  ' Obtains the tested application
  Set TestApp = TestedApps.Items(0)
  TestAppName = TestApp.ItemName

  ' Launches the tested application
  TestApp.Run

  

  ' Closes the tested application and checks whether it was closed successfully
  If Not TestApp.Close Then
    Log.Warning("The " & TestAppName & " application was not closed successfully and will be terminated.")
    ' Terminates the tested application
    TestApp.Terminate
  End If

End Sub

DelphiScript

procedure Test();
var TestApp, TestAppName;
begin

  // Obtains the tested application
  TestApp := TestedApps.Items(0);
  TestAppName := TestApp.ItemName;

  // Launches the tested application
  TestApp.Run();

  

  // Closes the tested application and checks whether it was closed successfully
  if not TestApp.Close then
    begin
    Log.Warning('The ' + TestAppName + ' application was not closed successfully and will be terminated.');
    // Terminates the tested application
    TestApp.Terminate;
    end;

end;

C++Script, C#Script

function Test()
{

  var TestApp, PDATestAppName;
  // Obtains the tested application
  TestApp = TestedApps["Items"](0);
  TestAppName = TestApp["ItemName"];

  // Launches the tested application
  TestApp["Run"]();

  

  // Closes the tested application and checks whether it was closed successfully
  if (! TestApp.Close() )
    {
    Log["Warning"]("The " + TestAppName + " application was not closed successfully and will be terminated.");
    // Terminates the tested application
    TestApp["Terminate"]();
    }

}

See Also

TestedApp.Close
TestedApp.Run
TestedApps.RunAll
Process.Close
Process.Terminate

Highlight search results