Mobile Common APIs
This page lists the APIs common to both Android and iOS. These APIs have a _m prefix in camel case, example: _mSwipeLeft.
These APIs work on an Android device/simulator as well as on an iOS device/simulator.
These APIs work on an Android device/simulator as well as on an iOS device/simulator.
Action APIs
_mActivateApplication
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
NA | NA | 7.5.0 | NA | NA |
Available for modes: Android | iOS
_mActivateApplication($bundleId[, $force])
Arguments
$bundleId | string | Android: Package name of the application iOS: Bundle ID of the application |
$force | boolean optional | Flag to specify whether to start an application with clean state. If not specified, default false will be used. |
Returns
null |
Sahi Pro Flowcharts Action :Activate Application
Details
Activates an application.
Activates an application.
_mActivateApplication("com.android.settings", true);
_mActivateApplication("com.apple.Preferences");
_mLongClick
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
NA | NA | 7.5.0 | NA | NA |
Available for modes: Android | iOS
_mLongClick($element[, $duration])
Arguments
$element | Mobile Element | Mobile element to long click on |
$duration | integer optional | Duration for the long click. |
Returns
null |
Sahi Pro Flowcharts Action :MLong Click
Details
_mLongClick simulates a user's long click on the given element.
_mLongClick simulates a user's long click on the given element.
_mLongClick(_button("Click Me"));
_mPinchOpen
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
NA | NA | 7.5.0 | NA | NA |
Available for modes: Android | iOS
_mPinchOpen($element, $percent, $speed)
Arguments
$element | Mobile Element | Mobile element to perform pinch open action on. |
$percent | float | Android: Optional. The size of the pinch as a percentage of this element's size. If not specified, a value of 1.0 will be used. iOS: Needs to be specified. Scale of the pinch gesture. Has to be greater than 1 |
$speed | integer|float | Android: Optional. Speed to perform the pinch gesture, to be specified as an integer . If not specified, default value will be used specific to device. iOS: Needs to be specified. Velocity of the pinch in scale factor per second, to be specified as a float. Has to be greater than or equal to 0. |
Returns
null |
Sahi Pro Flowcharts Action :MPinch Open
Details
Performs a pinch open gesture on the given element.
Performs a pinch open gesture on the given element.
Android:
_mPinchOpen(_image("abc"));
_mPinchOpen(_image("abc"), 0.5, 2000);
iOS:
_mPinchOpen(_image("abc"), 1.5, 0.8);
_mPinchClose
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
NA | NA | 7.5.0 | NA | NA |
Available for modes: Android | iOS
_mPinchClose($element, $percent, $speed)
Arguments
$element | Mobile Element | Mobile element to perform pinch close action on. |
$percent | float | Android: Optional. The size of the pinch as a percentage of this element's size. If not specified, a value of 1.0 will be used. iOS: Needs to be specified. Scale of the pinch gesture. Should be between 0 and 1 |
$speed | integer|float | Android: Optional. Speed to perform the pinch gesture, to be specified as an integer. If not specified, default value will be used specific to device. iOS: Needs to be specified. Velocity of the pinch in scale factor per second, to be specified as a float. Has to be lesser than 0. If a positive value is given, it will be converted to a negative value. |
Returns
null |
Sahi Pro Flowcharts Action :MPinch Close
Details
Performs a pinch close gesture on the given element.
Performs a pinch close gesture on the given element.
Android:
_mPinchClose(_image("abc"));
_mPinchClose(_image("abc"), 0.5, 2000);
iOS:
_mPinchClose(_image("abc"), 0.5, -0.8);
_mPressHome
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
NA | NA | 7.5.0 | NA | NA |
Available for modes: Android | iOS
_mPressHome()
Arguments
None |
Returns
null |
Sahi Pro Flowcharts Action :Press Home
Details
Brings up the Home screen.
Brings up the Home screen.
_mPressHome();
_mSetOrientation
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
NA | NA | 8.1.0 | NA | NA |
Available for modes: Android | iOS
_mSetOrientation($orientationType)
Arguments
$orientationType | Orientation type: can be PORTRAIT, PORTRAIT_UPSIDE_DOWN, LANDSCAPE_LEFT, LANDSCAPE_RIGHT |
Returns
null |
Sahi Pro Flowcharts Action :MSet Orientation
Details
Rotate the device screen based on the orientation type.
Rotate the device screen based on the orientation type.
// Rotate the screen in portrait mode.
_mSetOrientation("PORTRAIT");
// Rotate the screen upside down in portrait mode.
_mSetOrientation("PORTRAIT_UPSIDE_DOWN");
// Rorate the screen to the left side.
_mSetOrientation("LANDSCAPE_LEFT");
// Rorate the screen to the right side.
_mSetOrientation("LANDSCAPE_RIGHT");
infoNote:
PORTRAIT_UPSIDE_DOWN
is not supported in Android.Fetch APIs
_mOSVersion
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
NA | NA | 7.5.0 | NA | NA |
Available for modes: Android | iOS
_mOSVersion()
Arguments
None |
Returns
string | Android: SDK version of device/emulator. iOS: iOS version of device/simulator. |
Sahi Pro Flowcharts Action :MOSVersion
Details
Android: Returns the SDK Level of the Android device, for example: 21 for Lollypop, 20 for Kitkat etc.
iOS: Returns the iOS version of the iOS device, for example: 11.2.6
Android: Returns the SDK Level of the Android device, for example: 21 for Lollypop, 20 for Kitkat etc.
iOS: Returns the iOS version of the iOS device, for example: 11.2.6
var $version = _mOSVersion();
_mGetOrientation
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
NA | NA | 8.1.0 | NA | NA |
Available for modes: Android | iOS
_mGetOrientation()
Arguments
None |
Returns
string | Device orientation. |
Sahi Pro Flowcharts Action :MGet Orientation
Details
Returns device orientation, for example:
Returns device orientation, for example:
PORTRAIT
, PORTRAIT_UPSIDE_DOWN
, LANDSCAPE_LEFT
, LANDSCAPE_RIGHT
var $orientation = _mGetOrientation();
Swipe APIs
These APIs are used to induce swipe action on an element, for example: to delete an email from the list._mSwipeUp
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
NA | NA | 7.5.0 | NA | NA |
Available for modes: Android | iOS
_mSwipeUp([$element[, $percent[, $speed]]])
Arguments
$element | Mobile Element optional | Element to be swiped. If not specified, then it will consider the top most element to perform swipe gesture. |
$percent | float optional | Android: The length of the swipe as a percentage of the element's size. If not specified, a value of 1.0 will be used. iOS: It is not used. |
$speed | integer optional | Android: Speed to perform swipe. If not specified, default value will be used specific to device. iOS: It is not used. |
Returns
null |
Sahi Pro Flowcharts Action :Swipe Up
Details
Swipes up on the element.
Swipes up on the element.
_mSwipeUp();
_mSwipeUp(_mScrollView("Test"));
_mSwipeUp(_aRelativeLayout("Swipe Me"), 0.5, 1000);
_mSwipeDown
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
NA | NA | 7.5.0 | NA | NA |
Available for modes: Android | iOS
_mSwipeDown([$element[, $percent[, $speed]]])
Arguments
$element | Mobile Element optional | Element to be swiped. If not specified, then it will consider the top most element to perform swipe gesture. |
$percent | float optional | Android: The length of the swipe as a percentage of the element's size. If not specified, a value of 1.0 will be used. iOS: It is not used. |
$speed | integer optional | Android: Speed to perform swipe. If not specified, default value will be used specific to device. iOS: It is not used. |
Returns
null |
Sahi Pro Flowcharts Action :Swipe Down
Details
Swipes down on the element.
Swipes down on the element.
_mSwipeDown();
_mSwipeDown(_mScrollView("Test"));
_mSwipeDown(_aRelativeLayout("Swipe Me"), 0.5, 1000);
_mSwipeLeft
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
NA | NA | 7.5.0 | NA | NA |
Available for modes: Android | iOS
_mSwipeLeft([$element[, $percent[, $speed]]])
Arguments
$element | Mobile Element optional | Element to be swiped. If not specified, then it will consider the top most element to perform swipe gesture. |
$percent | float optional | Android: The length of the swipe as a percentage of the element's size. If not specified, a value of 1.0 will be used. iOS: It is not used. |
$speed | integer optional | Android: Speed to perform swipe. If not specified, default value will be used specific to device. iOS: It is not used. |
Returns
null |
Sahi Pro Flowcharts Action :Swipe Left
Details
Swipes left on the element.
Swipes left on the element.
_mSwipeLeft();
_mSwipeLeft(_mScrollView("Test"));
_mSwipeLeft(_aRelativeLayout("Swipe Me"), 0.5, 1000);
_mSwipeRight
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
NA | NA | 7.5.0 | NA | NA |
Available for modes: Android | iOS
_mSwipeRight([$element[, $percent[, $speed]]])
Arguments
$element | Mobile Element optional | Element to be swiped. If not specified, then it will consider the top most element to perform swipe gesture. |
$percent | float optional | Android: The length of the swipe as a percentage of the element's size. If not specified, a value of 1.0 will be used. iOS: It is not used. |
$speed | integer optional | Android: Speed to perform swipe. If not specified, default value will be used specific to device. iOS: It is not used. |
Returns
null |
Sahi Pro Flowcharts Action :Swipe Right
Details
Swipes right on the element.
Swipes right on the element.
_mSwipeRight();
_mSwipeRight(_mScrollView("Test"));
_mSwipeRight(_aRelativeLayout("Swipe Me"), 0.5, 1000);
WebView APIs
_mStartWebContext
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
NA | NA | 9.0.0 | NA | NA |
Available for modes: Android | iOS
_mStartWebContext($packageName)
Arguments
$packageName | string | Android: application package name iOS: Not required |
Returns
null |
Sahi Pro Flowcharts Action :MStart Web Context
Details
Changes the execution mode to
Changes the execution mode to
ANDROID_WEBVIEW
/IOS_WEBVIEW
and starts the execution of the following steps as Web.
Android:
_mStartWebContext("com.sahipro.SahiTestApp");
iOS:
_mStartWebContext();
infoFor playback on any
1.
2. Configure the proxy in
Android
/iOS
application which contains Webview (Hybrid contents)
1.
Android
/iOS
Device must be connected on the same network in which Sahi Pro is running.
2. Configure the proxy in
Android
/iOS
Device.infoSpecify the _mStopWebContext() API to stop the execution of the script in Android WebView mode.
_mStopWebContext
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
NA | NA | 9.0.0 | NA | NA |
Available for modes: Android | iOS
_mStopWebContext()
Arguments
None |
Returns
null |
Sahi Pro Flowcharts Action :MStop Web Context
Details
Stop the execution of following steps in Android/iOS WebView.
Stop the execution of following steps in Android/iOS WebView.
Mobile Browser APIs
_launchNewMobileBrowser
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
NA | NA | 7.5.0 | NA | NA |
Available for modes: Android | iOS(9.0.0)
_launchNewMobileBrowser($deviceId[, $url])
Arguments
$deviceId | string | deviceId of the device on which the browser will be launched. |
$url | string optional | URL to load on opening new browser instance. If URL is null, the Start URL of the script is launched. |
Returns
string | Browser instanceId. This can be passed to _selectBrowser |
Sahi Pro Flowcharts Action :Launch New Mobile Browser
Details
Returns the browserInstanceId Launches a new browser instance. This instance does not share cookies with the base browser.
Once launched, steps can be directed to different browser instances via
Returns the browserInstanceId Launches a new browser instance. This instance does not share cookies with the base browser.
Once launched, steps can be directed to different browser instances via
_selectBrowser
infoMode has to be set to ANDROID_BROWSER or IOS_BROWSER using _setMode before calling this API.
infoNote: Mainly used along with the _connectDevice. User must pass the deviceId returned by _connectDevice API.
// for Android
_setMode("ANDROID_BROWSER");
// _connectDevice will return the deviceId and use that deviceId as parameter in _launchNewMobileBrowser
var $deviceId = _connectDevice();
// It will launch browser with Specified URL.
var $sessionId = _launchNewMobileBrowser($deviceId, "http://sahitest.com/demo/");
_selectBrowser($sessionId);
...
// for iOS
_setMode("IOS_BROWSER");
// _connectDevice will return the deviceId and use that deviceId as parameter in _launchNewMobileBrowser
var $deviceId = _connectDevice();
// It will launch browser with Specified URL.
var $sessionId = _launchNewMobileBrowser($deviceId, "http://sahitest.com/demo/");
_selectBrowser($sessionId);
...
_launchNewMobileBrowser2
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
NA | NA | 9.0.0 | NA | NA |
Available for modes: Android | iOS
_launchNewMobileBrowser2([$deviceId[, $url]])
Arguments
$deviceId | string optional | deviceId of the device on which the browser will be launched, If deviceId is null, the Start DeviceId of the script is used. |
$url | string optional | URL to load on opening new browser instance. If URL is null, the Start URL of the script is launched. |
Returns
string | Browser instanceId. This can be passed to _selectBrowser |
Sahi Pro Flowcharts Action :Launch New Mobile Browser2
Details
Returns the browserInstanceId.
Launches a new browser instance. This instance does not share cookies with the base browser.
Once launched, steps can be directed to different browser instances via
Returns the browserInstanceId.
Launches a new browser instance. This instance does not share cookies with the base browser.
Once launched, steps can be directed to different browser instances via
_selectBrowser
infoMode has to be set to ANDROID_BROWSER or IOS_BROWSER using _setMode before calling this API.
warningNote: Unlike _launchNewMobileBrowser, this API will consume the device from the capacities.
// For Android Browser playback
_setMode("ANDROID_BROWSER");
var $sessionId = _launchNewMobileBrowser2();
_selectBrowser();
...
// For iOS Browser playback
_setMode("IOS_BROWSER");
var $sessionId = _launchNewMobileBrowser2();
_selectBrowser();
...
Other APIs
_deviceInfo
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
NA | NA | 8.0.0 | NA | NA |
Available for modes: Android | iOS
_deviceInfo()
Arguments
None |
Returns
object | Device object |
Sahi Pro Flowcharts Action :Device Info
Details
Returns device information as an associative array. Array contains following information:
Returns device information as an associative array. Array contains following information:
- name: Name of the device specified in
userdata/config/(android_devices.xml or ios_devices.xml)
- displayName: Display name of the device specified in
userdata/config/(android_devices.xml or ios_devices.xml)
- deviceName: Device name
- deviceId: Device Id.
- version: Device OS version
var $deviceInfo = _deviceInfo();
var $displayName = $deviceInfo["displayName"];
// or
var $displayName = $deviceInfo.displayName;