com.webmbt.plugin.WebDriverPluginShare |
![]() |
WebDriver / Selenium plugin ancestor that contains implementats of shared methods. Only used by Selenium plugin which will be changed to call SeleniumHelper.
Copyright © 2009 - 2017 TestOptimal LLC. All Rights Reserved.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
WebDriverPluginShare() |
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 |
clear(String locator_p)
clears the input field.
| ||||||||||
void |
click(String locator_p, String coordX_p, String coordY_p)
simulate click on the first element found.
| ||||||||||
void |
click(String locator_p)
simulate click on the first element found.
| ||||||||||
void |
click(String locator_p, String shiftCtrlAlt_p)
simulate click on the first element found with option of holding down shift, ctrl or alt key.
| ||||||||||
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 | 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 |
getCookie(String cookieName_p)
returns the value of the cookie.
| ||||||||||
Object |
getNativePluginObj()
returns the plugin native driver object, e.g.
| ||||||||||
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 |
highlightElement(String locator_p, String color_p, String millis_p)
highlight element(s) by changing its border color temporarily for a duration specified in milliseconds.
| ||||||||||
void |
highlightElement(String locator_p)
highlights the element identified the locator passe in for 1 second by drawing an orange border around
the element.
| ||||||||||
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[] |
listIFrames()
returns a list of frame names of current window
| ||||||||||
String |
locate(String loc_p)
locates the element and pass back the local locator that can be used by selenium native method.
| ||||||||||
void |
mouseDown(String locator_p)
trigger mouse down event on the first element found for locator_p.
| ||||||||||
void |
mouseOver(String locator_p)
trigger mouse over event on the first element found for locator_p.
| ||||||||||
void |
mouseUp(String locator_p)
trigger mouse up event on the first element found for locator_p.
| ||||||||||
void |
openURL(String url_p)
navigate to url specified.
| ||||||||||
void |
openWindow(String url_p, String winName_p)
opens a new browser window but leave existing windows open.
| ||||||||||
void |
refresh()
click on the browser refresh button.
| ||||||||||
void |
resetMainEveryLocator(String resetFlag_p)
to instruct Selenium plugin to reset the current target window to the default main window or
first frame if window contains frameset.
| ||||||||||
void |
restartBrowser(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.
| ||||||||||
void |
scrollBy(String x_delta_p, String y_delta_p)
scrolls window by the x and y pixels specified.
| ||||||||||
void |
scrollTo(String x_p, String y_p)
scrolls window to the x,y coordinates specified.
| ||||||||||
void |
selectFrame(String frameName_p)
This method is deprecated.
rel. 4.0, use locator syntax 'frame=xxx;myLoc' where xxx is the name of the frame or 0-based index of the frame (iframe).
| ||||||||||
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.
| ||||||||||
void |
setWindowMaximized()
maximizes the browser window.
| ||||||||||
void |
setWindowPosition(String left_p, String top_p)
sets the window home position.
| ||||||||||
void |
setWindowSize(String width_p, String height_p)
sets the browser window size to the specified dimension: width and height.
| ||||||||||
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 |
type(String locator_p, String shiftCtrlAlt_p, String keyString_p)
type the string to the first element found with locator_p with the option to have shift/control/alt key pressed.
| ||||||||||
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.
|
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().@return
params_p | 0, 1 or many parameters |
---|
MBTException |
---|
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
params_p | String parameters |
---|
MBTException | |
MBTException |
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
MBTException | |
MBTException |
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
MBTException | |
MBTException |
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
MBTException | |
MBTException |
accept the alert dialog window by clicking on "OK" button.
MBTException |
---|
clears the input field.
Example:
<action code="$clear('id=F1')"/>
MBTException |
---|
simulate click on the first element found. Element must 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.
MBTException |
---|
simulate click on the first element found.
Example:
<action code="$click('id=F1')"/>
MBTException |
---|
simulate click on the first element found with option of holding down shift, ctrl or alt key.
Not available for remote testing using selenium/appium/saucelabs servers.
Example:
<action code="$click('id=F1','S')"/>
MBTException |
---|
closes a window
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')"/>Webapp only.
MBTException |
---|
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')"/>
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"/>
MBTException |
---|
dismiss the alert/confirm dialog by clicking on close or "cancel" button.
MBTException |
---|
double click on the first element found.
Example:
<action code="$doubleClick('id=F1')"/>
MBTException |
---|
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.
fromLocator_p | element locator |
---|---|
toLocator_p | element locator |
MBTException |
---|
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]
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().
MBTException |
---|
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
MBTException |
---|
returns the message in the confirm popup dialog if present. blank if not.@return
MBTException |
---|
returns the value of the cookie.
MBTException |
---|
returns the plugin native driver object, e.g. selenium returns selenium webdriver object. Not an MScript function. For use in java handler only.
returns the text representation of current webpage. Webapp only
MBTException | |
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')"/>
MBTException |
---|
returns the title of the current window/page.
Example:
<log msg="Page title is: $getTitle()"/>
MBTException |
---|
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')"/>
MBTException |
---|
highlight element(s) by changing its border color temporarily for a duration specified in milliseconds. webapp only.
color_p | html color code |
---|---|
millis_p | number of milliseconds, 0 for leaving the highlight (note this may affect your application behavior due to style attribute changed) |
Exception |
---|
highlights the element identified the locator passe in for 1 second by drawing an orange border around the element.
Exception |
---|
retusn true if the alert dialog has been displayed(triggered).
MBTException |
---|
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')"/>
locator_p | locator to the checkbox |
---|
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().
MBTException |
---|
returns true if any of the elements found is disabled.
Example:
<log msg="Field F1 disabled?: $isDisabled('id=F1')."/>
MBTException |
---|
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>
MBTException |
---|
returns true if any of the elements is visible.
Example:
<log msg="Field F1 visible?: $isVisible('id=F1')."/>
MBTException |
---|
executes javascript on current window/frame. Be sure to use "return xyz" if you wish to receive the return from the call.@return
MBTException |
---|
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 focusto the frame abc and passes
xpath=id(\'id123\')
to $_keyPress('xpath=id(\'id123\')', 'A')@returnMBTException |
---|
trigger mouse down event on the first element found for locator_p.
Example:
<action code="$mouseDown('id=F1')"/>
MBTException |
---|
trigger mouse over event on the first element found for locator_p.
Example:
<action code="$mouseOver('id=F1')"/>
MBTException |
---|
trigger mouse up event on the first element found for locator_p.
Example:
<action code="$mouseUp('id=F1')"/>
MBTException |
---|
navigate to url specified. Example:
$openURL('http://google.com/')
Exception |
---|
opens a new browser window but leave existing windows open. You may use $selectWindow() to go back to other window.
url_p | url to open |
---|---|
winName_p | name to be assigned to the window |
Exception |
---|
click on the browser refresh button.
Example:
<action code="$refresh()"/>
MBTException |
---|
to instruct Selenium plugin to reset the current target window to the default main window or first frame if window contains frameset.
Call this method with "false" to avoid constantly resetting the current target window context for better performance, but be aware that you will need to adjust your locators accordingly and call $selectWindow('') if you need redirect current target window to the main window.
closes all browser windows if any and opens a new browser window at the url passed in.
url_p | url or blank to open the browser at the model's appURL |
---|
Exception |
---|
rightClick on the first element found with locator_p.
Example:
<action code="$rightClick('id=F1')"/>
MBTException |
---|
scrolls window by the x and y pixels specified. Use negative number to scroll backwards. webapp only.
x_delta_p | integer, amount to scroll on x coordinate (horizontal axis), specify '' or '0' for no change. |
---|---|
y_delta_p | integer, amount to scroll on y coordinate (vertical axis), specify '' or '0' for no change. |
MBTException |
---|
scrolls window to the x,y coordinates specified. Upper-left corner is (0,0). webapp only.
x_p | integer, x coordinate (horizontal) |
---|---|
y_p | integer, y coordinate (vertical) |
MBTException |
---|
This method is deprecated.
rel. 4.0, use locator syntax 'frame=xxx;myLoc' where xxx is the name of the frame or 0-based index of the frame (iframe).
select the named frame as the current default frame.
Example:
<action code="$selectFrame('frame1')"/>
frameName_p | name of the frame |
---|
MBTException |
---|
selects an option for the Select element.
Example:
<action code="$selectOption('id=selectF1','value=2')"/>
locator_p | locator for the element |
---|---|
optionLocator_p | locator for the option to be selected.
|
MBTException |
---|
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')"/>
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. |
---|
MBTException |
---|
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:
|
|
|
|
MBTException |
---|
changes the browser to be used for executing mbt. Should only be called in MBT_start trigger.
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')')
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 |
---|
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.properties
in Config
folder.
sets the checkbox.
Example:
<action code="$setCheckBox('id=F1','true')"/>
locator_p | locator to the checkbox element |
---|---|
checked_p | true or false |
MBTException |
---|
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.
millis_p | number of milliseconds |
---|
sets the proxy server url for webdriver
sets the first radio button found with locator_p.
Example:
<action code="$setRadioButton('id=F1','true')"/>
locator_p | locator to the radiobutton element |
---|---|
checked_p | true or false |
MBTException |
---|
maximizes the browser window.
Example:
$setWindowMaximized()
sets the window home position. Typically you would call this method in MBT_start trigger to position the browser at the desired position.
Example:
$setWindowPosition('100', '400')
sets the browser window size to the specified dimension: width and height. Inavalid width or height value will default to 1000.
Example:
$setWindowSize('1000','2000')
returns the number options in the first select element found
MBTException |
---|
Take a snapshot of current AUT window.
Typical use of this method is to call it in 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')"/>
Exception |
---|
type the string to the first element found with locator_p with the option to have shift/control/alt key pressed. It clears the current value before issuing typing the string into the field.
Not available for remote testing using selenium/appium/saucelabs servers.
Example:
<action code="$type('id=F1','S','abc')"/>
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. |
---|
MBTException | |
MBTException |
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')"/>
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. |
MBTException |
---|
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')"/>
MBTException |
---|
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.
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. |
MBTException |
---|
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.
MBTException |
---|
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.
winName_p | name of the window or window handle (obtained with $getAllWindows() |
---|
MBTException |
---|
returns true if the window with specified name/title is found. Else return false.
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. |
---|