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.

Action APIs

_mActivateApplication

Since: Sahi ProSahi OSSahi Pro StarterDesktop Add-OnMobile Add-On
NANANANA7.5.0

Available for modes: Android | iOS

_mActivateApplication($bundleId[, $force])

Arguments
$bundleIdstring Android: Package name of the application
iOS: Bundle ID of the application
$forceboolean optionalFlag to specify whether to start an application with clean state. If not specified, default false will be used.

Returns
null

Details

Activates an application.
_mActivateApplication("com.android.settings", true);
_mActivateApplication("com.apple.Preferences");


_mLongClick

Since: Sahi ProSahi OSSahi Pro StarterDesktop Add-OnMobile Add-On
NANANANA7.5.0

Available for modes: Android | iOS

_mLongClick($element[, $duration])

Arguments
$elementMobile Element Mobile element to long click on
$durationinteger optionalDuration for the long click.

Returns
null

Details

_mLongClick simulates a user's long click on the given element.
_mLongClick(_button("Click Me"));


_mPinchOpen

Since: Sahi ProSahi OSSahi Pro StarterDesktop Add-OnMobile Add-On
NANANANA7.5.0

Available for modes: Android | iOS

_mPinchOpen($element, $percent, $speed)

Arguments
$elementMobile Element Mobile element to perform pinch open action on.
$percentfloat 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
$speedinteger|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

Details

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 ProSahi OSSahi Pro StarterDesktop Add-OnMobile Add-On
NANANANA7.5.0

Available for modes: Android | iOS

_mPinchClose($element, $percent, $speed)

Arguments
$elementMobile Element Mobile element to perform pinch close action on.
$percentfloat 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
$speedinteger|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

Details

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 ProSahi OSSahi Pro StarterDesktop Add-OnMobile Add-On
NANANANA7.5.0

Available for modes: Android | iOS

_mPressHome()

Arguments
None

Returns
null

Details

Brings up the Home screen.
_mPressHome();


Fetch APIs

_mOSVersion

Since: Sahi ProSahi OSSahi Pro StarterDesktop Add-OnMobile Add-On
NANANANA7.5.0

Available for modes: Android | iOS

_mOSVersion()

Arguments
None

Returns
stringAndroid: SDK version of device/emulator.
iOS: iOS version of device/simulator.

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
var $version = _mOSVersion();


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 ProSahi OSSahi Pro StarterDesktop Add-OnMobile Add-On
NANANANA7.5.0

Available for modes: Android | iOS

_mSwipeUp([$element[, $percent[, $speed]]])

Arguments
$elementMobile Element optionalElement to be swiped. If not specified, then it will consider the top most element to perform swipe gesture.
$percentfloat optionalAndroid: 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.
$speedinteger optionalAndroid: Speed to perform swipe. If not specified, default value will be used specific to device.
iOS: It is not used.

Returns
null

Details

Swipes up on the element.
_mSwipeUp();
_mSwipeUp(_mScrollView("Test"));
_mSwipeUp(_aRelativeLayout("Swipe Me"), 0.5, 1000);


_mSwipeDown

Since: Sahi ProSahi OSSahi Pro StarterDesktop Add-OnMobile Add-On
NANANANA7.5.0

Available for modes: Android | iOS

_mSwipeDown([$element[, $percent[, $speed]]])

Arguments
$elementMobile Element optionalElement to be swiped. If not specified, then it will consider the top most element to perform swipe gesture.
$percentfloat optionalAndroid: 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.
$speedinteger optionalAndroid: Speed to perform swipe. If not specified, default value will be used specific to device.
iOS: It is not used.

Returns
null

Details

Swipes down on the element.
_mSwipeDown();
_mSwipeDown(_mScrollView("Test"));
_mSwipeDown(_aRelativeLayout("Swipe Me"), 0.5, 1000);


_mSwipeLeft

Since: Sahi ProSahi OSSahi Pro StarterDesktop Add-OnMobile Add-On
NANANANA7.5.0

Available for modes: Android | iOS

_mSwipeLeft([$element[, $percent[, $speed]]])

Arguments
$elementMobile Element optionalElement to be swiped. If not specified, then it will consider the top most element to perform swipe gesture.
$percentfloat optionalAndroid: 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.
$speedinteger optionalAndroid: Speed to perform swipe. If not specified, default value will be used specific to device.
iOS: It is not used.

Returns
null

Details

Swipes left on the element.
_mSwipeLeft();
_mSwipeLeft(_mScrollView("Test"));
_mSwipeLeft(_aRelativeLayout("Swipe Me"), 0.5, 1000);


_mSwipeRight

Since: Sahi ProSahi OSSahi Pro StarterDesktop Add-OnMobile Add-On
NANANANA7.5.0

Available for modes: Android | iOS

_mSwipeRight([$element[, $percent[, $speed]]])

Arguments
$elementMobile Element optionalElement to be swiped. If not specified, then it will consider the top most element to perform swipe gesture.
$percentfloat optionalAndroid: 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.
$speedinteger optionalAndroid: Speed to perform swipe. If not specified, default value will be used specific to device.
iOS: It is not used.

Returns
null

Details

Swipes right on the element.
_mSwipeRight();
_mSwipeRight(_mScrollView("Test"));
_mSwipeRight(_aRelativeLayout("Swipe Me"), 0.5, 1000);


Other APIs

_deviceInfo

Since: Sahi ProSahi OSSahi Pro StarterDesktop Add-OnMobile Add-On
NANANANA8.0.0

Available for modes: Android | iOS

_deviceInfo()

Arguments
None

Returns
objectDevice object

Details

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;