Skip to main content

SeeTest Client - RunNativeAPICall

info

Please note that this tool is classified as a Legacy tool. We recommend transitioning to our updated solutions to maintain optimal performance and security in your workflows. For more information on this matter, please reach out to technical support .

RunNativeAPICall(Zone, Element, Index, Text)

info

Note: This command will work only on instrumented applications. for more information see application preparation.

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.

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).

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.

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.

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 Expand source

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 Expand source

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 Expand source

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 Expand source

my $str3 = $client->runNativeAPICall("NATIVE", "xpath=//*[\@id='video_view']", 0, "view.pause(); var length = view.getDuration(); length = length*0.9; view.seekTo(length);");