Android Functions
This page lists the functions specific to Android. These functions have an _a prefix in camel case, example: _aPressBack. These functions will work only on an Android device/emulator.
Action Functions
Section titled “Action Functions”_aWakeUp
Section titled “_aWakeUp”- Since
- Mobile Engine 7.5.0
Modes Android
_aWakeUp()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
null |
_aWakeUp simulates pressing the power button if the screen is OFF else it does nothing if the screen is already ON.
_aPressBack
Section titled “_aPressBack”- Since
- Mobile Engine 7.5.0
Modes Android
_aPressBack()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
null |
_aPressBack Performs a Back action.
_aPressRecentApps
Section titled “_aPressRecentApps”- Since
- Mobile Engine 7.5.0
Modes Android
_aPressRecentApps()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
null |
_aPressRecentApps Brings up the Recent Apps screen.
_aPressSearch
Section titled “_aPressSearch”- Since
- Mobile Engine 7.5.0
Modes Android
_aPressSearch()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
null |
_aPressSearch Brings up the Search box.
_aPressMenu
Section titled “_aPressMenu”- Since
- Mobile Engine 7.5.0
Modes Android
_aPressMenu()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
null |
_aPressMenu Simulates a press on the MENU button.
_aPressEnter
Section titled “_aPressEnter”- Since
- Mobile Engine 7.5.0
Modes Android
_aPressEnter()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
null |
_aPressEnter Simulates a press on the ENTER key.
_aPressDelete
Section titled “_aPressDelete”- Since
- Mobile Engine 7.5.0
Modes Android
_aPressDelete()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
null |
_aPressDelete Simulates a press on the DELETE key.
Fetch Functions
Section titled “Fetch Functions”_aIsScreenOn
Section titled “_aIsScreenOn”- Since
- Mobile Engine 7.5.0
Modes Android
_aIsScreenOn()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
boolean | true or false based based on screen is ON or OFF. |
Returns true or false based on screen is ON or OFF.
var $screenOn = _aIsScreenOn();Implicit scroll Functions for element identification
Section titled “Implicit scroll Functions for element identification”In Android, only visible elements can be interacted with. Thus if a scroll view has elements that do not lie on the screen, these elements cannot be interacted with, unless they are scrolled into view. In a scroll view that can contain different numbers of elements at different times, the user will first have to determine how much to scroll. To save the user this trouble, Sahi provides functions that automatically perform the scrolling to identify the element.
_aEnableVerticalScroll
Section titled “_aEnableVerticalScroll”- Since
- Mobile Engine 7.5.0
Modes Android
_aEnableVerticalScroll([$element[, $maxScrollCount]])Arguments
| Name | Type | Description |
|---|---|---|
$element | Android Elementoptional | Scrollable element in which subsequent elements will be searched. If not specified, top most scrollable element will be considered. |
$maxScrollCount | integeroptional | Specify maximum scroll count to attempt scrolling to identify an element. If not specified, it will perform the scrolling till the end. |
Returns
null |
Enables automatic vertical scrolling and disables horizontal scrolling for element identification. This affects all subsequent steps in the script. To turn it off, call _aDisableScroll().
Once _aEnableVerticalScroll has been called, an element is identified as follows.
- When an element is identified, if an _in clause is specified, it will be identified in that container. Else it will be identified in the topmost container.
- If the element is visible on the page, it will be identified.
- Else, if the container is scrollable, it will be scrolled vertically from the beginning till the element is identified. If the end has been reached, it means that the element has not been found.
- Else, if the container is not scrollable but contains a scrollable child container, the child container will be scrolled vertically from the beginning till the element is identified. If the end has been reached, it means that the element has not been found.
_aEnableHorizontalScroll
Section titled “_aEnableHorizontalScroll”- Since
- Mobile Engine 7.5.0
Modes Android
_aEnableHorizontalScroll([$element[, $maxScrollCount]])Arguments
| Name | Type | Description |
|---|---|---|
$element | Android Elementoptional | Scrollable element in which subsequent elements will be searched. If not specified, top most scrollable element will be considered. |
$maxScrollCount | integeroptional | Specify maximum scroll count to attempt scrolling to identify an element. If not specified, it will perform the scrolling till the end. |
Returns
null |
Enables automatic horizontal scrolling and disables vertical scrolling for element identification. This affects all subsequent steps in the script. To turn it off, call _aDisableScroll().
Once _aEnableHorizontalScroll has been called, an element is identified as follows.
- When an element is identified, if an _in clause is specified, it will be identified in that container. Else it will be identified in the topmost container.
- If the element is visible on the page, it will be identified.
- Else, if the container is scrollable, it will be scrolled horizontally from the beginning till the element is identified. If the end has been reached, it means that the element has not been found.
- Else, if the container is not scrollable but contains a scrollable child container, the child container will be scrolled horizontally from the beginning till the element is identified. If the end has been reached, it means that the element has not been found.
_aDisableScroll
Section titled “_aDisableScroll”- Since
- Mobile Engine 7.5.0
Modes Android
_aDisableScroll()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
null |
Disables automatic horizontal and vertical scrolling for element identification. This affects all subsequent steps in the script.
Once _aDisableScroll has been called, an element is identified as follows.
- When an element is identified, if an _in clause is specified, it will be identified in that container. Else it will be identified in the topmost container.
- If the element is visible on the page, it will be identified. Else it means that the element has not been found.
_aIsVerticalScrollEnabled
Section titled “_aIsVerticalScrollEnabled”- Since
- Mobile Engine 7.5.0
Modes Android
_aIsVerticalScrollEnabled()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
boolean | true or false based on vertical scrolling is enabled or not. |
Returns true if automatic vertical scrolling has been enabled by calling _aEnableVerticalScroll().
var $enabled = _aIsVerticalScrollEnabled();_aIsHorizontalScrollEnabled
Section titled “_aIsHorizontalScrollEnabled”- Since
- Mobile Engine 7.5.0
Modes Android
_aIsHorizontalScrollEnabled()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
boolean | true or false based on horizontal scrolling is enabled or not. |
Returns true if automatic horizontal scrolling has been enabled by calling _aEnableHorizontalScroll().
var $enabled = _aIsHorizontalScrollEnabled();_aIsScrollEnabled
Section titled “_aIsScrollEnabled”- Since
- Mobile Engine 7.5.0
Modes Android
_aIsScrollEnabled()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
boolean | true or false based on vertical/horizontal scrolling is enabled or not. |
Returns true if automatic horizontal or vertical scrolling has been enabled by calling _aEnableVerticalScroll() or _aEnableHorizontalScroll().
var $enabled = _aIsScrollEnabled();Explicit scroll Functions
Section titled “Explicit scroll Functions”_aScrollLeftMost
Section titled “_aScrollLeftMost”- Since
- Mobile Engine 7.5.0
Modes Android
_aScrollLeftMost($element[, $maxSwipes])Arguments
| Name | Type | Description |
|---|---|---|
$element | Android Element | element to be scrolled |
$maxSwipes | integeroptional | maximum swipes to attempt to scroll to the leftmost position. If not specified, the default max swipes as supported by the device will be used. |
Returns
boolean | true or false based based whether the element can still scroll. |
Scrolls the element’s contents to the leftmost position, i.e. it scrolls horizontally to the beginning. Returns true or false.
_aScrollLeftMost(_mScrollView("Test"));_aScrollLeftMost(_mScrollView("Test"), 5); //this will perform 5 swipes only_aScrollRightMost
Section titled “_aScrollRightMost”- Since
- Mobile Engine 7.5.0
Modes Android
_aScrollRightMost($element[, $maxSwipes])Arguments
| Name | Type | Description |
|---|---|---|
$element | Android Element | element to be scrolled |
$maxSwipes | integeroptional | maximum swipes to attempt to scroll to the rightmost position. If not specified, the default max swipes as supported by the device will be used. |
Returns
boolean | true or false based based whether the element can still scroll. |
Scrolls the element’s contents to the rightmost position, i.e. it scrolls horizontally to the end. Returns true or false.
_aScrollRightMost(_mScrollView("Test"));_aScrollRightMost(_mScrollView("Test"), 5); //this will perform 5 swipes only_aScrollTopMost
Section titled “_aScrollTopMost”- Since
- Mobile Engine 7.5.0
Modes Android
_aScrollTopMost($element[, $maxSwipes])Arguments
| Name | Type | Description |
|---|---|---|
$element | Android Element | element to be scrolled |
$maxSwipes | integeroptional | maximum swipes to attempt to scroll to the topmost position. If not specified, the default max swipes as supported by the device will be used. |
Returns
boolean | true or false based based whether the element can still scroll. |
Scrolls the element’s contents to the topmost position, i.e. it scrolls vertically to the beginning. Returns true or false.
_aScrollTopMost(_mScrollView("Test"));_aScrollTopMost(_mScrollView("Test"), 5); //this will perform 5 swipes only_aScrollBottomMost
Section titled “_aScrollBottomMost”- Since
- Mobile Engine 7.5.0
Modes Android
_aScrollBottomMost($element[, $maxSwipes])Arguments
| Name | Type | Description |
|---|---|---|
$element | Android Element | element to be scrolled |
$maxSwipes | integeroptional | maximum swipes to attempt to scroll to the bottommost position. If not specified, the default max swipes as supported by the device will be used. |
Returns
boolean | true or false based based whether the element can still scroll. |
Scrolls the element’s contents to the bottommost position, i.e. it scrolls vertically to the end. Returns true or false.
_aScrollBottomMost(_mScrollView("Test"));_aScrollBottomMost(_mScrollView("Test"), 5); //this will perform 5 swipes only_aScrollLeft
Section titled “_aScrollLeft”- Since
- Mobile Engine 7.5.0
Modes Android
_aScrollLeft($element[, $percent[, $speed]])Arguments
| Name | Type | Description |
|---|---|---|
$element | Android Element | element to be scrolled |
$percent | floatoptional | percent to scroll the element, If not specified, a value of 1.0 will be used. |
$speed | integeroptional | speed to perform scroll, If not specified, default value will be used specific to device. |
Returns
boolean | true or false based based whether the element can still scroll. |
Scrolls the element’s contents one page to the left. Returns false if content cannot be scrolled further, true otherwise.
_aScrollLeft(_mScrollView("Test"));_aScrollLeft(_mScrollView("Test"), 0.5, 1000);_aScrollRight
Section titled “_aScrollRight”- Since
- Mobile Engine 7.5.0
Modes Android
_aScrollRight($element[, $percent[, $speed]])Arguments
| Name | Type | Description |
|---|---|---|
$element | Android Element | element to be scrolled |
$percent | floatoptional | percent to scroll the element, If not specified, a value of 1.0 will be used. |
$speed | integeroptional | speed to perform scroll, If not specified, default value will be used specific to device. |
Returns
boolean | true or false based based whether the element can still scroll. |
Scrolls the element’s contents one page to the right. Returns false if content cannot be scrolled further, true otherwise.
_aScrollRight(_mScrollView("Test"));_aScrollRight(_mScrollView("Test"), 0.5, 1000);_aScrollUp
Section titled “_aScrollUp”- Since
- Mobile Engine 7.5.0
Modes Android
_aScrollUp($element[, $percent[, $speed]])Arguments
| Name | Type | Description |
|---|---|---|
$element | Android Element | element to be scrolled |
$percent | floatoptional | percent to scroll the element, If not specified, a value of 1.0 will be used. |
$speed | integeroptional | speed to perform scroll, If not specified, default value will be used specific to device. |
Returns
boolean | true or false based based whether the element can still scroll. |
Scrolls the element’s contents one page up. Returns false if content cannot be scrolled further, true otherwise.
_aScrollUp(_mScrollView("Test"));_aScrollUp(_mScrollView("Test"), 0.5, 1000);_aScrollDown
Section titled “_aScrollDown”- Since
- Mobile Engine 7.5.0
Modes Android
_aScrollDown($element[, $percent[, $speed]])Arguments
| Name | Type | Description |
|---|---|---|
$element | Android Element | element to be scrolled |
$percent | floatoptional | percent to scroll the element, If not specified, a value of 1.0 will be used. |
$speed | integeroptional | speed to perform scroll, If not specified, default value will be used specific to device. |
Returns
boolean | true or false based based whether the element can still scroll. |
Scrolls the element’s contents one page down. Returns false if content cannot be scrolled further, true otherwise.
_aScrollDown(_mScrollView("Test"));_aScrollDown(_mScrollView("Test"), 0.5, 1000);Android WebView Functions
Section titled “Android WebView Functions”_aStartWebContext (Deprecated)
Section titled “_aStartWebContext (Deprecated)”- Since
- Mobile Engine 8.0.0
Modes Android
_aStartWebContext($packageName)Arguments
| Name | Type | Description |
|---|---|---|
$packageName | string | application package name |
Returns
null |
Changes the execution mode to ANDROID_WEBVIEW and starts the execution of the following steps as Web.
_aStartWebContext("com.sahipro.SahiTestApp");_aStopWebContext (Deprecated)
Section titled “_aStopWebContext (Deprecated)”- Since
- Mobile Engine 8.0.0
Modes Android
_aStopWebContext()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
null |
Stop the execution of following steps in Android WebView.
Other Functions
Section titled “Other Functions”_aSetSwipeDeadzonePercentage
Section titled “_aSetSwipeDeadzonePercentage”- Since
- Mobile Engine 7.5.0
Modes Android
_aSetSwipeDeadzonePercentage($percent)Arguments
| Name | Type | Description |
|---|---|---|
$percent | float | percent to set the deadzone for Swipe gesture. |
Returns
null |
After leaving the dead zone area then it starts swiping.
_aSetSwipeDeadzonePercentage(0.1);
