mob
Provides methods for mobile automation.
Locators:
Native application locators for

/XPATH
- Locates element using an XPath 1.0 expression.~ACCESSIBILITY_ID
- Locates element by its Accessibility Id.id=ID
- Locates element by its id.class=CLASS
- Locates element by its class.text=TEXT
- Locates element by its visible text.text-contains=TEXT
- Locates element whose visible text contains the specified string.desc=DESCRIPTION
- Locates element by its description.desc-contains=DESCRIPTION
- Locates element whose description contains the specified string.scrollable
- Locates elements that are scrollable.
Native application locators for

/XPATH
- Locates element using an XPath 1.0 expression.id=ID
- Locates element by its ID.~ACCESSIBILITY_ID
- Locates element by its Accessibility Id.
Hybrid
and Web
application locators for




/XPATH
- Locates element using an XPath 1.0 expression.id=ID
- Locates element by its id.name=NAME
- Locates element by its name attribute.tag=NAME
- Locates element by its tag name.link=TEXT
- Locates anchor element whose text matches the given string.link-contains=TEXT
- Locates anchor element whose text contains the given string.css=CSS_SELECTOR
- Locates element using a CSS selector.
Pattern arguments:
Commands which expect a string matching pattern in their arguments, support following patterns unless specified otherwise:
regex:PATTERN
- Match using regular expression.PATTERN
- Verbatim matching.
Accepts an alert or a confirmation dialog.
In case of an alert box this command is identical to
alertDismiss
.** Usage example:**
mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.click("id=Submit");// Clicks an element and opens an alert.
mob.alertAccept();//Automatically press on 'OK' button in the alert pop-up.
Supported On:




Dismisses an alert or a confirmation dialog.
In case of an alert box this command is identical to
alertAccept
.** Usage example:**
mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.click("id=Submit");// Clicks an element and opens an alert.
mob.alertDismiss();//Automatically press on 'Cancel' button in the alert pop-up.
Supported On:




Asserts whether alert matches the specified pattern and dismisses it.
Text pattern can be any of the supported string matching patterns(on the top of page).
** Usage example:**
mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.click("id=Submit");// Clicks an element and opens an alert.
mob.assertAlert("Your Alert's text");//Asserts the alert's text.
Parameters:
Name | Type | Description |
---|---|---|
pattern | String | Text pattern. |
timeout | Number | optional Timeout in milliseconds. Default is 60 seconds. |
Supported On:

Asserts element's inner text.
Text pattern can be any of the supported string matching patterns (on the top of page). If the element is not interactable, then it will allways return empty string as its text.
** Usage example:**
mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.assertText("id=UserName","John Doe");// Asserts if an element’s text is as expected.
Parameters:
Name | Type | Description |
---|---|---|
locator | String |Element | Element locator. |
pattern | String | Assertion text or pattern. |
timeout | Number | optional Timeout in milliseconds. Default is 60 seconds. |
Supported On:




Asserts the page title.
Assertion pattern can be any of the supported string matching patterns(on the top of page).
** Usage example:**
mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.assertTitle("Your websites title!");// Asserts if the title of the page.
Parameters:
Name | Type | Description |
---|---|---|
pattern | String | Assertion text or pattern. |
timeout | Number | optional Timeout in milliseconds. Default is 60 seconds. |
Supported On:


Asserts element's value.
** Usage example:**
mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.assertValue("id=UserName", "John Doe");// Asserts if the value of an element.
Parameters:
Name | Type | Description |
---|---|---|
locator | String |Element | Element locator. |
pattern | String | Value pattern. |
timeout | Number | optional Timeout in milliseconds. Default is 60 seconds. |
Supported On:




Navigate backwards in the browser history or simulates back button on Android device.
** Usage example:**
mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.click("id=NextPage);// Clicks an element and opens an alert.
mob.back();//Navigate back to previous page.
Supported On:



Clears element's value or content
** Usage example:**
mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.type("id=Password", "Password");//Types a password to a field.
mob.clear("id=Password");//Clears the characters from the field of an element.
Parameters:
Name | Type | Description |
---|---|---|
locator | String |Element | Element locator. |
timeout | Number | optional Timeout in milliseconds. Default is 60 seconds. |
Supported On:




Clicks on an element.
** Usage example:**
mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.click("id=Submit");// Clicks an element.
Parameters:
Name | Type | Description |
---|---|---|
locator | String |Element | Element locator. |
timeout | Number | optional Timeout in milliseconds. Default is 60 seconds. |
Supported On:




Clicks on a non-visible element.
** Usage example:**
mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.clickHidden("id=hiddenContent);// Clicks an hidden element.
Parameters:
Name | Type | Description |
---|---|---|
locator | String |Element | Element locator. |
clickParent | Boolean | optional If true, then parent of the element is clicked. |
Supported On:


Performs a long click/touch on an element.
** Usage example:**
mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.clickLong("id=Mark",6000);// Clicks an element for a certain duration.
Parameters:
Name | Type | Description |
---|---|---|
locator | String |Element | Element locator. |
duration | Number | Touch duration in milliseconds. |
timeout | Number | optional Timeout in milliseconds. Default is 60 seconds. |
Supported On:




Performs tap on an element multiple times in quick succession.
** Usage example:**
mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.clickMultipleTimes("id=Mark",4);// Clicks an element certain amount of times.
Parameters:
Name | Type | Description |
---|---|---|
locator | String |Element | Element locator. |
taps | Number | Number of taps. |
timeout | Number | optional Timeout in milliseconds. Default is 60 seconds. |
Supported On:




Closes the currently open app.
** Usage example:**
mob.init(caps); // Starts a mobile session and opens app from desired capabilities
mob.launchApp(); // Launch the app.
mob.closeApp(); // Close the app.
Supported On:


Stop test execution and allow interactive command execution (REPL).
** Usage example:**
mob.init();
mob.open("www.yourwebsite.com");
mob.debug();
Supported On:




Ends the current session.
Parameters:
Name | Type | Description |
---|---|---|
status | String | optional Test status, either passed or failed . |
Tap on an element, drag by the specified offset, and release.
** Usage example:**
mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.dragAndDrop("id=Mark",-80,100);// Tap on an element, drag by the specified offset, and release.
Parameters:
Name | Type | Description |
---|---|---|
locator | String |Element | Element locator on which to perform the initial tap. |
xoffset | Number | Horizontal offset. Positive for right direction; Negative for left. |
yoffset | Number | Vertical offset. Positive for down direction; Negative for up. |
timeout | Number | optional Timeout in milliseconds. Default is 60 seconds. |
Supported On:


Enable or disable wifi or data.
** Usage example:**
mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.enableNetwork(true,false);//Enable wifi and disable data.
Parameters:
Name | Type | Description |
---|---|---|
wifi | Boolean | Enable (true) or disable (false) wifi. |
data | Boolean | Enable (true) or disable (false) data. |
Supported On:

Executes JavaScript in the context of the currently selected frame or window.
If return value is null or there is no return value,
null
is returned.** Usage example:**
mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.execute(function(){
angular.element("#closeBtn").trigger('ng-click').click()
});//Executes / injects a javascript functions.
Parameters:
Name | Type | Description |
---|---|---|
script | String |Function | The JavaScript to execute. |
arg | ...Object | optional Optional arguments to be passed to the JavaScript function. |
Returns:
Object
- The return value.Supported On:


Finds an element.
** Usage example:**
mob.init(caps);//Starts a mobile session and opens app from desired capabilities
var el = mob.findElement("id=Password");
mob.click(el);
Parameters:
Name | Type | Description |
---|---|---|
locator | String | Element locator. |
parent | Element | optional Optional parent element for relative search. |
timeout | Number | optional Timeout in milliseconds. Default is 60 seconds. |
Returns:
Element
- A Element object.Supported On:




Finds elements.
** Usage example:**
mob.init(caps);//Starts a mobile session and opens app from desired capabilities
var els = mob.findElements("//div");
for (let el of els) {
var text = mob.getText(el);
log.info(text);
}
Parameters:
Name | Type | Description |
---|---|---|
locator | String | Element locator. |
parent | Element | optional Optional parent element for relative search. |
timeout | Number | optional Timeout in milliseconds. Default is 60 seconds. |
Returns:
Array.<Element>
- Collection of Element objects.Supported On:




Gets the text displayed by an alert or confirm dialog.
** Usage example:**
mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.click("id=Submit");// Clicks an element and opens an alert.
var a = mob.getAlertText();//Gets alert text.
Returns:
String
- Alert's text.Supported On:




Collects logs from the Appium server.
** Usage example:**
mob.init(caps); //Starts a mobile session and opens app from desired capabilities
mob.getAppiumLogs(); //Collects logs from the Appium server
Returns:
Array.<Object>
- A list of logs.Supported On:




Collects browser logs from the mobile device.
** Usage example:**
mob.init(caps); //Starts a mobile session and opens app from desired capabilities
mob.getBrowserLogs(); //Collects logs from the browser console
Returns:
Array.<Object>
- A list of logs.Supported On:




Returns currently defined capabilities.
Returns:
Object
- Current capabilities object.Gets current Android app's activity name.
** Usage example:**
mob.init(caps); // Starts a mobile session and opens app from desired capabilities
let activity = mob.getCurrentActivity(); // Gets current Android activity.
Supported On:

Gets current Android app's package name.
** Usage example:**
mob.init(caps); // Starts a mobile session and opens app from desired capabilities
let package = mob.getCurrentPackage(); // Gets current Android package.
Supported On:

Collects logs from the mobile device.
** Usage example:**
mob.init(caps); //Starts a mobile session and opens app from desired capabilities
mob.getDeviceLogs(); //Collects logs from the mobile device
Returns:
Array.<Object>
- A list of logs.Supported On:




Gets the time on the device.
** Usage example:**
mob.init(caps); //Starts a mobile session and opens app from desired capabilities
mob.getDeviceTime(); //Gets the device time
Returns:
String
- Time.Supported On:


Returns the underlying WDIO driver.
Returns:
Object
- WDIO driver.Get element's location.
** Usage example:**
mob.init(caps);//Starts a mobile session and opens app from desired capabilities
var loc = mob.getLocation("id=element");//Get element's location.
var x = loc.x;
var y = loc.y;
Parameters:
Name | Type | Description |
---|---|---|
locator | String |Element | Element locator. |
timeout | Number | optional Timeout in milliseconds. Default is 60 seconds. |
Returns:
Object
- X and Y location of the element relative to top-left page corner.Supported On:




Gets the source code of the page.
** Usage example:**
mob.init(caps);//Starts a mobile session and opens app from desired capabilities
var a = mob.getSource();//Gets the source code of the page.
Returns:
String
- HTML in case of web or hybrid application or XML in case of native.Supported On:




Returns the text (rendered text shown to the user; whitespace-trimmed) of an element.
** Usage example:**
mob.init(caps);//Starts a mobile session and opens app from desired capabilities
var a = mob.getText("id=TextArea");//Gets the text from an element.
Parameters:
Name | Type | Description |
---|---|---|
locator | String |Element | Element locator. |
timeout | Number | optional Timeout in milliseconds. Default is 60 seconds. |
Returns:
String
- Element's text.Supported On:




Returns the title of the currently active window.
Returns:
String
- The page title.Supported On:

Gets the URL of the currently active window.
** Usage example:**
mob.init();//Opens browser session.
mob.open("www.yourwebsite.com");// Opens a website.
mob.getUrl();//Gets the url from the current page.
Returns:
String
- The page URL.Supported On:

Gets element's value (whitespace-trimmed).
** Usage example:**
mob.init(caps);
var a = mob.getValue("id=ValueArea");//Gets the value from an element.
Parameters:
Name | Type | Description |
---|---|---|
locator | String |Element | Element locator. |
timeout | Number | optional Timeout in milliseconds. Default is 60 seconds. |
Returns:
String
- Element's value.Supported On:




Gets handles of currently open windows.
** Usage example:**
mob.init();// Starts a mobile session.
mob.open("www.yourwebsite.com");// Opens a website.
mob.getWindowHandles();//Gets the window handles of currently open windows.
Returns:
Array.<String>
- Array of all available window handles.Supported On:

Hides device keyboard.
** Usage example:**
mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.type("id=Password", "Password");//Types a password to a field.
mob.hideKeyboard("pressKey", "Done");//Hides device keyboard.
Parameters:
Name | Type | Description |
---|---|---|
strategy | String | optional Strategy to use for closing the keyboard - 'press', 'pressKey', 'swipeDown', 'tapOut', 'tapOutside', 'default'. |
key | String | optional Key value if strategy is 'pressKey'. |
keyCode | String | optional Key code if strategy is 'pressKey'. |
keyName | String | optional Key name if strategy is 'pressKey'. |
Supported On:



Initializes a new Appium session.
Parameters:
Name | Type | Description |
---|---|---|
caps | String | optional Desired capabilities. If not specified capabilities will be taken from suite definition. |
appiumUrl | String | optional Remote Appium server URL (default: http://localhost:4723/wd/hub). |
Install an app on the remote device.
** Usage example:**
mob.init(caps); // Starts a mobile session and opens app from desired capabilities
mob.installApp('/mylocalappfile.apk'); // Install the app.
Parameters:
Name | Type | Description |
---|---|---|
appLocalPath | String | The local file path to APK or IPA file. |
Supported On:


Determines if an app is installed on the device.
** Usage example:**
mob.init(caps); //Starts a mobile session and opens app from desired capabilities
let installed = mob.isAppInstalled('com.android.calculator2'); // Determines if calculator app is installed.