Silk Mobile

Table of Contents (Homepage)

RunNativeAPICall

RunNativeAPICall(Zone, Element, Index, Text)

Note: Command will work only after application preparation .

images/images/os-icons/os_ios_150x150.png

images/images/os-icons/os_android_150x150.png

images/images/os-icons/os_windows_150x150.png

Description

Gives the ability to create and run scripts that are based on the Native API methods available for the class of the element.

Parameters

  • Zone: Select Zone

  • Element: Select Element (should use xPath)

  • Index: Element index

  • Script: The Native API script that will run on the identified element

Usage

Scenario: In the following example, we will use the Android Native API methods in order to inspect and manipulate a video that is playing on the device.

First, we will identify in the object spy the element on which we want to create the API call script. In this case, we will select the element of classandroid.widget.VideoView, since it is the one responsible for playing the video. After that, right click on the element in the object spy hierarchy tree, and click on the API Call.

images/download/attachments/2689193/1.jpg

A new dialog box will open up. In the Methods list, we can now observe all the different Native API functions that are available for this specific class (android.widget.VideoView).

images/download/attachments/2689193/2.jpg

We can now create a script based on the available methods. The script can include one or more different methods. In this example, our script will include 3 different methods:

  • view.pause - will pause the video.

  • view.getDuration - will return the total length of the video in milliseconds.

  • view.seekTo - will move the video to a specific time position.

images/download/attachments/2689193/3.jpg

The script will pause the video, get its total duration, and then move to the time position where the video is at 90% completion. Notice that the script can also include variables that are defined and returned and actions that are not directly related to the element itself (like calculating the 90% time position).

The script can now be tested by using the Test button. The actions will be performed on the device, and if the script returns a value it will it show in the return box. After the script is tested and ready, clicking the Add button will automatically add the script as a command to the studio command tab.

images/download/attachments/2689193/4.jpg

To exit the API Call dialog box, click the OK button.

Code Examples

Java Example
String str3 = client.runNativeAPICall("NATIVE", "xpath=//*[@id='video_view']", 0, "view.pause(); var length = view.getDuration(); length = length*0.9; view.seekTo(length);");
C# Example
string str3 = client.RunNativeAPICall("NATIVE", "xpath=//*[@id='video_view']", 0, "view.pause(); var length = view.getDuration(); length = length*0.9; view.seekTo(length);");
VBScript Example
str7 = client.RunNativeAPICall ( "NATIVE", "xpath=//*[@id='video_view']", 0, "view.pause(); var length = view.getDuration(); length = length*0.9; view.seekTo(length);" )
Report
Python Example
var3 = self.client.runNativeAPICall("NATIVE", "xpath=//*[@id='video_view']", 0, "view.pause(); var length = view.getDuration(); length = length*0.9; view.seekTo(length);")
Perl Example
my $str3 = $client->runNativeAPICall("NATIVE", "xpath=//*[\@id='video_view']", 0, "view.pause(); var length = view.getDuration(); length = length*0.9; view.seekTo(length);");