Invoke Method (TestObject)

Class

TestObject.

Action

Dynamically invokes a method on the test object. Returns null for methods with the return type void.

Invoke can dynamically invoke all public methods that the MSDN defines for the test object. For test objects in a Windows Forms application or a WPF application, Invoke can additionally invoke all public static methods that the MSDN defines and all user-defined public static methods of any type.

Syntax

C#
TestObject.Invoke(methodName, [parameters])
VB
TestObject.Invoke(methodName, [parameters])
Variable Description
methodName The method name, such as Select. String.
parameters The method parameters. If the function requires no parameters an empty list is passed.

Example 1

For an object of the type DataGrid, you can call all methods that the MSDN defines for the type System.Windows.Forms.DataGrid.

Example 2

To call the static .NET method String.Compare(String s1, String s2) inside the application under test, use the following code:
//VB .NET code
Dim result as Integer = mainWindow.Invoke("System.String.Compare", "a", "b")
//C# code
int result = (int) mainWindow.Invoke("System.String.Compare", "a", "b");

The object mainWindow only identifies the application inside which the method is called and can be replaced by any other object in the application.