Sys.WaitProcess Method

Applies to TestComplete 15.48, last modified on March 01, 2023

Description

Delays script execution until the specified process appears in the list of processes or the specified time limit is reached. To determine whether the returned object is an extant process, call Exists.

WaitProcess does not launch the process. It simply waits for it for a maximum of Timeout milliseconds.

Declaration

Sys.WaitProcess(ProcessName, Timeout, ProcessIndex)

ProcessName [in]    Required    String    
Timeout [in]    Optional    Integer Default value: 0   
ProcessIndex [in]    Optional    Integer Default value: 1   
Result The Process object

Applies To

The method is applied to the following object:

Sys

Parameters

The method has the following parameters:

ProcessName

The name of the executable file that launched the process.

Timeout

Milliseconds to delay the script execution in order to allow the process to start. If Timeout is 0, the method searches for the desired process once and then returns immediately. If Timeout is -1, the waiting time is infinite.

ProcessIndex

The index of the process instance among those started by the same executable. The first process has index 1, the second - 2, etc. 1 is the default value. If you obtain several processes with the same name and the process with the lowest index is terminated, the indexes of other processes will be decreased by one.

Result Value

The Process object with the specified name. If the specified object does not exist, the method returns an empty stub object.

Remarks

Unlike the Process method, WaitProcess does not post an error message to the log if the desired process does not exist. It simply returns an empty stub object. Use the Exists property of the returned object to determine whether the desired window exists in the system. If the process exists, its Exists property will return True; the property of the stub object will return False. Note that calling any method of the stub object, except for WaitWindow, will cause an error.

Example

The following example demonstrates how to use the WaitProcess method in scripts:

JavaScript, JScript

p = Sys.WaitProcess("Notepad", 2000);
if (! p.Exists)
  // Process does not exist
...

Python

p = Sys.WaitProcess("Notepad", 2000)
if not p.Exists:
  # Process does not exist
  ...

VBScript

Set p = Sys.WaitProcess("Notepad", 2000)
If Not p.Exists Then
  ' Process does not exist
  ...
End If

DelphiScript

var p;
begin
  p := Sys.WaitProcess('Notepad', 2000);
  if not p.Exists then
    // Process does not exist
  ...
end;

C++Script, C#Script

var p;
p = Sys["Process"]("Notepad", 2000);
if (! p["Exists"])
  // Process does not exist
...

See Also

Process Method
Process Object
ProcessName Property
Index Property (Process and Browser Objects)

Highlight search results