Since: API Level v2
public final class

MobilePlugin

com.webmbt.plugin.MobilePlugin

Class Overview

Mobile plugin (in beta) provides a set of MScript methods to test web and native mobile applications in real physical device and in simulated device through Appium. Appium server must be installed separately (Install Appium) or selenium web service like saucelabs and others that support appium service, as well as the mobile device sdk: Android Studio (SDK) for Android devices or X Code Development for IOS devices.

You must set the Mobile.platformName and Mobile.deviceName with $Mobile.setCapabilityString('mobileTYpe','type code') to instruct Mobile plugin if you wish to test with Android or IOS and which IOS device: IPhone or IPad.

To test using cloud based commercial services e.g. SauceLabs.com and TestingBot.com, you will need to set up an account and set up "AppiumURL" to point to your remote selenium server/appium server in webdriver_Mobile.properties. Please consult their company website for more information.

There are many ways to locate an element in the document as supported by WebDriver/appium for web element and native ui element:

  • by id: find element with matching id, e.g.id=abc or just abc
  • by name: find element by matching name attribute, e.g. name=abc
  • by css: find element by css, e.g. css=div span .firstName
  • by link: find element by anchor text, e.g. link=click me
  • by partial link text: find element by matching partial of anchor text, e.g. link*=order
  • by xpath: find element by xpath, e.g. xpath=/html/body/div[2]

Keep in mind some of the locator styles may only be used for web app and not for native device app. Check out Michael Sorens' post on Selenium locators.

For web element this plugin will search for the element in all frames/iframes IF the element is not found in the current context. Be aware that this may result in multiple elements found if multiple elements are found with the same locator in different frames/iframes. You may use the following "frame=" to indicate which frame/iframe to search for the element in a specific frame/iframe.

Additionally you can qualify the element locator with any or all of the following separated with a semi-colon ";" and no white spaces allowed around the semi-colon.

  • window=mywindow
  • frame=myframe

For example: frame=iframe1;id=xyz to find the element with id of xyz on frame named iframe1.

You may use frame name "current" to instruct system to only search the element for the locator in the context of current frame. This is useful when there are multiple instances of the elements with the same locator exist in multiple frames.

Use one of the setCapability methods to set/change WebDriver's browser capabilities as supported by WebDriver.

Example:

$setCapabilityString('chrome.switches', 'load-extension=/path/to/unpacked_extension', ' ')

All of the above requires that you set WebDriver Capabilities by either setting them in webdriver_Mobile.properties file or calling $setCapabilityString(). You may find more information about the WebDriver Capabilities settings on the internet, e.g. tutorial on Appium.

Typically you will include following capability settings in MBT_start trigger in each model or in webdriver_Mobile.properties file for all models:

  1. mobile.platformName: "Android", "IOS"
  2. mobile.platformVersion: "4.1"
  3. mobile.deviceName: "Android Emulator"
  4. mobile.fullReset: true/false - boolean
  5. mobile.noReset: true/false - boolean
  6. mobile.newCommandTimeout: integer milliseconds, e.g. 60
  7. mobile.app: AUT app absolute path
  8. mobile.appPackage: package name
  9. mobile.avd: android virtual device (emulator) name, like Nexus7. Make sure the avd has been defined/created in the android sdk/studio.
  10. mobile.CHROMEDRIVER_EXECUTABLE: file path to chromedriver
  11. mobile.browserName: browser name
  12. mobile.language: language code
  13. mobile.locale: locale string
  14. mobile.orientation: orientation code
  15. mobile.autoWebview: true/false

Copyright © 2009 - 2017 TestOptimal LLC. All Rights Reserved.

Summary

Public Constructors
MobilePlugin()
Public Methods
String WebDriver(String... params_p)
calls a method in org.openqa.selenium.WebDriver class that accepts String parameter(s) or no parameters.
String[] WebDriverElement(String... params_p)
calls a method in org.openqa.selenium.WebElement class that accepts String parameter(s) or no parameters.
String WebDriverManage(String... params_p)
calls a method in org.openqa.selenium.WebDriver.Options class that accepts String parameter(s) or no parameters.
String WebDriverNavigate(String... params_p)
calls a method in org.openqa.selenium.WebDriver.Navigation class that accepts String parameter(s) or no parameters.
String WebDriverSwitchTo(String... params_p)
calls a method in org.openqa.selenium.WebDriver.TargetLocator class that accepts String parameter(s) or no parameters.
void acceptAlert()
accept the alert dialog window by clicking on "OK" button.
void androidLock()
sends lock action to the android device
void androidLongPressKeyCode(String key)
performs a long key press on android device
void androidLongPressKeyCode(String key, String metaState)
performs a long meta key press on android device
void androidPressKeyCode(String key)
presses a key on android device
void androidPressKeyCode(String key, String metaState)
performs meta key press on android device
void androidToggleLocation()
sends toggle action on location service to the android device
void androidUnlock()
perform unlock action on Android device
void cancel()
Cancel this action, if it was partially completed by the performsTouchActions.
void clear(String locator_p)
clears the input field.
void click(String locator_p)
click on the first element found.
void closeWindow(String windowName_p)
closes a window
boolean containsText(String text_p)
returns true if current page contains the text passed in.
boolean containsText(String loc_p, String text_p)
returns true if the element of the locator passed in contains the text specified.
int count(String locator_p)
returns count of number of objects for the element locator passed in.
void dismissAlert()
dismiss the alert/confirm dialog by clicking on close or "cancel" button.
void doubleClick(String locator_p)
double click on the first element found.
void dragAndDrop(String fromLocator_p, String toLocator_p)
drag an element and drop it onto another element.
String execute(String cmd_p, String... params)
executes a command on mobile device
String getAlertText()
String getAllWindows()
return the information of all windows currently open.
String[] getAllWindowsID()
returns a list of window handles.@return
String[] getAttr(String locator_p, String attrName_p)
Returns the value of HTML attribute value defined in the element.
String getBrowserType()
returns the type of browser currently being launched.
String getConfirmText()
returns the message in the confirm popup dialog if present.
String getContext()
returns the context name
String getCookie(String cookieName_p)
returns the value of the cookie.
String getDeviceTime()
retrieves current time from mobile device.
String getLocation()
retrieves device current location.
String getLocation(String part)
returns the device location component specified.
String getOrientation()
retrieves device's current orientation.
String getPageText()
returns the text representation of current webpage.
String[] getText(String locator_p)
Returns the text of the element.
String getTitle()
returns the title of the current window/page.
String[] getValue(String locator_p)
Returns the value of the first element found with the locator_p.
void iosFindElementByUIAutomation(String loc)
finds element by UI Automation id on IOS device
void iosHideKeyboard(String keyName, String strategy)
Hides the keyboard if it is showing on IOS device.
void iosHideKeyboard()
hides keyboard if it is showing on IOS device
void iosHideKeyboard(String keyName)
hides the keyboard by pressing the button specified by keyName if it is showing on IOS device
void iosShake()
sends shake action on IOS device
boolean isAlertPresent()
retusn true if the alert dialog has been displayed(triggered).
boolean isChecked(String locator_p)
returns true if the first element found with locator_p is checked: radio button or checkbox only.
boolean isConfirmPresent()
retusn true if the confirm dialog has been displayed(triggered).
boolean isDisabled(String locator_p)
returns true if any of the elements found is disabled.
boolean isPresent(String locator_p)
returns true if the element exists in the current page/frame/window.
boolean isVisible(String locator_p)
returns true if any of the elements is visible.
String js(String javascript_p)
executes javascript on current window/frame.
String locate(String loc_p)
locates the element and pass back the local locator that can be used by selenium native method.
void longPressCoord(String x, String y, String duration)
perform long press action on x, y coordinate for the specified duration
void longPressCoord(String x, String y)
perform long press action on x, y coordinate
void longPressElem(String loc, String duration)
Press and hold the at an elements upper-left corner, offset by the given amount, until the contextmenu event has fired.
void longPressElem(String loc)
performs long press action on an element
void mouseDown(String locator_p)
trigger mouse down event on the first element found with locator_p.
void mouseOver(String locator_p)
trigger mouse over event on the first element found with locator_p.
void mouseUp(String locator_p)
trigger mouse up event on the first element found locator_p.
void moveToCoord(String x, String y)
Move current touch to a new position relative to the current position on the screen.
void moveToElem(String loc)
Move current touch to center of an element.
void openURL(String url_p)
navigate to url specified.
void pressCoord(String x, String y)
perform press action on x, y coordinate
void pressElem(String loc, String x, String y)
Press and hold the at an elements upper-left corner, offset by the given amount, until the contextmenu event has fired.
void pressElem(String loc)
performs long press action on an element
void refresh()
click on the browser refresh button.
void release()
Remove the current touching implement from the screen (withdraw your touch).
void restartAUT(String url_p)
closes all browser windows if any and opens a new browser window at the url passed in.
void rightClick(String locator_p)
rightClick on the first element found with locator_p.
boolean rotate(String orient)
change device orientation
void selectOption(String locator_p, String optionLocator_p)
selects an option for the Select element.
void selectWindow(String windowName_p)
selects a specified window as the current target window which all future commands to be directed to.
void sendKey(String locator_p, String keyString_p)
type the string to the first element found with locator_p.
void setBrowserCmd(String browserCmd_p)
changes the browser to be used for executing mbt.
void setCapabilityBoolean(String capKey_p, String capVal_p)
void setCapabilityInteger(String capKey_p, String capVal_p)
void setCapabilityList(String capKey_p, String capVal_p, String delChar_p)
void setCapabilityLong(String capKey_p, String capVal_p)
void setCapabilityString(String capKey_p, String capVal_p)
sets a capability setting for the selected browser.
void setCheckBox(String locator_p, String checked_p)
sets the checkbox.
void setImplicitWait(String millis_p)
sets the implicitWait parameter for WebDriver.
void setProxy(String proxyURL_p)
sets the proxy server url for webdriver
void setRadioButton(String locator_p, String checked_p)
sets the first radio button found with locator_p.
int sizeOf(String locator_p)
returns the number options in the first select element found
String snapScreen(String fn_p)
Take a snapshot of current AUT window.
void swipeHorizontal(String startFract, String anchorFract, String endFract, String dur)
sends horizontal swipe action to the device
void swipeVertical(String startFract, String anchorFract, String endFract, String dur)
sends vertical swipe action to the device
void tapCoord(String x, String y)
Tap an absolute position on the screen.
void tapElem(String loc, String x, String y)
Tap an element, offset from upper left corner.
void tapElem(String loc)
Tap the center of an element.
void type(String locator_p, String keyString_p)
type the string to the first element found with locator_p.
void typeKeys(String locator_p, String keyString_p)
type the string to the first element found with locator_p.
boolean waitForCondition(String locator_p, String condType_p, String condResult_p, String timeoutMillis_p)
waits for a condition specified on the element up to the specified timeout in milliseconds.
boolean waitForElement(String locator_p, String timeoutMillis_p)
waits for an element to be visible up to the specified timeout in milliseconds.
boolean waitForWindow(String winName_p, String timeoutMillis_p)
waits for a window to open/appear up to the specified timeout in milliseconds.
boolean windowExists(String winNameTitle_p)
returns true if the window with specified name/title is found.

Public Constructors

public MobilePlugin ()

Since: API Level v2

Public Methods

public String WebDriver (String... params_p)

Since: API Level v2

calls a method in org.openqa.selenium.WebDriver class that accepts String parameter(s) or no parameters.

Example:

$WebDriver('getPageSource')
The above expression calls org.openqa.selenium.WebDriver.getPageSource().

Parameters
params_p 0, 1 or many parameters
Throws
MBTException

public String[] WebDriverElement (String... params_p)

Since: API Level v2

calls a method in org.openqa.selenium.WebElement class that accepts String parameter(s) or no parameters.

Example:

$WebDriverElement('id=f1','click')
The above expression calls org.openqa.selenium.WebElement.click()@return

Parameters
params_p String parameters
Throws
MBTException

public String WebDriverManage (String... params_p)

Since: API Level v2

calls a method in org.openqa.selenium.WebDriver.Options class that accepts String parameter(s) or no parameters.

Example:

$WebDriverManage('getCookieNamed','xyz')
The above expression calls org.openqa.selenium.WebDriver.Options.getCookieNamed("xyz") returns the cookie value.@return

Throws
MBTException

public String WebDriverNavigate (String... params_p)

Since: API Level v2

calls a method in org.openqa.selenium.WebDriver.Navigation class that accepts String parameter(s) or no parameters.

Example:

$WebDriverNavigate('back')
The above expression calls org.openqa.selenium.WebDriver.Navigation.back()@return

Throws
MBTException

public String WebDriverSwitchTo (String... params_p)

Since: API Level v2

calls a method in org.openqa.selenium.WebDriver.TargetLocator class that accepts String parameter(s) or no parameters.

Example:

$WebDriverSwitchTo('frame','ABC')
The above expression calls org.openqa.selenium.WebDriver.TargetLocator.frame("ABC")@return

Throws
MBTException

public void acceptAlert ()

Since: API Level v2

accept the alert dialog window by clicking on "OK" button.

Throws
MBTException

public void androidLock ()

Since: API Level v2

sends lock action to the android device

public void androidLongPressKeyCode (String key)

Since: API Level v2

performs a long key press on android device

Parameters
key - key code integer

public void androidLongPressKeyCode (String key, String metaState)

Since: API Level v2

performs a long meta key press on android device

Parameters
key - key code integer
metaState - meta state
Throws
MBTException

public void androidPressKeyCode (String key)

Since: API Level v2

presses a key on android device

Parameters
key - key code integer

public void androidPressKeyCode (String key, String metaState)

Since: API Level v2

performs meta key press on android device

Parameters
key - key code integer
metaState - meta state
Throws
MBTException

public void androidToggleLocation ()

Since: API Level v2

sends toggle action on location service to the android device

public void androidUnlock ()

Since: API Level v2

perform unlock action on Android device

public void cancel ()

Since: API Level v2

Cancel this action, if it was partially completed by the performsTouchActions.

Throws
MBTException

public void clear (String locator_p)

Since: API Level v2

clears the input field.

Example:

<action code="$clear('id=F1')"/> 

Throws
MBTException

public void click (String locator_p)

Since: API Level v2

click on the first element found.

Example:

<action code="$click('id=F1')"/> 

Throws
MBTException

public void closeWindow (String windowName_p)

Since: API Level v2

closes a window

Throws
MBTException

public boolean containsText (String text_p)

Since: API Level v2

returns true if current page contains the text passed in. The text must be static text string only.

Example:

<log msg="Page contains text XXXX? $containsText('XXXX')"/> 

Throws
MBTException

public boolean containsText (String loc_p, String text_p)

Since: API Level v2

returns true if the element of the locator passed in contains the text specified. The text must be static text string only.

Example:

<log msg="Page contains text XXXX? $containsText('id=xyz', 'XXXX')"/>

Throws
MBTException

public int count (String locator_p)

Since: API Level v2

returns count of number of objects for the element locator passed in.

Example:

<log msg="$found $count('name=paymentType') payment types on the screen"/>

Throws
MBTException

public void dismissAlert ()

Since: API Level v2

dismiss the alert/confirm dialog by clicking on close or "cancel" button.

Throws
MBTException

public void doubleClick (String locator_p)

Since: API Level v2

double click on the first element found.

Example:

<action code="$doubleClick('id=F1')"/>

Throws
MBTException

public void dragAndDrop (String fromLocator_p, String toLocator_p)

Since: API Level v2

drag an element and drop it onto another element. Only the first element found for both drag source and drop source locators are acted on.

Example:

<action code="$dragAndDrop('id=F1','id=f2')"/> 
The above MScript drags element F1 and drops it on the element f2.

Parameters
fromLocator_p element locator
toLocator_p element locator
Throws
MBTException

public String execute (String cmd_p, String... params)

Since: API Level v2

executes a command on mobile device

Parameters
cmd_p command string
params optional parameters formatted 'key=value'. You may supply multiple parameters: 'key1=value1', 'key2=value2', ...

public String getAlertText ()

Since: API Level v2

Throws
MBTException

public String getAllWindows ()

Since: API Level v2

return the information of all windows currently open.

Each window is described in the following format, multiple windows are separated with a semi-colon ";". :
name:title[idx]

public String[] getAllWindowsID ()

Since: API Level v2

returns a list of window handles.@return

Throws
MBTException
MBTException
See Also

public String[] getAttr (String locator_p, String attrName_p)

Since: API Level v2

Returns the value of HTML attribute value defined in the element.

Example:

<log msg="Field attribute: $getAttr('id=F1','class')."/>

Each type of HTML element has a set of attributes but it also allows user defined attributes. For example "table" element has these attributes "id", "name", "width", "height", "class", etc. These are standard attributes to define a table in HTML. You may add any user attributes like "customerNumber", "orderNumber", "firstName", etc. These user defined attributes are also accessible by getAttr().

Throws
MBTException
See Also
  • http://www.w3schools.com/tags/default.asp

public String getBrowserType ()

Since: API Level v2

returns the type of browser currently being launched. This is thread specific. That is, a model running multiple threads each thread can launch different browser.@return

Throws
MBTException

public String getConfirmText ()

Since: API Level v2

returns the message in the confirm popup dialog if present. blank if not.@return

Throws
MBTException

public String getContext ()

Since: API Level v2

returns the context name

public String getCookie (String cookieName_p)

Since: API Level v2

returns the value of the cookie.

Throws
MBTException

public String getDeviceTime ()

Since: API Level v2

retrieves current time from mobile device.

Returns
  • formatted time string

public String getLocation ()

Since: API Level v2

retrieves device current location.

public String getLocation (String part)

Since: API Level v2

returns the device location component specified.

Parameters
part Longitude, Latitude, Altitude

public String getOrientation ()

Since: API Level v2

retrieves device's current orientation.

public String getPageText ()

Since: API Level v2

returns the text representation of current webpage.

Returns
  • text string that represents the current page.
Throws
MBTException
MBTException

public String[] getText (String locator_p)

Since: API Level v2

Returns the text of the element. If multiple elements found, return a String with all text strung together separated by semicolon.

Example:

<log msg="$getText('id=rowTitle')"/> 

Throws
MBTException

public String getTitle ()

Since: API Level v2

returns the title of the current window/page.

Example:

<log msg="Page title is: $getTitle()"/>

Throws
MBTException

public String[] getValue (String locator_p)

Since: API Level v2

Returns the value of the first element found with the locator_p. If element does not have value attribute, it returns the text. If element still does not have text attribute, it returns blank.

Example:

<log msg="userid is: $getValue('userid')"/>

Throws
MBTException

public void iosFindElementByUIAutomation (String loc)

Since: API Level v2

finds element by UI Automation id on IOS device

public void iosHideKeyboard (String keyName, String strategy)

Since: API Level v2

Hides the keyboard if it is showing on IOS device. Hiding the keyboard often depends on the way an app is implemented, no single strategy always works.

Parameters
keyName - a String, representing the text displayed on the button of the keyboard you want to press. For example: "Done".
strategy - HideKeyboardStrategy

public void iosHideKeyboard ()

Since: API Level v2

hides keyboard if it is showing on IOS device

public void iosHideKeyboard (String keyName)

Since: API Level v2

hides the keyboard by pressing the button specified by keyName if it is showing on IOS device

Parameters
keyName - a String, representing the text displayed on the button of the keyboard you want to press. For example: "Done".

public void iosShake ()

Since: API Level v2

sends shake action on IOS device

public boolean isAlertPresent ()

Since: API Level v2

retusn true if the alert dialog has been displayed(triggered).

Throws
MBTException

public boolean isChecked (String locator_p)

Since: API Level v2

returns true if the first element found with locator_p is checked: radio button or checkbox only.

Example:

<log msg="The checkbox F1 checked? $isChecked('id=F1')"/>

Parameters
locator_p locator to the checkbox
Throws
MBTException

public boolean isConfirmPresent ()

Since: API Level v2

retusn true if the confirm dialog has been displayed(triggered). isConfirmPresent() must be called immediately after the action that trigger the confirm popup. optionally you can call getConfirmText().

Throws
MBTException

public boolean isDisabled (String locator_p)

Since: API Level v2

returns true if any of the elements found is disabled.

Example:

<log msg="Field F1 disabled?: $isDisabled('id=F1')."/>

Throws
MBTException

public boolean isPresent (String locator_p)

Since: API Level v2

returns true if the element exists in the current page/frame/window. Invisible elements are considered present.

Example:

<if val1="$isPresent('checkbox1')" op="eq" val2="true"/> 
    <log msg="checkbox1 is present on this page">
</if>

Throws
MBTException

public boolean isVisible (String locator_p)

Since: API Level v2

returns true if any of the elements is visible.

Example:

<log msg="Field F1 visible?: $isVisible('id=F1')."/> 

Throws
MBTException

public String js (String javascript_p)

Since: API Level v2

executes javascript on current window/frame. Be sure to use "return xyz" if you wish to receive the return from the call.

This method only valid for browser testing.@return

Throws
MBTException

public String locate (String loc_p)

Since: API Level v2

locates the element and pass back the local locator that can be used by selenium native method. This method should only be used inside the parameter of the native method call.

Example:

$_keyPress('$locate('frame=abc;xpath=id(\'id123\')', 'A') which set the focus
to the frame abc and passes xpath=id(\'id123\') to $_keyPress('xpath=id(\'id123\')', 'A')@return

Throws
MBTException

public void longPressCoord (String x, String y, String duration)

Since: API Level v2

perform long press action on x, y coordinate for the specified duration

Parameters
x - x coordinate
y - y coordinate
duration - duration in milliseconds
Throws
MBTException

public void longPressCoord (String x, String y)

Since: API Level v2

perform long press action on x, y coordinate

Parameters
x - x coordinate
y - y coordinate
Throws
MBTException

public void longPressElem (String loc, String duration)

Since: API Level v2

Press and hold the at an elements upper-left corner, offset by the given amount, until the contextmenu event has fired.

Parameters
loc - element locator
duration - duration in milliseconds
Throws
MBTException

public void longPressElem (String loc)

Since: API Level v2

performs long press action on an element

Parameters
loc - element locator
Throws
MBTException

public void mouseDown (String locator_p)

Since: API Level v2

trigger mouse down event on the first element found with locator_p.

Example:

<action code="$mouseDown('id=F1')"/> 

Throws
MBTException

public void mouseOver (String locator_p)

Since: API Level v2

trigger mouse over event on the first element found with locator_p.

Example:

<action code="$mouseOver('id=F1')"/> 

Throws
MBTException

public void mouseUp (String locator_p)

Since: API Level v2

trigger mouse up event on the first element found locator_p.

Example:

<action code="$mouseUp('id=F1')"/>

Throws
MBTException

public void moveToCoord (String x, String y)

Since: API Level v2

Move current touch to a new position relative to the current position on the screen.

Parameters
x - x coordinate
y - y coordinate
Throws
MBTException

public void moveToElem (String loc)

Since: API Level v2

Move current touch to center of an element.

Parameters
loc - element locator
Throws
MBTException

public void openURL (String url_p)

Since: API Level

navigate to url specified. Example:

$openURL('http://google.com/')

Throws
Exception

public void pressCoord (String x, String y)

Since: API Level v2

perform press action on x, y coordinate

Parameters
x - x coordinate
y - y coordinate
Throws
MBTException

public void pressElem (String loc, String x, String y)

Since: API Level v2

Press and hold the at an elements upper-left corner, offset by the given amount, until the contextmenu event has fired.

Parameters
loc - element locator
x - x coordinate
y - y coordinate
Throws
MBTException

public void pressElem (String loc)

Since: API Level v2

performs long press action on an element

Throws
MBTException

public void refresh ()

Since: API Level v2

click on the browser refresh button.

Example:

<action code="$refresh()"/> 

Throws
MBTException

public void release ()

Since: API Level v2

Remove the current touching implement from the screen (withdraw your touch).

Throws
MBTException

public void restartAUT (String url_p)

Since: API Level v2

closes all browser windows if any and opens a new browser window at the url passed in.

Parameters
url_p url or blank to open the browser at the model's appURL
Throws
Exception

public void rightClick (String locator_p)

Since: API Level v2

rightClick on the first element found with locator_p.

Example:

<action code="$rightClick('id=F1')"/> 

Throws
MBTException

public boolean rotate (String orient)

Since: API Level v2

change device orientation

Parameters
orient Landscape or Portrait
Returns
  • true if valid orientation was specified.

public void selectOption (String locator_p, String optionLocator_p)

Since: API Level v2

selects an option for the Select element.

Example:

<action code="$selectOption('id=selectF1','value=2')"/> 

Parameters
locator_p locator for the element
optionLocator_p locator for the option to be selected.
  • label=labelPattern: matches options based on their labels, i.e. the visible text. (This is the default.)

    For example, label=regexp:^[Oo]ther

  • value=valuePattern: matches options based on their values.

    For example, value=other

  • id=id: matches options based on their ids.

    id=option1

  • index=index: matches an option based on its index (offset from zero).

    index=2

Throws
MBTException

public void selectWindow (String windowName_p)

Since: API Level v2

selects a specified window as the current target window which all future commands to be directed to. Pass empty string for the window name to reset current target window to the main window.

You may also select window by window title (rel 4.0.8).

Example:

<action code="$selectWindow('mainWin')"/> 

Parameters
windowName_p name of the window, pass empty string for main window. You may pass in an integer (1-based) to select window by its index or regular expression with syntax /regExpr/ or use suffix/prefix "*" for startsWith and endsWith.
Throws
MBTException

public void sendKey (String locator_p, String keyString_p)

Since: API Level v2

type the string to the first element found with locator_p. The element must be an input field. It does not clear the content/value of the element if it's not empty.

Example:

<action code="$sendKey('id=F1','abc')"/>

Use the following tokens to simulate special keyboard key:

  • [KEYS.BACK_SPACE]
  • [KEYS.TAB]
  • [KEYS.CLEAR]
  • [KEYS.RETURN]
  • [KEYS.ENTER]
  • [KEYS.SHIFT]
  • [KEYS.LEFT_SHIFT]
  • [KEYS.CONTROL]
  • [KEYS.LEFT_CONTROL]
  • [KEYS.ALT]
  • [KEYS.LEFT_ALT]
  • [KEYS.PAUSE]
  • [KEYS.ESCAPE]
  • [KEYS.SPACE]
  • [KEYS.PAGE_UP]
  • [KEYS.PAGE_DOWN]
  • [KEYS.END]
  • [KEYS.HOME]
  • [KEYS.LEFT]
  • [KEYS.ARROW_LEFT]
  • [KEYS.UP]
  • [KEYS.ARROW_UP]
  • [KEYS.RIGHT]
  • [KEYS.ARROW_RIGHT]
  • [KEYS.NULL]
  • [KEYS.CANCEL]
  • [KEYS.HELP]
  • [KEYS.BACK_SPACE]
  • [KEYS.DOWN]
  • [KEYS.ARROW_DOWN]
  • [KEYS.INSERT]
  • [KEYS.DELETE]
  • [KEYS.SEMICOLON]
  • [KEYS.EQUALS]
  • [KEYS.NUMPAD0]
  • [KEYS.NUMPAD1]
  • [KEYS.NUMPAD2]
  • [KEYS.NUMPAD3]
  • [KEYS.NUMPAD4]
  • [KEYS.NUMPAD5]
  • [KEYS.NUMPAD6]
  • [KEYS.NUMPAD7]
  • [KEYS.NUMPAD8]
  • [KEYS.NUMPAD9]
  • [KEYS.MULTIPLY]
  • [KEYS.ADD]
  • [KEYS.SEPARATOR]
  • [KEYS.SUBTRACT]
  • [KEYS.DECIMAL]
  • [KEYS.DIVIDE]
  • [KEYS.F1]
  • [KEYS.F2]
  • [KEYS.F3]
  • [KEYS.F4]
  • [KEYS.F5]
  • [KEYS.F6]
  • [KEYS.F7]
  • [KEYS.F8]
  • [KEYS.F9]
  • [KEYS.F10]
  • [KEYS.F11]
  • [KEYS.F12]
  • [KEYS.META]
  • [KEYS.COMMAND]
  • [KEYS.ZENKAKU_HANKAKU]
Key token must be used alone or attached to the end of the string. For example, $sendKey('id=field1','[KEYS.ENTER]') or $sendKey('id=field1','abc[KEYS.TAB]')

Throws
MBTException
See Also
  • type(loc, keyString)

public void setBrowserCmd (String browserCmd_p)

Since: API Level v2

changes the browser to be used for executing mbt. Should only be called in MBT_start trigger in order for this change to take effective.

You may use a dataset to store a list of browser start cmds and randomly retrieve one to set for each virtual users to simulate multiple users using different browsers.

For example, you can use $nextDataSetRow(java.lang.String dataSetID_p, java.lang.String floatIdx_p), $rand(), and $getData('ds','field') to retrieve different browser "cmd" from a file/spreadsheet to achieve testing with virtual users with each running different browser, like
<action code="$nextDataSetRow('myDS', '$rand()')"/>
<action code="$setBrowserCmd('$getData('myDS', 'myField')')"/>

The alternative is to use DataGen plugin to randomly choose a browser from the list of browsers specified.

Example:

$setBrwoserCmd('$randFromList('internetExplorer|firefox|Chrome')')

Parameters
browserCmd_p legal Selenium browser start cmd including custom browser start cmd. If blank is passed in, it will not change the browser.

For example iexplore for IE, firefox for Firefox, custom c:/xxxx/yy.exe for custom browser to run a specific exe.

s

public void setCapabilityBoolean (String capKey_p, String capVal_p)

Since: API Level v2

public void setCapabilityInteger (String capKey_p, String capVal_p)

Since: API Level v2

public void setCapabilityList (String capKey_p, String capVal_p, String delChar_p)

Since: API Level v2

public void setCapabilityLong (String capKey_p, String capVal_p)

Since: API Level v2

public void setCapabilityString (String capKey_p, String capVal_p)

Since: API Level v2

sets a capability setting for the selected browser. Must supply the exact key and value in an appropriate format. This method is only valid in MBT_start trigger. Calling this method outside MBT_start trigger has no effect.

This method has variations for different data type. Choose the correct variation that is appropriate for the capability setting according to the browser's specific requirement.

For more information about capability setting supported by the specific browser, please visit WebDriver support page at: http://code.google.com/p/selenium/wiki

Optionally you can set capabilities by editing webdriver_Mobile.properties in Config folder.

public void setCheckBox (String locator_p, String checked_p)

Since: API Level v2

sets the checkbox.

Example:

<action code="$setCheckBox('id=F1','true')"/> 

Parameters
locator_p locator to the checkbox element
checked_p true or false
Throws
MBTException

public void setImplicitWait (String millis_p)

Since: API Level v2

sets the implicitWait parameter for WebDriver. Implicit wait is the maximun amount of WebDriver will wait for the element to appear in the document. This setting applies to WebDriver directly and is used for all operations that require finding an element in the document.

You may need to use other wait method to supplement this global setting to meet specific needs in different part of the model.

Parameters
millis_p number of milliseconds

public void setProxy (String proxyURL_p)

Since: API Level v2

sets the proxy server url for webdriver

public void setRadioButton (String locator_p, String checked_p)

Since: API Level v2

sets the first radio button found with locator_p.

Example:

<action code="$setRadioButton('id=F1','true')"/> 

Parameters
locator_p locator to the radiobutton element
checked_p true or false
Throws
MBTException

public int sizeOf (String locator_p)

Since: API Level v2

returns the number options in the first select element found

Throws
MBTException

public String snapScreen (String fn_p)

Since: API Level v2

Take a snapshot of current AUT window.

Typical use of this method is to call it in or trigger to take a snapshot of the screen of the error.

The screen shot will be marked with the first exception (if multiple exceptions) triggered by current mScript and thus available from the exception popup.

Example:

<action code="$Selenium.snapScreen('myFileName')"/>

Returns
  • file path of the screen shot file
Throws
Exception

public void swipeHorizontal (String startFract, String anchorFract, String endFract, String dur)

Since: API Level v2

sends horizontal swipe action to the device

Parameters
startFract - horizontal (x) fraction (0.0 - 1.0)
anchorFract - y fraction
endFract - horizontal (x) fraction
dur - touch duration in milliseconds

public void swipeVertical (String startFract, String anchorFract, String endFract, String dur)

Since: API Level v2

sends vertical swipe action to the device

Parameters
startFract - horizontal (y) fraction (0.0 - 1.0)
anchorFract - x fraction
endFract - horizontal (y) fraction
dur - touch duration in milliseconds

public void tapCoord (String x, String y)

Since: API Level v2

Tap an absolute position on the screen.

Parameters
x - x coordinate
y - y coordinate
Throws
MBTException

public void tapElem (String loc, String x, String y)

Since: API Level v2

Tap an element, offset from upper left corner.

Parameters
loc - element locator
x - offset from upper-left corner of the element
y - offset from upper-top corner of the element
Throws
MBTException

public void tapElem (String loc)

Since: API Level v2

Tap the center of an element.

Parameters
loc - element locator
Throws
MBTException

public void type (String locator_p, String keyString_p)

Since: API Level v2

type the string to the first element found with locator_p. The element must be an input field. It clears the current value before issuing typing the string into the field.

Example:

<action code="$type('id=F1','abc')"/> 

Parameters
locator_p element locator
keyString_p string to be typed into the field. You may use key token as described in sendKey(loc, keyString) function to enter special keyboar key.
Throws
MBTException
See Also
  • sendKey(loc, keystring)

public void typeKeys (String locator_p, String keyString_p)

Since: API Level v2

type the string to the first element found with locator_p. The element must be an input field. It does not clear the content/value of the element if it's not empty. This is equivalent to sendKey().

Example:

<action code="$sendKey('id=F1','abc')"/> 

Throws
MBTException
See Also
  • sendKey(locator, keyString)
  • typeKey(locator, keyString)
  • type(locator, keyString)

public boolean waitForCondition (String locator_p, String condType_p, String condResult_p, String timeoutMillis_p)

Since: API Level v2

waits for a condition specified on the element up to the specified timeout in milliseconds. Returns true if the condition becomes true, false if it times out.

Parameters
condType_p text, visible, enabled or name of the attribute e.g. 'class', 'style', 'width', etc.
condResult_p expected state/value of the found element. e.g. for 'text' type, specify the expected string or regular expression, for 'visible' type, specify true or false, etc.
Returns
  • true if condition is found to be true within timeout duration, else return false.
Throws
MBTException

public boolean waitForElement (String locator_p, String timeoutMillis_p)

Since: API Level v2

waits for an element to be visible up to the specified timeout in milliseconds. Returns true if the element is found, false it times out.

Returns
  • true if element is found
Throws
MBTException

public boolean waitForWindow (String winName_p, String timeoutMillis_p)

Since: API Level v2

waits for a window to open/appear up to the specified timeout in milliseconds. Returns true if the window is found, false it times out waiting.

Parameters
winName_p name of the window or window handle (obtained with $getAllWindows()
Returns
  • true if element is found
Throws
MBTException

public boolean windowExists (String winNameTitle_p)

Since: API Level v2

returns true if the window with specified name/title is found. Else return false.

Parameters
winNameTitle_p name of the window, pass empty string for main window. You may pass in an integer (1-based) to select window by its index or regular expression with syntax /regExpr/ or use suffix/prefix "*" for startsWith and endsWith.