Close Method

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

Description

The TestedApp.Close method closes the tested application by sending the WM_SYSCOMMAND message with the wParam parameter set to SC_CLOSE to the main window of the application. The method returns True if the application actually closes within the time period specified by the Auto-wait timeout project option. Otherwise, Close returns False. This method only affects the applications launched by TestComplete (either via the user interface or from a script).

If several instances of the application exist in the system, this method closes all of them. It returns True if they all were closed within the time limit, otherwise False. You may call TestedApp.Terminate when Close fails to stop the application.

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

Declaration

ProgObj.Close()

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 demonstrates the differences between working with tested applications via the TestedApp and Process objects. Process.Close only closes the associated application instance, whereas TestedApp.Close closes all running tested applications.

JavaScript, JScript

function ClosingApplications()
{
var LastPad;
  //Launch three instances of Notepad
  //and obtain the third one as the LastPad process
  LastPad=TestedApps.Notepad.Run(3);
  ...
  //Close a Notepad instance
  LastPad.Close(); //The Process.Close method is called
  aqUtils.Delay(1000); // Wait until the application is closed
  ...
  //Close the two remaining instances of Notepad
  TestedApps.Notepad.Close(); //The TestedApp.Close method is called
}

Python

def ClosingApplications():
  # Launch three instances of Notepad
  # and obtain the third one as the LastPad process
  LastPad = TestedApps.Notepad.Run(3)
  # ...
  # Close a Notepad instance
  LastPad.Close() # The Process.Close method is called
  aqUtils.Delay(1000) # Wait until the application is closed
  # ...
  # Close the two remaining instances of Notepad
  TestedApps.Notepad.Close() # The TestedApp.Close method is called

VBScript

Sub ClosingApplications
  'Launch three instances of Notepad
  'and obtain the third one as the LastPad process
  Set LastPad=TestedApps.Notepad.Run(3)
  ...
  'Close a Notepad instance
  LastPad.Close 'The Process.Close method is called
  aqUtils.Delay(1000) ' Wait until the application is closed
  ...
  'Close the two remaining instances of Notepad
  TestedApps.Notepad.Close 'The TestedApp.Close method is called
End Sub

DelphiScript

procedure ClosingApplications;
var LastPad: OleVariant;
begin
  //Launch three instances of Notepad
  //and obtain the third one as the LastPad process
  LastPad:=TestedApps.Notepad.Run(3);
  ...
  //Close a Notepad instance
  LastPad.Close; //The Process.Close method is called
  aqUtils.Delay(1000); // Wait until the application is closed
  ...
  //Close the two remaining instances of Notepad
  TestedApps.Notepad.Close; //The TestedApp.Close method is called
end;

C++Script, C#Script

function ClosingApplications()
{
var LastPad;
  //Launch three instances of Notepad
  //and obtain the third one as the LastPad process
  LastPad=TestedApps["notepad"]["Run"](3);
  ...
  //Close a Notepad instance
  LastPad["Close"](); //The Process.Close method is called
  aqUtils["Delay"](1000); // Wait until the application is closed
  ...
  //Close the two remaining instances of Notepad
  TestedApps["notepad"]["Close"](); //The TestedApp.Close method is called
}

See Also

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

Highlight search results