WaitForCompletion Method

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

Description

The Runner.CallObjectMethodAsync function calls an object method asynchronously and returns a CallObjectMethodAsyncResult object. Using this object's WaitForCompletion method you can pause the script's execution until the execution of the specified object function is over or until the specified time period elapses.

Declaration

CallObjectMethodAsyncResultObj.WaitForCompletion(Timeout)

CallObjectMethodAsyncResultObj An expression, variable or parameter that specifies a reference to a CallObjectMethodAsyncResult object
Timeout [in]    Required    Integer    
Result None

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Timeout

Specifies the number of milliseconds to wait until the execution of the specified object function is over. If the Timeout is 0, the method will return immediately. If the Timeout is -1, the waiting time is infinite.

Result Value

None.

Remarks

Use the WaitForCompletion method only if you called a method that is provided by the application under test. If you call a method provided by TestComplete, then you should check the Completed property of the CallObjectMethodAsyncResult object in a loop to wait for the method's result. See Calling Methods Asynchrounously.

Example

The following code demonstrates how you can use the WaitForCompletion method to wait until the execution of the specified method is over.

JavaScript, JScript

function CallingMethodAsynchronously()
{
  // The following method calls the ShowModal method asynchronously.
  // Obj is a variable that holds a reference to an object of an Open Application.
  // This object contains the ShowModal method
  var CallResultObj = Runner.CallObjectMethodAsync(Obj, "ShowModal", "Caption", "Title", 10, 10);
 
  // Simulate user actions over the modal dialog
  // ...
 
  // Wait 10 seconds until the asynchronous call is over
  CallResultObj.WaitForCompletion(10000);

  // Check the results
  Res = CallResultObj.ReturnValue;
}

Python

def CallingMethodAsynchronously():
  # The following method calls the ShowModal method asynchronously.
  # Obj is a variable that holds a reference to an object of an Open Application.
  # This object contains the ShowModal method
  CallResultObj = Runner.CallObjectMethodAsync(Obj, "ShowModal", "Caption", "Title", 10, 10)
  # Simulate user actions over the modal dialog
  # ...
  # Wait 10 seconds until the asynchronous call is over
  CallResultObj.WaitForCompletion(10000)
  # Check the results
  Res = CallResultObj.ReturnValue

VBScript

Sub CallingMethodAsynchronously
  ' The following method calls the ShowModal method asynchronously.
  ' Obj is a variable that holds a reference to an object of an Open Application.
  ' This object contains the ShowModal method
  Set CallResultObj = Runner.CallObjectMethodAsync(Obj, "ShowModal", "Caption", "Title", 10, 10)
 
  ' Simulate user actions over the modal dialog
  ' ...
 
  ' Wait 10 seconds until the asynchronous call is over
  CallResultObj.WaitForCompletion 10000

  ' Check the results
  Res = CallResultObj.ReturnValue
End Sub

DelphiScript

function CallingMethodAsynchronously;
var CallResultObj, Res;
begin
  // The following method calls the ShowModal method asynchronously.
  // Obj is a variable that holds a reference to an object of an Open Application.
  // This object contains the ShowModal method
  CallResultObj := Runner.CallObjectMethodAsync(Obj, 'ShowModal', 'Caption', 'Title', 10, 10);
 
  // Simulate user actions over the modal dialog
  // ...
 
  // Wait 10 seconds until the asynchronous call is over
  CallResultObj.WaitForCompletion(10000);

  // Check the results
  Res := CallResultObj.ReturnValue;
end;

C++Script, C#Script

function CallingMethodAsynchronously()
{
  // The following method calls the ShowModal method asynchronously.
  // Obj is a variable that holds a reference to an object of an Open Application.
  // This object contains the ShowModal method
  var CallResultObj = Runner["CallObjectMethodAsync"]( Obj, "ShowModal", "Caption", "Title", 10, 10 );
 
  // Simulate user actions over the modal dialog
  // ...
 
  // Wait 10 seconds until the asynchronous call is over
  CallResultObj["WaitForCompletion"](10000);

  // Check the results
  Res = CallResultObj["ReturnValue"];
}

See Also

Calling Methods Asynchronously
Testing Modal Windows
Completed Property

Highlight search results