Dynamically Invoking Methods for Native Mobile Apps

Dynamic invoke enables you to directly call methods of the underlying Appium WebDriver for a mobile native app. This is useful whenever an Appium WebDriver method is not exposed through the Silk4NET API.

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

Supported Methods

  • When testing a native mobile application on Android, Silk4NET supports the methods available in the AndroidDriver class of the Appium Java-client API.
  • When testing a native mobile application on iOS, Silk4NET supports the methods available in the IOSDriver class of the Appium Java-client API.

Supported Parameter Types

The following parameter types are supported:
  • Primitive types (boolean, integer, long, double, string)

    Both primitive types, such as int, and object types, such as java.lang.Integer are supported. Primitive types are widened if necessary, allowing, for example, to pass an int where a long is expected.

  • Enum types

    Enum parameters must be passed as string. The string must match the name of an enum value. For example, if the method expects a parameter of the enum ScreenOrientation, you can use the string values LANDSCAPE or PORTRAIT.

  • Lists

    Allows calling methods with list, array, or var-arg parameters. Conversion to an array type is done automatically, provided the elements of the list are assignable to the target array type.

Returned Values

The following values are returned for methods that have a return value:
  • The correct value for all built-in Silk4NET types. These types are listed in the Supported Parameter Types section.
  • All methods that have no return value return null in C# or Nothing in VB.

Example

The following code sample contains some common examples for using dynamic invoke.

' VB .NET code
' Getting the page source
Dim pageSource As String = _desktop.MobileDevice("//MobileDevice").Invoke("getPageSource")

' Resetting an app
_desktop.MobileDevice("//MobileDevice").Invoke("resetApp")

' Changing the device orientation
_desktop.MobileDevice("//MobileDevice").Invoke("rotate", "LANDSCAPE")
_desktop.MobileDevice("//MobileDevice").Invoke("rotate", "PORTRAIT")

' Dynamic invoke on MobileObject (calls get redirected to the underlying web element for WebDriver)
With _desktop.MobileDevice("//MobileDevice")
  .MobileObject("CheckBox 2").Invoke("click")
End With
// C#
MobileDevice device = _desktop.MobileDevice("//MobileDevice");

// Getting the page source
var pageSource = (string) device.Invoke("getPageSource");

// Resetting an app
device.Invoke("resetApp");

// Changing the device orientation
device.Invoke("rotate", "LANDSCAPE");
device.Invoke("rotate", "PORTRAIT");

// Dynamic invoke on MobileObject (calls get redirected to the underlying web element for WebDriver)
device.MobileObject("//MobileObject[@caption='CheckBox 2']").Invoke("click");