Runner.CallObjectMethodAsync Method

Applies to TestComplete 15.70, last modified on December 17, 2024

Description

When you call a method of an object, TestComplete pauses the script execution until the execution of the called method is over (that is, the script is paused until the method returns). Using the CallObjectMethodAsync method you can call application methods without pausing the script. This is useful if the method displays a modal window or dialog and you need to simulate user actions in this dialog (see Testing Modal Windows for more information).

You can also use this method to obtain a property’s value asynchronously (that is, you can use the method to perform asynchrounous calls to the property’s get method).

Declaration

Runner.CallObjectMethodAsync(Obj, MethodName, Param1, Param2, ..., ParamN)

Obj [in]    Required    The object whose method will be called    
MethodName [in]    Required    String    
Param1 [in]    Optional    Variant    
Param2 [in]    Optional    Variant    
...
ParamN [in]    Optional    Variant    
Result A CallObjectMethodAsyncResult object

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

Obj

Specifies the object whose method will be called.

MethodName

The name of the desired object method or property.

Param1, Param2, ... ParamN

Specifies the method parameters (if any). If you obtain the value of an indexed property, these parameters specify the index values.

Result Value

CallObjectMethodAsync returns the CallObjectMethodAsyncResult object that contains methods and properties allowing you to pause the script execution until the called method returns and providing access to method results.

Remarks

CallObjectMethodAsync was added to simplify testing of modal windows and dialog boxes displayed by script routines or by methods that reside in Open Applications. See Testing Modal Windows for complete information.

It is not recommended to use this method to perform asynchronous calls to methods provided by TestComplete (that is, to methods that are provided by TestComplete but not by the application under test).

This method cannot be used in script extensions. For more information on objects that you can use in script extensions, see Objects Available to Script Extensions.

This method cannot be used to call methods of custom objects you create in your tests.

Example

The following example demonstrates how you can use the Runner.CallObjectMethodAsync method to display a modal window and perform testing actions over it.

JavaScript, JScript

function Test()
{
  var TestedApp, Form, ModalForm, Result;
  // Launches the tested application
  TestedApp = TestedApps.ModalSamples;
  TestedApp.Run();

  Form = Aliases.SampleApp.Form;
  // Calls the method that displays a modal form
  Result = Runner.CallObjectMethodAsync(Form, "ShowModal");

  // Performs actions over the modal form
  ModalForm = Aliases.SampleApp.ModalForm;
  …
  // Closes the modal form
  ModalForm.Close();
  // Waits for the method completion
  Result.WaitForCompletion(2000);
  …
  TestedApp.Close();
}

Python

def Test():
  # Launches the tested application
  TestedApp = TestedApps.ModalSamples
  TestedApp.Run()
  Form = Aliases.SampleApp.Form
  # Calls the method that displays a modal form
  Result = Runner.CallObjectMethodAsync(Form, "ShowModal")
  # Performs actions over the modal form
  ModalForm = Aliases.SampleApp.ModalForm
  # ...
  # Closes the modal form
  ModalForm.Close()
  # Waits for the method completion
  Result.WaitForCompletion(2000)
  # ...
  TestedApp.Close()

VBScript

Sub Test

  Dim TestedApp, Form, ModalForm, Result
  ' Launches the tested application
  Set TestedApp = TestedApps.ModalSamples
  TestedApp.Run

  Set Form = Aliases.SampleApp.Form
  ' Calls the method that displays a modal form
  Set Result = Runner.CallObjectMethodAsync(Form, "ShowModal")

  ' Performs actions over the modal form
  Set ModalForm = Aliases.SampleApp.ModalForm
  …
  ' Closes the modal form
  ModalForm.Close
  ' Waits for the method completion
  Result.WaitForCompletion(2000)
  …
  TestedApp.Close

End Sub

DelphiScript

procedure Test();
var TestedApp, Form, ModalForm, Result;
begin
  // Launches the tested application
  TestedApp := TestedApps.ModalSamples;
  TestedApp.Run;

  Form := Aliases.SampleApp.Form;
  // Calls the method that displays a modal form
  Result := Runner.CallObjectMethodAsync(Form, 'ShowModal');

  // Performs actions over the modal form
  ModalForm := Aliases.SampleApp.ModalForm;
  …
  // Closes the modal form
  ModalForm.Close();
  // Waits for the method completion
  Result.WaitForCompletion(2000);
  …
  TestedApp.Close();
end;

C++Script, C#Script

function Test()
{
  var TestedApp, Form, ModalForm, Result;
  // Launches the tested application
  TestedApp = TestedApps["ModalSamples"];
  TestedApp["Run"]();

  Form = Aliases["SampleApp"]["Form"];
  // Calls the method that displays a modal form
  Result = Runner["CallObjectMethodAsync"](Form, "ShowModal");

  // Performs actions over the modal form
  ModalForm = Aliases["SampleApp"]["ModalForm"];
  …
  // Closes the modal form
  ModalForm["Close"]();
  // Waits for the method completion
  Result["WaitForCompletion"](2000);
  …
  TestedApp["Close"]();
}

See Also

Calling Methods Asynchronously
Testing Modal Windows
CallMethod Method
SetObjectPropertyAsync Method

Highlight search results