Skip to content
Get Free Trial

Mobile Common Functions

This page lists the functions common to both Android and iOS. These functions have a _m prefix in camel case, example: _mSwipeLeft. These functions work on an Android device/simulator as well as on an iOS device/simulator.

Since
Mobile Engine 7.5.0

Modes AndroidiOS

_mActivateApplication($bundleId[, $force])

Arguments

NameTypeDescription
$bundleIdstringAndroid: Package name of the application
iOS: Bundle ID of the application
$forcebooleanoptionalFlag to specify whether to start an application with clean state. If not specified, default false will be used.

Returns

null

Activates an application.

_mActivateApplication("com.android.settings", true);
_mActivateApplication("com.apple.Preferences");
Since
Mobile Engine 7.5.0

Modes AndroidiOS

_mLongClick($element[, $duration])

Arguments

NameTypeDescription
$elementMobile ElementMobile element to long click on
$durationintegeroptionalDuration for the long click.

Returns

null

_mLongClick simulates a user’s long click on the given element.

_mLongClick(_button("Click Me"));
Since
Mobile Engine 7.5.0

Modes AndroidiOS

_mPinchOpen($element, $percent, $speed)

Arguments

NameTypeDescription
$elementMobile ElementMobile element to perform pinch open action on.
$percentfloatAndroid: 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|floatAndroid: 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

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);
Since
Mobile Engine 7.5.0

Modes AndroidiOS

_mPinchClose($element, $percent, $speed)

Arguments

NameTypeDescription
$elementMobile ElementMobile element to perform pinch close action on.
$percentfloatAndroid: 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|floatAndroid: 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

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);
Since
Mobile Engine 7.5.0

Modes AndroidiOS

_mPressHome()

Arguments

NameTypeDescription
None

Returns

null

Brings up the Home screen.

_mPressHome();
Since
Mobile Engine 8.1.0

Modes AndroidiOS

_mSetOrientation($orientationType)

Arguments

NameTypeDescription
$orientationTypeOrientation type: can be PORTRAIT, PORTRAIT_UPSIDE_DOWN, LANDSCAPE_LEFT, LANDSCAPE_RIGHT

Returns

null

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");
Since
Mobile Engine 7.5.0

Modes AndroidiOS

_mOSVersion()

Arguments

NameTypeDescription
None

Returns

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

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();
Since
Mobile Engine 8.1.0

Modes AndroidiOS

_mGetOrientation()

Arguments

NameTypeDescription
None

Returns

stringDevice orientation.

Returns device orientation, for example: PORTRAIT, PORTRAIT_UPSIDE_DOWN, LANDSCAPE_LEFT, LANDSCAPE_RIGHT

var $orientation = _mGetOrientation();

These functions are used to induce swipe action on an element, for example: to delete an email from the list.

Since
Mobile Engine 7.5.0

Modes AndroidiOS

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

Arguments

NameTypeDescription
$elementMobile ElementoptionalElement to be swiped. If not specified, then it will consider the top most element to perform swipe gesture.
$percentfloatoptionalAndroid: 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.
$speedintegeroptionalAndroid: Speed to perform swipe. If not specified, default value will be used specific to device.
iOS: It is not used.

Returns

null

Swipes up on the element.

_mSwipeUp();
_mSwipeUp(_mScrollView("Test"));
_mSwipeUp(_aRelativeLayout("Swipe Me"), 0.5, 1000);
Since
Mobile Engine 7.5.0

Modes AndroidiOS

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

Arguments

NameTypeDescription
$elementMobile ElementoptionalElement to be swiped. If not specified, then it will consider the top most element to perform swipe gesture.
$percentfloatoptionalAndroid: 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.
$speedintegeroptionalAndroid: Speed to perform swipe. If not specified, default value will be used specific to device.
iOS: It is not used.

Returns

null

Swipes down on the element.

_mSwipeDown();
_mSwipeDown(_mScrollView("Test"));
_mSwipeDown(_aRelativeLayout("Swipe Me"), 0.5, 1000);
Since
Mobile Engine 7.5.0

Modes AndroidiOS

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

Arguments

NameTypeDescription
$elementMobile ElementoptionalElement to be swiped. If not specified, then it will consider the top most element to perform swipe gesture.
$percentfloatoptionalAndroid: 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.
$speedintegeroptionalAndroid: Speed to perform swipe. If not specified, default value will be used specific to device.
iOS: It is not used.

Returns

null

Swipes left on the element.

_mSwipeLeft();
_mSwipeLeft(_mScrollView("Test"));
_mSwipeLeft(_aRelativeLayout("Swipe Me"), 0.5, 1000);
Since
Mobile Engine 7.5.0

Modes AndroidiOS

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

Arguments

NameTypeDescription
$elementMobile ElementoptionalElement to be swiped. If not specified, then it will consider the top most element to perform swipe gesture.
$percentfloatoptionalAndroid: 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.
$speedintegeroptionalAndroid: Speed to perform swipe. If not specified, default value will be used specific to device.
iOS: It is not used.

Returns

null

Swipes right on the element.

_mSwipeRight();
_mSwipeRight(_mScrollView("Test"));
_mSwipeRight(_aRelativeLayout("Swipe Me"), 0.5, 1000);
Since
Mobile Engine 9.0.0

Modes AndroidiOS

_mStartWebContext($packageName)

Arguments

NameTypeDescription
$packageNamestringAndroid: application package name
iOS: Not required

Returns

null

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();
Since
Mobile Engine 9.0.0

Modes AndroidiOS

_mStopWebContext()

Arguments

NameTypeDescription
None

Returns

null

Stop the execution of following steps in Android/iOS WebView.

Since
Mobile Engine 7.5.0

Modes AndroidiOS(9.0.0)

_launchNewMobileBrowser($deviceId[, $url])

Arguments

NameTypeDescription
$deviceIdstringdeviceId of the device on which the browser will be launched.
$urlstringoptionalURL to load on opening new browser instance. If URL is null, the Start URL of the script is launched.

Returns

stringBrowser instanceId. This can be passed to _selectBrowser

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

// 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, "https://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, "https://sahitest.com/demo/");
_selectBrowser($sessionId);
...
Since
Mobile Engine 9.0.0

Modes AndroidiOS

_launchNewMobileBrowser2([$deviceId[, $url]])

Arguments

NameTypeDescription
$deviceIdstringoptionaldeviceId of the device on which the browser will be launched, If deviceId is null, the Start DeviceId of the script is used.
$urlstringoptionalURL to load on opening new browser instance. If URL is null, the Start URL of the script is launched.

Returns

stringBrowser instanceId. This can be passed to _selectBrowser

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

// For Android Browser playback
_setMode("ANDROID_BROWSER");
var $sessionId = _launchNewMobileBrowser2();
_selectBrowser();
...
// For iOS Browser playback
_setMode("IOS_BROWSER");
var $sessionId = _launchNewMobileBrowser2();
_selectBrowser();
...
Since
Mobile Engine 8.0.0

Modes AndroidiOS

_deviceInfo()

Arguments

NameTypeDescription
None

Returns

objectDevice object

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;