com.webmbt.plugin
Interface MScriptMethodIntf

All Known Implementing Classes:
HtmlUnitPlugin, SeleniumPlugin, WebPluginAncestor

public interface MScriptMethodIntf

Defines a set of common methods required by mScript.

Locator string: Locator is a string expression to identify elements on the webpage. The element can be identified using different identifier. The locator string must follow the appropriate formats.

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.

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

Author:
yxl01

Method Summary
 void click(java.lang.String locator_p)
          simulate click on the element.
 void click(java.lang.String locator_p, java.lang.String shiftCtrlAlt_p)
          simulate click on the element with option of holding down shift, ctrl or alt key.
 void click(java.lang.String locator_p, java.lang.String coordX_p, java.lang.String coordY_p)
          simulate click on the element that supports coordinates, for example an image.
 boolean containsText(java.lang.String text_p)
          returns true if current page contains the text passed in.
 int count(java.lang.String locator_p)
          returns count of number of objects for the element locator passed in.
 void doubleClick(java.lang.String locator_p)
          double click on the element.
 void dragAndDrop(java.lang.String fromLocator_p, java.lang.String movement_p)
          drag element, move it by the movement string and then release it (drag and drop).
 java.lang.String getAlertText()
          returns the message in the alert popup dialog if present.
 java.lang.String[] getAttr(java.lang.String locator_p, java.lang.String attrName_p)
          Returns the value of HTML attribute value defined in the element.
 java.lang.String getConfirmText()
          returns the message in the confirm popup dialog if present.
 java.lang.String getCookie(java.lang.String cookieName_p)
          returns the value of the cookie.
 java.lang.String[] getText(java.lang.String locator_p)
          Returns the text of the element.
 java.lang.String getTitle()
          returns the title of the current window/page.
 java.lang.String[] getValue(java.lang.String locator_p)
          Returns the value of the element found with the locator_p.
 boolean isAlertPresent()
          retusn true if the alert dialog has been displayed(triggered).
 boolean isChecked(java.lang.String locator_p)
          returns true if the locator_p is checked: radio button or checkbox only.
 boolean isConfirmPresent()
          retusn true if the confirm dialog has been displayed(triggered).
 boolean isDisabled(java.lang.String locator_p)
          returns true if any of the elements found is disabled.
 boolean isPresent(java.lang.String locator_p)
          returns true if the element exists in the current page/frame/window.
 boolean isVisible(java.lang.String locator_p)
          returns true if any of the elements is visible.
 java.lang.String js(java.lang.String winLocator_p, java.lang.String javascript_p)
          executes javascript passed in on the window identified in winLocator_p.
 void mouseDown(java.lang.String locator_p)
          trigger mouse down event on element locator_p
 void mouseOver(java.lang.String locator_p)
          trigger mouse over event on the element locator_p
 void mouseUp(java.lang.String locator_p)
          trigger mouse up event on the element locator_p
 void refresh()
          click on the browser refresh button
 void rightClick(java.lang.String locator_p)
          rightClick on the element
 void selectFrame(java.lang.String frameName_p)
          select the named frame as the current default frame.
 void selectOption(java.lang.String locator_p, java.lang.String optionLocator_p)
          selects the option
 void selectWindow(java.lang.String windowName_p)
          select the named window as the current default window.
 void setCheckBox(java.lang.String locator_p, java.lang.String checked_p)
          sets the checkbox
 void setRadioButton(java.lang.String locator_p, java.lang.String checked_p)
          sets the radio button
 void setupAlert()
          prepare system to handle alert popup.
 void setupConfirmResponse(java.lang.String bool_p)
          prepare system to handle the confirmation dialog with OK/Yes or Cancel/No.
 int sizeOf(java.lang.String locator_p)
          returns the number options in the select
 java.lang.String snapScreen(java.lang.String fileName_p)
          INTERNAL USE ONLY takes a snap shot of current browser screen and saves the result in the file name passed in.
 void type(java.lang.String locator_p, java.lang.String keyString_p)
          type the string to the element if the element is an input field.
 void type(java.lang.String locator_p, java.lang.String shiftCtrlAlt_p, java.lang.String keyString_p)
          type the string to the element with the option to have shift/control/alt key pressed.
 void typeKey(java.lang.String locator_p, java.lang.String keyString_p)
          Enters a string by pressing keys which triggers key pressed event as if user is entering the string one char at a time.
 void waitForCondition(java.lang.String script_p, java.lang.String timeout_p)
          Runs the specified JavaScript snippet repeatedly until it evaluates to "true".
 java.lang.String waitForPageToLoad(java.lang.String timeoutMillis_p)
          waits for the page to complete the load (just html dom).
 void webAuth(java.lang.String authType_p, java.lang.String userID_p, java.lang.String password_p, java.lang.String waitMillis_p, java.lang.String gotoURL_p)
          performs HTTP basic authentication.
 

Method Detail

getValue

java.lang.String[] getValue(java.lang.String locator_p)
                            throws com.webmbt.MBTException
Returns the value of the element found with the locator_p. If multiple elements found, return a String with all values strung together separated by semicolon. 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')"/>

Parameters:
locator_p -
Returns:
Throws:
com.webmbt.MBTException

getText

java.lang.String[] getText(java.lang.String locator_p)
                           throws com.webmbt.MBTException
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:
com.webmbt.MBTException

isPresent

boolean isPresent(java.lang.String locator_p)
                  throws com.webmbt.MBTException
returns true if the element exists in the current page/frame/window.

Example:

<if val1="$isPresent('checkbox1')" op="eq" val2="true"/>

  <log msg="checkbox1 is present on this page">

</if>

Throws:
com.webmbt.MBTException

count

int count(java.lang.String locator_p)
          throws com.webmbt.MBTException
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:
com.webmbt.MBTException

isDisabled

boolean isDisabled(java.lang.String locator_p)
                   throws com.webmbt.MBTException
returns true if any of the elements found is disabled.

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

Throws:
com.webmbt.MBTException

isVisible

boolean isVisible(java.lang.String locator_p)
                  throws com.webmbt.MBTException
returns true if any of the elements is visible.

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

Throws:
com.webmbt.MBTException

getAttr

java.lang.String[] getAttr(java.lang.String locator_p,
                           java.lang.String attrName_p)
                           throws com.webmbt.MBTException
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:
com.webmbt.MBTException
See Also:
http://www.w3schools.com/tags/default.asp

click

void click(java.lang.String locator_p)
           throws com.webmbt.MBTException
simulate click on the element.

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

Throws:
com.webmbt.MBTException

click

void click(java.lang.String locator_p,
           java.lang.String shiftCtrlAlt_p)
           throws com.webmbt.MBTException
simulate click on the element with option of holding down shift, ctrl or alt key.

Example: <action code="$click('id=F1','S')"/>

Parameters:
shiftCtrlAlt_p - S for shift, C for ctrl, A for alt, for example "SA" for holding down Shift and Alt key.
locator_p -
shiftCtrlAlt_p -
Throws:
com.webmbt.MBTException

click

void click(java.lang.String locator_p,
           java.lang.String coordX_p,
           java.lang.String coordY_p)
           throws com.webmbt.MBTException
simulate click on the element that supports coordinates, for example an image.

Example: <action code="$click('id=F1','100','200')"/>

Notice that even though coordX_p and coordY_p are integer parameters, they must be enclosed by a set of single quote.

Parameters:
locator_p -
coordX_p -
coordY_p -
Throws:
com.webmbt.MBTException

doubleClick

void doubleClick(java.lang.String locator_p)
                 throws com.webmbt.MBTException
double click on the element.

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

Throws:
com.webmbt.MBTException

rightClick

void rightClick(java.lang.String locator_p)
                throws com.webmbt.MBTException
rightClick on the element

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

Throws:
com.webmbt.MBTException

type

void type(java.lang.String locator_p,
          java.lang.String keyString_p)
          throws com.webmbt.MBTException
type the string to the element if the element is an input field.

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

Throws:
com.webmbt.MBTException

type

void type(java.lang.String locator_p,
          java.lang.String shiftCtrlAlt_p,
          java.lang.String keyString_p)
          throws com.webmbt.MBTException
type the string to the element with the option to have shift/control/alt key pressed.

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

Parameters:
locator_p -
shiftCtrlAlt_p - include char "c" for control key, "a" for alt key and "s" for shift key. For example "cs" to have control and shift keys pressed.
keyString_p -
Throws:
com.webmbt.MBTException

mouseOver

void mouseOver(java.lang.String locator_p)
               throws com.webmbt.MBTException
trigger mouse over event on the element locator_p

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

Throws:
com.webmbt.MBTException

mouseDown

void mouseDown(java.lang.String locator_p)
               throws com.webmbt.MBTException
trigger mouse down event on element locator_p

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

Parameters:
locator_p -
Throws:
com.webmbt.MBTException

mouseUp

void mouseUp(java.lang.String locator_p)
             throws com.webmbt.MBTException
trigger mouse up event on the element locator_p

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

Parameters:
locator_p -
Throws:
com.webmbt.MBTException

dragAndDrop

void dragAndDrop(java.lang.String fromLocator_p,
                 java.lang.String movement_p)
                 throws com.webmbt.MBTException
drag element, move it by the movement string and then release it (drag and drop).

Example: <action code="$dragAndDrop('id=F1','100,20')"/> to drag element F1 and drop the element at location 100px to the right and 20px down from its original location.

Parameters:
fromLocator_p - element locator
movement_p - format x,y in pixels.
Throws:
com.webmbt.MBTException

selectOption

void selectOption(java.lang.String locator_p,
                  java.lang.String optionLocator_p)
                  throws com.webmbt.MBTException
selects the option

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:
com.webmbt.MBTException

setCheckBox

void setCheckBox(java.lang.String locator_p,
                 java.lang.String checked_p)
                 throws com.webmbt.MBTException
sets the checkbox

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

Parameters:
locator_p - locator to the checkbox element
checked_p - true or false
Throws:
com.webmbt.MBTException

isChecked

boolean isChecked(java.lang.String locator_p)
                  throws com.webmbt.MBTException
returns true if the 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:
com.webmbt.MBTException

setRadioButton

void setRadioButton(java.lang.String locator_p,
                    java.lang.String checked_p)
                    throws com.webmbt.MBTException
sets the radio button

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

Parameters:
locator_p - locator to the radiobutton element
checked_p - true or false
Throws:
com.webmbt.MBTException

refresh

void refresh()
             throws com.webmbt.MBTException
click on the browser refresh button

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

Throws:
com.webmbt.MBTException

getTitle

java.lang.String getTitle()
                          throws com.webmbt.MBTException
returns the title of the current window/page.

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

Throws:
com.webmbt.MBTException

containsText

boolean containsText(java.lang.String text_p)
                     throws com.webmbt.MBTException
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:
com.webmbt.MBTException

selectWindow

void selectWindow(java.lang.String windowName_p)
                  throws com.webmbt.MBTException
select the named window as the current default window.

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

Parameters:
windowName_p - name of the window
Throws:
com.webmbt.MBTException

selectFrame

void selectFrame(java.lang.String frameName_p)
                 throws com.webmbt.MBTException
select the named frame as the current default frame.

Example: <action code="$selectFrame('frame1')"/>

Parameters:
frameName_p - name of the frame
Throws:
com.webmbt.MBTException

snapScreen

java.lang.String snapScreen(java.lang.String fileName_p)
                            throws java.lang.Exception
INTERNAL USE ONLY takes a snap shot of current browser screen and saves the result in the file name passed in.

Throws:
java.lang.Exception

waitForPageToLoad

java.lang.String waitForPageToLoad(java.lang.String timeoutMillis_p)
                                   throws com.webmbt.MBTException
waits for the page to complete the load (just html dom). Times out if the page load is not completed within the timeMillis_p. This does not include the dynamic content created by javascript or ajax. You may need to use system method sleep(millis) instead to wait for the dynamic content to be fully created and initialized by ajax and other javascript packages.

Throws:
com.webmbt.MBTException

sizeOf

int sizeOf(java.lang.String locator_p)
           throws com.webmbt.MBTException
returns the number options in the select

Throws:
com.webmbt.MBTException

getCookie

java.lang.String getCookie(java.lang.String cookieName_p)
                           throws com.webmbt.MBTException
returns the value of the cookie.

Throws:
com.webmbt.MBTException

setupConfirmResponse

void setupConfirmResponse(java.lang.String bool_p)
                          throws com.webmbt.MBTException
prepare system to handle the confirmation dialog with OK/Yes or Cancel/No. Call this function before the confirmation dialog opens up. It clears previous confirm dialog message if any. isConfirmPresent() must be called right after the action script which causes the confirm to show up. optionally you may call getConfirmText() after the isConfirmPresent() call.

Throws:
com.webmbt.MBTException

setupAlert

void setupAlert()
                throws com.webmbt.MBTException
prepare system to handle alert popup. Call this function before the alert dialog opens up. It clears previous alert message if any. isAlertPresent() must be called right after the action script which causes the alert to show up. optionally you may call getAlertText() after the isAlertPresent() call.

Throws:
com.webmbt.MBTException

getAlertText

java.lang.String getAlertText()
                              throws com.webmbt.MBTException
returns the message in the alert popup dialog if present. null if not.

Returns:
Throws:
com.webmbt.MBTException

getConfirmText

java.lang.String getConfirmText()
                                throws com.webmbt.MBTException
returns the message in the confirm popup dialog if present. null if not.

Returns:
Throws:
com.webmbt.MBTException

isAlertPresent

boolean isAlertPresent()
                       throws com.webmbt.MBTException
retusn true if the alert dialog has been displayed(triggered).

Returns:
Throws:
com.webmbt.MBTException

isConfirmPresent

boolean isConfirmPresent()
                         throws com.webmbt.MBTException
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().

Returns:
Throws:
com.webmbt.MBTException

js

java.lang.String js(java.lang.String winLocator_p,
                    java.lang.String javascript_p)
                    throws com.webmbt.MBTException
executes javascript passed in on the window identified in winLocator_p.

Parameters:
winLocator_p - locator for the window where the javascript will be executed on. win=windowName. Null or blank to run on current (top) window.

For Selenium, by default the js will be executed on the Selenium object that wraps around the user window. To execute the js on the AUT window, add prefix/qualifier window. to the js function name or js object.

javascript_p -
Returns:
blank (Selenium) or javascrpt return (HtmlUnit).
Throws:
com.webmbt.MBTException

webAuth

void webAuth(java.lang.String authType_p,
             java.lang.String userID_p,
             java.lang.String password_p,
             java.lang.String waitMillis_p,
             java.lang.String gotoURL_p)
             throws java.lang.Exception
performs HTTP basic authentication.

Parameters:
authType_p - "HttpBasicAuth", more authentication types may be added in the future.
userID_p - user id/name
password_p - password
waitMillis_p - number of milliseconds to wait for the authentication to execute
gotoURL_p - AUT url
Throws:
java.lang.Exception
Since:
3.0.30

typeKey

void typeKey(java.lang.String locator_p,
             java.lang.String keyString_p)
             throws com.webmbt.MBTException
Enters a string by pressing keys which triggers key pressed event as if user is entering the string one char at a time.

Example: $typeKey('id=textField1', 'john')

Parameters:
locator_p -
keyString_p -
Throws:
com.webmbt.MBTException

waitForCondition

void waitForCondition(java.lang.String script_p,
                      java.lang.String timeout_p)
Runs the specified JavaScript snippet repeatedly until it evaluates to "true". The snippet may have multiple lines, but only the result of the last line will be considered. Note that, by default, the snippet will be run in the runner's test window, not in the window of your application. To get the window of your application, you can use the JavaScript snippet selenium.browserbot.getCurrentWindow(), and then run your JavaScript in there.

Parameters:
script - - the JavaScript snippet to run
timeout - - a timeout in milliseconds, after which this command will return with an error


Copyright © 2008. All Rights Reserved.