Dynamically Invoking SAP Methods

Dynamic invoke enables you to directly call methods, retrieve properties, or set properties, on an actual instance of a control in the application under test. You can also call methods and properties that are not available in the Silk Test Classic API for this control. Dynamic invoke is especially useful when you are working with custom controls, where the required functionality for interacting with the control is not exposed through the Silk Test Classic API.

Call dynamic methods on objects with the DynamicInvoke method. To retrieve a list of supported dynamic methods for a control, use the GetDynamicMethodList method.

Call multiple dynamic methods on objects with the DynamicInvokeMethods method. To retrieve a list of supported dynamic methods for a control, use the GetDynamicMethodList method.

Retrieve dynamic properties with the GetProperty method and set dynamic properties with the SetProperty method. To retrieve a list of supported dynamic properties for a control, use the GetPropertyList method.

For example, to call a method named SetTitle, which requires the title to be set as an input parameter of type string, on an actual instance of a control in the application under test, type the following:
control.DynamicInvoke("SetTitle", {"my new title"})
Note: Typically, most properties are read-only and cannot be set.
Note: Reflection is used in most technology domains to call methods and retrieve properties.

Supported Methods and Properties

The following methods and properties can be called:
  • Methods and properties that Silk Test Classic supports for the control.
  • All public methods that the SAP automation interface defines
  • If the control is a custom control that is derived from a standard control, all methods and properties from the standard control can be called.

Supported Parameter Types

The following parameter types are supported:
  • All built-in Silk Test Classic types

    Silk Test Classic types includes primitive types (such as boolean, int, string), lists, and other types (such as Point and Rect).

  • UI controls

    UI controls can be passed or returned as AnyWin.

Returned Values

The following values are returned for properties and methods that have a return value:
  • The correct value for all built-in Silk Test Classic types. These types are listed in the Supported Parameter Types section.
  • All methods that have no return value return NULL.

Example

A custom calculator control has a Reset method and an Add method, which performs an addition of two numbers. You can use the following code to call the methods directly from your tests:
customControl.Invoke("Reset")
REAL sum = customControl.DynamicInvoke("Add",{1,2})