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.
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.

Initializes a new Appium session with provided desired capabilities and optional host name and port.
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.

alertDismiss()

Dismisses currently displayed alert.

assertText(locator, pattern, message)

Asserts element's inner text.
Parameters:
Name Type Description
locator String 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.
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.
Parameters:
Name Type Description
locator String 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.

clear(locator)

Clears element's value or content
Parameters:
Name Type Description
locator String Element locator.

click(locator)

Clicks on an element.
Parameters:
Name Type Description
locator String Element locator.

clickHidden(locator, clickParent)

Clicks hidden element.
Parameters:
Name Type Description
locator String Element locator.
clickParent Boolean optionalIf true, then parent of the element is clicked.

dragAndDrop(locator, xoffset, yoffset)

Tap on an element, drag by the specified offset, and release.
Parameters:
Name Type Description
locator String Element locator on which to perform the initial tap.
xoffset Integer Horizontal offset. Positive for right direction; Negative for left.
yoffset Integer Vertical offset. Positive for up direction; Negative for down.

execute(js, ...arg)

Executes JavaScript code inside HTML page.
Parameters:
Name Type Description
js String Script to execute.
...arg Object optionalOptional script arguments.

findElement(locator, parent)→ {WebElement}

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)→ {undefined}

Finds elements.
Parameters:
Name Type Description
locator String Element locator.
parent Object optionalOptional parent element for relative search.
Returns:
{0} - Collection of WebElement JSON objects.

alertText()→ {String}

Gets alert text.
Returns:
String - Alert's text.

getLocation(locator)

Get element's location.
Parameters:
Name Type Description
locator String Element locator.

getSource()→ {String}

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)

Gets element's text.
Parameters:
Name Type Description
locator String Element locator.

hideKeyboard(strategy)

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.
Parameters:
Name Type Description
locator String Element locator.
Returns:
Boolean - true if element is checkable. false otherwise.

isChecked(locator)→ {Boolean}

Determines if checkbox or radio element is checked.
Parameters:
Name Type Description
locator String Element locator.
Returns:
Boolean - true if element is checked. false otherwise.

isClickable(locator)→ {Boolean}

Determines if an element is clickable.
Parameters:
Name Type Description
locator String Element locator.
Returns:
Boolean - true if element is clickable. false otherwise.

isDisplayed(locator)→ {Boolean}

Checks if element is visible on the screen.
Parameters:
Name Type Description
locator String Element locator.
Returns:
Boolean - true if the element is visible.

isExist(locator, wait)→ {Boolean}

Wait for an element to become available.

The element is not necessary needs to be visible.
Parameters:
Name Type Description
locator String Element locator.
wait Integer 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.
Parameters:
Name Type Description
locator String Element locator.
Returns:
Boolean - true if element is selected. false otherwise.

isWebViewContext()→ {Boolean}

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.
Parameters:
Name Type Description
url String The URL to open.

pause(ms)

Pauses test execution for given amount of milliseconds.
Parameters:
Name Type Description
ms Integer 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.
Parameters:
Name Type Description
scrollElmLocator String View element to scroll.
findElmLocator String Target element to find in the view.
xoffset Integer optionalIndicates the size in pixels of the horizontal scroll step (positive - scroll right, negative - scroll left). Default is 0.
yoffset Integer optionalIndicates the size in pixels of the vertical scroll step (positive - scroll up, negative - scroll down). Default is -30.
retries Integer 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.
Parameters:
Name Type Description
locator String Element locator.
alignToTop Boolean optionalIndicates whether to align the element to the top. Element is centered otherwise.

sendKeys(value)

Send a sequence of key strokes to the active window or element.
Parameters:
Name Type Description
value String Sequence of key strokes to send.

setContext(context)

Sets a specific context (NATIVE_APP, WEBVIEW, etc.).
Parameters:
Name Type Description
context String The context name.

setNativeContext()

Sets context to NATIVE_APP.

setValue(locator, value)

Sets element's value.
Parameters:
Name Type Description
locator String Element locator.
value String Value to set.

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.

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
Parameters:
Name Type Description
wait Integer 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
Parameters:
Name Type Description
wait Integer 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.
Parameters:
Name Type Description
locator String optionalLocator of the
xoffset Number Horizontal offset.
yoffset Number Vertical offset. Nagative value indicates swipe down and positive indicates swipe up direction.
speed Number optionalTime in seconds to spend performing the swipe. Default is 1 second.

takeScreenshot()

Take a screenshot of the current page or screen.

tap(x, y)

Perform tap at the specified coordinate.
Parameters:
Name Type Description
x Integer x offset.
y Integer y offset.

verifyText(locator, pattern, message)

Verifies element's inner text.
Parameters:
Name Type Description
locator String 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.
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.
Parameters:
Name Type Description
locator String Element locator.
pattern String Assertion text or pattern.
message String optionalMessage to generate in case of verification failure.

waitForElement(locator, wait)

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

The element is not necessary needs to be visible.
Parameters:
Name Type Description
locator String Element locator.
wait Integer 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.
Parameters:
Name Type Description
locator String Element locator.
wait Integer optionalTime in milliseconds to wait for the element. Default is 60 seconds.