mob

Provides methods for mobile automation.

Locators:

Native application locators for
  • /XPATH - Locates element using an XPath 1.0 expression.
  • 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.
Hybridand Webapplication 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.
  • 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.

Methods

getCaps()→ {Object}

Returns currently defined device capabilities.

Returns:
Object - capabilities - Current capabilities object.

init(caps, host, port)

Initializes a new Appium session.

Parameters:
Name Type Description
caps String= optionalDesired capabilities. If not specified capabilities will be taken from suite definition.
host String= optionalAppium server host name or Selenium Grid full URL (default: localhost).
port Number= optionalAppium server port (default: 4723). If full URL is specified in the host parameter, port parameter must not be specified.

transaction(name)

Opens new transaction.

The transaction will persist till a new one is opened. Transaction names must be unique.

Parameters:
Name Type Description
name String The transaction name.

dispose()

Ends the current session.

alertAccept()

Accepts currently displayed alert.


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.

alertDismiss()

Dismisses currently displayed alert.


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.

assertText(locator, pattern, message)

Asserts element's inner 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|WebElement) Element locator.
pattern String Assertion text or pattern.
message String= optionalMessage to generate in case of assert failure.

assertTitle(pattern, message)

Asserts the page title.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.assertTitle ("title=Your websites title!");// Asserts if the title of the page.
Parameters:
Name Type Description
pattern String Assertion text or pattern.
message String= optionalMessage to generate in case of assert failure.

assertValue(locator, pattern, message)

Asserts element's value.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.assertValue ("id=UserName", "value=John Doe");// Asserts if the value of an element.
Parameters:
Name Type Description
locator (String|WebElement) Element locator.
pattern String Assertion text or pattern.
message String= optionalMessage to generate in case of assert failure.

back()

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.

clear(locator)

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|WebElement) Element locator.

click(locator)

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|WebElement) Element locator.

clickHidden(locator, clickParent)

Clicks hidden 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|WebElement) Element locator.
clickParent Boolean= optionalIf true, then parent of the element is clicked.

clickLong(locator, duration)

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|WebElement) Element locator.
duration Number Touch duration in milliseconds.

clickMultipleTimes(locator, taps)

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|WebElement) Element locator.
taps Number Number of taps.

dragAndDrop(locator, xoffset, yoffset)

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|WebElement) Element locator on which to perform the initial tap.
xoffset Number Horizontal offset. Positive for right direction; Negative for left.
yoffset Number Vertical offset. Negative for down direction; Positive for up.

enableNetwork(wifi, data)

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 or disable wifi or data.
Parameters:
Name Type Description
wifi Boolean Enable (true) or disable (false) wifi.
data Boolean Enable (true) or disable (false) data.

execute(script, arg)→ {Object}

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 optionalOptional script arguments.
Returns:
Object - The return value.

findElement(locator, parent)→ {WebElement}

Finds an element.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.findElement("id=Password","id=divPass");//Finds an element.
Parameters:
Name Type Description
locator String Element locator.
parent Object= optionalOptional parent element for relative search.
Returns:
WebElement - A WebElement object.

findElements(locator, parent)→ {Array.<WebElement>}

Finds elements.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.findElement("//div[@class='Headers']","id=divHeaders); //Finds elements.
Parameters:
Name Type Description
locator String Element locator.
parent Object= optionalOptional parent element for relative search.
Returns:
Array.<WebElement> - Collection of WebElement JSON objects.

alertText()→ {String}

Gets alert text.


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.alertText();//Gets alert text.
Returns:
String - Alert's text.

getAppiumLogs()→ {String}

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:
String - A list of logs.

getDeviceLogs()→ {String}

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 browser console or mobile device
Returns:
String - A list of logs.

getDeviceTime()→ {String}

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.

getLocation(locator)

Get element's location.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
var a = mob.getLocation("id=Element");//Get element's location.
Parameters:
Name Type Description
locator (String|WebElement) Element locator.

getSource()→ {String}

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.

getText(locator)→ {String}

Gets element's text.


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|WebElement) Element locator.
Returns:
String - Element's text.

getValue(locator)→ {String}

Gets element's value.


Usage example

mob.init(caps);
var a = mob.getValue("id=ValueArea");//Gets the value from an element.
Parameters:
Name Type Description
locator (String|WebElement) Element locator.
Returns:
String - Element's value.

hideKeyboard(strategy)

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("tapOutside");//Hides device keyboard.
Parameters:
Name Type Description
strategy String= optionalStrategy to use for closing the keyboard - `tapOutside` or `pressDone`. Default is `tapOutside`.

isCheckable(locator)→ {Boolean}

Determines if checkbox or radio element is checkable.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.isCheckable("id=checkBox");//Determines if checkbox or radio element is checkable.
Parameters:
Name Type Description
locator (String|WebElement) Element locator.
Returns:
Boolean - true if element is checkable. false otherwise.

isChecked(locator)→ {Boolean}

Determines if checkbox or radio element is checked.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.isChecked("id=checkBox");//Determines if checkbox or radio element is checked.
Parameters:
Name Type Description
locator (String|WebElement) Element locator.
Returns:
Boolean - true if element is checked. false otherwise.

isClickable(locator)→ {Boolean}

Determines if an element is clickable.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.isClickable("id=Element");//Determines if element is clickable.
Parameters:
Name Type Description
locator (String|WebElement) Element locator.
Returns:
Boolean - true if element is clickable. false otherwise.

isExist(locator, wait)→ {Boolean}

Wait for an element to become available.

The element is not necessary needs to be visible.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.isExist("id=Element");//Determines if element exists.
Parameters:
Name Type Description
locator String Element locator.
wait Number= optionalTime in milliseconds to wait for the element. Default is 60 seconds.
Returns:
Boolean - true if the element exists. false otherwise.

isSelected(locator)→ {Boolean}

Determines if an element is selected.


Usage example

mob.init(caps);
var a = mob.isSelected("id=Selection");
if (a) {
  ...
} else {
  ...
}
Parameters:
Name Type Description
locator (String|WebElement) Element locator.
Returns:
Boolean - true if element is selected. false otherwise.

isVisible(locator, timeout)→ {Boolean}

Checks if element is present and visible. Returns false if element was not found or wasn't visible within the specified timeout.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.isVisible("id=Selection");//Determines if element is visible.
Parameters:
Name Type Description
locator (String|WebElement) An element locator.
timeout Number= optionalTimeout in milliseconds to wait for element to appear. Default is 60 seconds.
Returns:
Boolean - True if element was found and it was visible. False otherwise.

isWebViewContext()→ {Boolean}

Checks if the current context is of WebView type.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.isWebViewContext();//Checks if the current context is of WebView type.
Returns:
Boolean - true if the context name is WEBVIEW or CHROMIUM.

open(url)

Opens an URL.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.open('www.yourwebsite.com');//Opens an URL.
Parameters:
Name Type Description
url String The URL to open.

pause(ms)

Pauses test execution for given amount of milliseconds.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.pause(5000);//Waits amount of miliseconds till performs the next command.
Parameters:
Name Type Description
ms Number milliseconds to pause the execution.

scrollIntoElement(scrollElmLocator, findElmLocator, xoffset, yoffset, retries)

Scrolls the view element until a specified target element inside the view is found.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.scrollIntoElement('id=bottomPanel','id=Button',0,-30,50);//Scrolls the view element until a specified target element inside the view is found.
Parameters:
Name Type Description
scrollElmLocator String View element to scroll.
findElmLocator String Target element to find in the view.
xoffset Number= optionalIndicates the size in pixels of the horizontal scroll step (positive - scroll right, negative - scroll left). Default is 0.
yoffset Number= optionalIndicates the size in pixels of the vertical scroll step (positive - scroll up, negative - scroll down). Default is -30.
retries Number= optionalIndicates the number of scroll retries before giving up if element not found. Default is 50.

scrollIntoView(locator, alignToTop)

Scrolls the element into the visible area of the browser window.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.scrollIntoElement('id=bottomPanel',true);//Scrolls the element into the visible area of the browser window.
Parameters:
Name Type Description
locator String Element locator.
alignToTop Boolean= optionalIndicates whether to align the element to the top. Element is centered otherwise.

selectFrame(frameLocator)

Selects a frame or an iframe within the current window.

Available frame locators:

  • 'parent' - Select parent frame.
  • 'top' - Select top window.
  • NUMBER - Select frame by its 0-based index.
  • LOCATOR - Locator identifying the frame (relative to the top window). Multiple locators can be passed in order to switch between nested frames.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.selectFrame('id=iFrame');//Selects a frame or an iframe within the current window.
Parameters:
Name Type Description
frameLocator ...(String|Number) optionalA locator identifying the frame or iframe. Or a series of locators.

sendKeys(value)

Send a sequence of key strokes to the active window or element.

Refer to Key Codes for the list of supported raw keyboard key codes.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.sendKeys (‘\uE03B’);//Types keys by reference to a key code.
Parameters:
Name Type Description
value String Sequence of key strokes to send.

setAutoWait(enable)

Specifies whether commands should automatically wait till element appear before executing.

By default automatic waiting is enabled. This setting affects all commands which expect to perform some action on elements, except wait*, assert*, is* and other commands which receive optional timeout parameter.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.setAutoWait(true);//Specifies whether commands should automatically wait till element appear before executing.
Parameters:
Name Type Description
enable Boolean true to enable automatic waiting, false to disable.

setContext(context)

Sets a specific context (NATIVE_APP, WEBVIEW, etc.).


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.setContext(NATIVE_APP);//Sets a specific context (NATIVE_APP, WEBVIEW, etc.).
Parameters:
Name Type Description
context String The context name.

setNativeContext()

Sets context to NATIVE_APP.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.setNativeContext();//Sets context to NATIVE_APP.

setTimeout(timeout)

Specifies the amount of time that Oxygen will wait for actions to complete.

This includes the open command, waitFor* commands, and all other commands which wait for elements to appear or become visible before operating on them.
If command wasn't able to complete within the specified period it will fail the test.
The default time-out is 60 seconds.


Usage example

mob.init();//Opens browser session.
mob.setTimeout(60000);//Sets the time out to amount of milliseconds .
Parameters:
Name Type Description
timeout Number A time-out in milliseconds.

setWebViewContext()

Sets context to the first available WEBVIEW or CHROMIUM (Crosswalk WebView) view.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.setWebViewContext();//Sets context to the first available WEBVIEW or CHROMIUM (Crosswalk WebView) view.

shake()

Perform shake action on the device

Supported on Android and iOS 9 or earlier versions.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.shake();//Perform shake action on the device.

smsClickLink(wait)

Clicks SMS message URL.

SMSPopup application must be installed and running on the device to use this command. https://github.com/oxygenhq/android-smspopup/releases


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.click("id=sendSmS");// Clicks an element.
mob.smsClickLink(60000);//Clicks SMS message URL.
Parameters:
Name Type Description
wait Number= optionalTime in milliseconds to wait for sms popup. Default is 60 seconds.

smsGetText(wait)→ {String}

Gets SMS text on Android phone.

SMSPopup application must be installed and running on the device to use this command. https://github.com/oxygenhq/android-smspopup/releases


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.click("id=sendSmS");// Clicks an element.
var a = mob.smsGetText(60000);//Gets SMS text on Android phone.
Parameters:
Name Type Description
wait Number= optionalTime in milliseconds to wait for sms popup. Default is 60 seconds.
Returns:
String - SMS text.

swipe(locator, xoffset, yoffset, speed)

Perform a swipe on the screen or an element.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.swipe("id=Element",-60,0,150);//Perform a swipe on the screen or an element.
Parameters:
Name Type Description
locator String= optionalLocator of the element to swipe on.
xoffset Number Horizontal offset.
yoffset Number Vertical offset. Negative value indicates swipe down and positive indicates swipe up direction.
speed Number= optionalThe speed of swiping in pixels per second. Default is 30.

takeScreenshot()→ {String}

Take a screenshot of the current page or screen and return it as base64 encoded string.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.takeScreenshot();//Take a screenshot of the current page or screen and return it as base64 encoded string.
Returns:
String - Screenshot image encoded as a base64 string.

tap(x, y)

Perform tap at the specified coordinate.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.tap(60,300);//Perform tap at the specified coordinate.
Parameters:
Name Type Description
x Number x offset.
y Number y offset.

type(locator, value)

Send a sequence of key strokes to an element (clears value before).

Refer to Key Codes for the list of supported raw keyboard key codes.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.type('id=TextArea', 'hello world\uE007');
Parameters:
Name Type Description
locator (String|WebElement) An element locator.
value String The value to type.

unlockPattern(locator, cols, rows, pattern)

Unlocks a pattern lock


1 2 3
4 5 6
7 8 9
a b c
Parameters:
Name Type Description
locator String Element locator for the pattern lock.
cols Number Number of columns in the pattern.
rows Number Number of rows in the pattern.
pattern String Pattern sequence. Pins are hexadecimal and case sensitive. See example.

verifyText(locator, pattern, message)

Verifies element's inner text.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.verifyText('id=header', 'hello world','The element does not match the text');//Verifies element's inner text.
Parameters:
Name Type Description
locator (String|WebElement) Element locator.
pattern String Assertion text or pattern.
message String= optionalMessage to generate in case of verification failure.

verifyTitle(pattern, message)

Verifies the page title.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.verifyTitle('Website Title','The Title does not match the expected text');//Verifies the page title.
Parameters:
Name Type Description
pattern String Assertion text or pattern.
message String= optionalMessage to generate in case of verification failure.

verifyValue(locator, pattern, message)

Verifies element's value.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.verifyValue('id=Element','2','The value does not match the expected pattern');//Verifies element's value.
Parameters:
Name Type Description
locator (String|WebElement) Element locator.
pattern String Assertion text or pattern.
message String= optionalMessage to generate in case of verification failure.

waitForExist(locator, wait)

Wait for an element for the provided amount of milliseconds to exist in DOM.

The element is not necessary needs to be visible.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.waitForExist('id=Element');//Wait for an element for the provided amount of milliseconds to exist in DOM.
Parameters:
Name Type Description
locator (String|WebElement) Element locator.
wait Number= optionalTime in milliseconds to wait for the element. Default is 60 seconds.

waitForVisible(locator, wait)

Wait for an element for the provided amount of milliseconds to be visible.


Usage example

mob.init(caps);//Starts a mobile session and opens app from desired capabilities
mob.waitForVisible('id=Element');//Wait for an element for the provided amount of milliseconds to be visible.
Parameters:
Name Type Description
locator (String|WebElement) Element locator.
wait Number= optionalTime in milliseconds to wait for the element. Default is 60 seconds.