public class SingleBrowserSeleniumClient extends com.thoughtworks.selenium.DefaultSelenium implements SeleniumClient
DefaultSelenium client to provide a more sensible implementation
as well some extra utility methods such as keypress.| Modifier and Type | Field and Description |
|---|---|
protected long |
ACTION_WAIT
The maximum wait time for actions that don't require page loads.
|
protected long |
PAGE_LOAD_WAIT
The maximum page load wait time used by Selenium.
|
| Constructor and Description |
|---|
SingleBrowserSeleniumClient(SeleniumConfiguration config) |
| Modifier and Type | Method and Description |
|---|---|
void |
captureEntirePageScreenshot(String filePath) |
void |
check(String name,
String value)
Checks a checkbox given a name and value.
|
void |
click(String locator,
boolean waitForPageToLoad)
Click the element with the given locator and optionally wait for the page to load, using
PAGE_LOAD_WAIT. |
void |
click(String locator,
long timeoutMillis)
Click the element with the given locator and wait for the page to load, for a maximum of timeoutMillis.
|
void |
clickAndWaitForAjaxWithJquery(String locator)
Click the element with the given locator and wait for the ajax call to finish.
|
void |
clickAndWaitForAjaxWithJquery(String locator,
long timeoutMillis)
Click the element with the given locator and wait for the ajax call to finish.
|
void |
clickButton(String buttonText,
boolean waitForPageToLoad) |
void |
clickButtonAndWaitForAjaxWithJquery(String buttonText) |
void |
clickButtonWithName(String buttonName,
boolean waitForPageToLoad) |
void |
clickButtonWithNameAndWaitForAjaxWithJquery(String buttonName) |
void |
clickElementWithClass(String className) |
void |
clickElementWithClassAndWaitForAjaxWithJquery(String className) |
void |
clickElementWithCss(String cssSelector) |
void |
clickElementWithCssAndWaitForAjaxWithJquery(String cssSelector) |
void |
clickElementWithTitle(String title) |
void |
clickElementWithTitleAndWaitForAjaxWithJquery(String title) |
void |
clickElementWithXpath(String xpath) |
void |
clickElementWithXpathAndWaitForAjaxWithJquery(String xpath) |
void |
clickLinkWithText(String text,
boolean waitForPageToLoad) |
void |
evaluate(String command)
Execute a script in the client.
|
Object |
execute(String command,
Object... arguments)
Execute a script on the client.
|
void |
generateKeyEvent(String locator,
KeyEventType eventType,
int keyCode,
int characterCode,
boolean shiftKey,
boolean altKey,
boolean controlKey,
boolean metaKey)
This is a low level function to generate one keyboard event.
|
Browser |
getBrowser() |
ScreenElement |
getElementAtPoint(int x,
int y) |
boolean |
hasJquery() |
void |
keyPress(String locator,
String key)
This will type into a field by sending key down / key press / key up events.
|
void |
open(String url)
Unlike
DefaultSelenium.open(java.lang.String, java.lang.String), this opens the provided URL relative to the application context path. |
void |
open(String url,
long timeoutMillis)
Opens the given URL and waits a maximum of timeoutMillis for the page to load completely.
|
void |
openNoWait(String url)
Wait for page to load doesn't work the case of non-HTML based resources (like images).
|
void |
refreshAndWait() |
boolean |
resizeScreen(ScreenResolution resolution,
boolean refreshAfterResize) |
void |
selectOption(String selectName,
String label)
This will select an option from a
select field. |
void |
selectOptionAndWaitForAjaxWithJquery(String selectName,
String label)
This will select an option from a
select field. |
void |
seleniumKeyPress(String locator,
String key) |
void |
simulateKeyPressForCharacter(String locator,
Character character)
This will send all the events for a particular character
NOTE: This function will only handle vanilla ascii characters
more exotic characters will be ignored (ie.
|
void |
simulateKeyPressForCharacter(String locator,
Character character,
Collection<KeyEventType> eventsToFire)
This will send all the events for a particular character
NOTE: This function will only handle vanilla ascii characters
more exotic characters will be ignored (ie.
|
void |
simulateKeyPressForSpecialKey(String locator,
int keyCode)
This will send all the events for a particular special key (for example F1 or the down arrow key)
The keyCode matches the codes in java.awt.event.KeyEvent
NOTE: the return key actually fires events with a keyCode of 13 NOT VK_ENTER
This will fire ALL events for the special key.
|
void |
simulateKeyPressForSpecialKey(String locator,
int keyCode,
Collection<KeyEventType> eventsToFire)
This will send all the events for a particular special key (for example F1 or the down arrow key)
The keyCode matches the codes in java.awt.event.KeyEvent
NOTE: the return key actually fires events with a keyCode of 13 NOT VK_ENTER
*
|
void |
start() |
void |
submit(String form,
boolean waitForPageToLoad)
Submit the named form locator and optionally wait for the page to load, using
PAGE_LOAD_WAIT. |
void |
submit(String form,
long timeoutMillis)
Submit the given form and wait for the page to load, for a maximum of timeoutMillis.
|
void |
toggleToCharacterCode(boolean toCharacterCode)
This sets if subsiquent calls to the keyEvent (@keyDown, @keyPress, @keyUp) fuctions
will set the code in the characterCode or not.
|
void |
toggleToKeyCode(boolean toKeyCode)
This sets if subsiquent calls to the keyEvent (@keyDown, @keyPress, @keyUp) fuctions
will set the code in the keyCode or not.
|
void |
typeInElementWithCss(String cssSelector,
String text) |
void |
typeInElementWithName(String elementName,
String text) |
void |
typeWithFullKeyEvents(String locator,
String string)
This will type into a field by first blanking it out and then sending key down / key press / key up
events.
|
void |
typeWithFullKeyEvents(String locator,
String string,
boolean reset)
This will type into a field by first blanking it out and then sending key down / key press / key up
events.
|
void |
waitForAjaxWithJquery()
Waits for the page to finish loading ajax calls, and returns if there are no more ajax calls currently running.
|
void |
waitForAjaxWithJquery(long timeoutMillis)
Waits for the page to finish loading ajax calls, and returns if there are no more ajax calls currently running.
|
void |
waitForCondition(String javascript)
Executes the given Javascript in the context of the text page and waits for it to evaluate to true
for a maximum of
ACTION_WAIT milliseconds. |
void |
waitForCondition(String javascript,
long timeoutMillis)
Executes the given Javascript in the context of the text page and waits for it to evaluate to true
for a maximum of timeoutMillis.
|
boolean |
waitForJQuery(long waitTimeMillis)
Wait for jQuery AJAX calls to return.
|
void |
waitForPageToLoad()
Waits for the page to load with the default timeout configured in
SeleniumConfiguration. |
void |
waitForPageToLoad(long timeoutMillis)
Overloads
DefaultSelenium.waitForPageToLoad(String) to take in a long. |
addCustomRequestHeader, addLocationStrategy, addScript, addSelection, allowNativeXpath, altKeyDown, altKeyUp, answerOnNextPrompt, assignId, attachFile, captureEntirePageScreenshot, captureEntirePageScreenshotToString, captureNetworkTraffic, captureScreenshot, captureScreenshotToString, check, chooseCancelOnNextConfirmation, chooseOkOnNextConfirmation, click, clickAt, close, contextMenu, contextMenuAt, controlKeyDown, controlKeyUp, createCookie, deleteAllVisibleCookies, deleteCookie, deselectPopUp, doubleClick, doubleClickAt, dragAndDrop, dragAndDropToObject, dragdrop, fireEvent, focus, getAlert, getAllButtons, getAllFields, getAllLinks, getAllWindowIds, getAllWindowNames, getAllWindowTitles, getAttribute, getAttributeFromAllWindows, getBodyText, getConfirmation, getCookie, getCookieByName, getCssCount, getCursorPosition, getElementHeight, getElementIndex, getElementPositionLeft, getElementPositionTop, getElementWidth, getEval, getExpression, getHtmlSource, getLocation, getLog, getMouseSpeed, getPrompt, getSelectedId, getSelectedIds, getSelectedIndex, getSelectedIndexes, getSelectedLabel, getSelectedLabels, getSelectedValue, getSelectedValues, getSelectOptions, getSpeed, getTable, getText, getTitle, getValue, getWhetherThisFrameMatchFrameExpression, getWhetherThisWindowMatchWindowExpression, getXpathCount, goBack, highlight, ignoreAttributesWithoutValue, isAlertPresent, isChecked, isConfirmationPresent, isCookiePresent, isEditable, isElementPresent, isOrdered, isPromptPresent, isSomethingSelected, isTextPresent, isVisible, keyDown, keyDownNative, keyPressNative, keyUp, keyUpNative, metaKeyDown, metaKeyUp, mouseDown, mouseDownAt, mouseDownRight, mouseDownRightAt, mouseMove, mouseMoveAt, mouseOut, mouseOver, mouseUp, mouseUpAt, mouseUpRight, mouseUpRightAt, open, openWindow, refresh, removeAllSelections, removeScript, removeSelection, retrieveLastRemoteControlLogs, rollup, runScript, select, selectFrame, selectPopUp, selectWindow, setBrowserLogLevel, setContext, setCursorPosition, setExtensionJs, setMouseSpeed, setSpeed, setTimeout, shiftKeyDown, shiftKeyUp, showContextualBanner, showContextualBanner, shutDownSeleniumServer, start, start, stop, submit, type, typeKeys, uncheck, useXpathLibrary, waitForCondition, waitForFrameToLoad, waitForPageToLoad, waitForPopUp, windowFocus, windowMaximizeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddCustomRequestHeader, addLocationStrategy, addScript, addSelection, allowNativeXpath, altKeyDown, altKeyUp, answerOnNextPrompt, assignId, attachFile, captureEntirePageScreenshot, captureEntirePageScreenshotToString, captureNetworkTraffic, captureScreenshot, captureScreenshotToString, check, chooseCancelOnNextConfirmation, chooseOkOnNextConfirmation, click, clickAt, close, contextMenu, contextMenuAt, controlKeyDown, controlKeyUp, createCookie, deleteAllVisibleCookies, deleteCookie, deselectPopUp, doubleClick, doubleClickAt, dragAndDrop, dragAndDropToObject, dragdrop, fireEvent, focus, getAlert, getAllButtons, getAllFields, getAllLinks, getAllWindowIds, getAllWindowNames, getAllWindowTitles, getAttribute, getAttributeFromAllWindows, getBodyText, getConfirmation, getCookie, getCookieByName, getCssCount, getCursorPosition, getElementHeight, getElementIndex, getElementPositionLeft, getElementPositionTop, getElementWidth, getEval, getExpression, getHtmlSource, getLocation, getLog, getMouseSpeed, getPrompt, getSelectedId, getSelectedIds, getSelectedIndex, getSelectedIndexes, getSelectedLabel, getSelectedLabels, getSelectedValue, getSelectedValues, getSelectOptions, getSpeed, getTable, getText, getTitle, getValue, getWhetherThisFrameMatchFrameExpression, getWhetherThisWindowMatchWindowExpression, getXpathCount, goBack, highlight, ignoreAttributesWithoutValue, isAlertPresent, isChecked, isConfirmationPresent, isCookiePresent, isEditable, isElementPresent, isOrdered, isPromptPresent, isSomethingSelected, isTextPresent, isVisible, keyDown, keyDownNative, keyPressNative, keyUp, keyUpNative, metaKeyDown, metaKeyUp, mouseDown, mouseDownAt, mouseDownRight, mouseDownRightAt, mouseMove, mouseMoveAt, mouseOut, mouseOver, mouseUp, mouseUpAt, mouseUpRight, mouseUpRightAt, open, openWindow, refresh, removeAllSelections, removeScript, removeSelection, retrieveLastRemoteControlLogs, rollup, runScript, select, selectFrame, selectPopUp, selectWindow, setBrowserLogLevel, setContext, setCursorPosition, setExtensionJs, setMouseSpeed, setSpeed, setTimeout, shiftKeyDown, shiftKeyUp, showContextualBanner, showContextualBanner, shutDownSeleniumServer, start, start, stop, submit, type, typeKeys, uncheck, useXpathLibrary, waitForCondition, waitForFrameToLoad, waitForPageToLoad, waitForPopUp, windowFocus, windowMaximizeprotected final long PAGE_LOAD_WAIT
SeleniumConfiguration.getPageLoadWait().protected final long ACTION_WAIT
SeleniumConfiguration.getActionWait().public SingleBrowserSeleniumClient(SeleniumConfiguration config)
public Browser getBrowser()
getBrowser in interface SeleniumClientpublic void seleniumKeyPress(String locator, String key)
seleniumKeyPress in interface SeleniumClientpublic void open(String url)
DefaultSelenium.open(java.lang.String, java.lang.String), this opens the provided URL relative to the application context path.
It also waits for the page to load -- a maximum of PAGE_LOAD_WAIT before returning.open in interface SeleniumClientopen in interface com.thoughtworks.selenium.Seleniumopen in class com.thoughtworks.selenium.DefaultSeleniumpublic void openNoWait(String url)
openNoWait in interface SeleniumClienturl - public void open(String url, long timeoutMillis)
open in interface SeleniumClientpublic void waitForPageToLoad(long timeoutMillis)
DefaultSelenium.waitForPageToLoad(String) to take in a long.waitForPageToLoad in interface SeleniumClientpublic void waitForPageToLoad()
SeleniumConfiguration.waitForPageToLoad in interface SeleniumClientpublic void waitForCondition(String javascript)
ACTION_WAIT milliseconds.waitForCondition in interface SeleniumClientif you would like to specify your own timeout.public void waitForCondition(String javascript, long timeoutMillis)
waitForCondition in interface SeleniumClientpublic void waitForAjaxWithJquery()
ACTION_WAIT millisecondswaitForAjaxWithJquery in interface SeleniumClientif you would like to specify your own timeout.public void waitForAjaxWithJquery(long timeoutMillis)
waitForAjaxWithJquery in interface SeleniumClientpublic void click(String locator, boolean waitForPageToLoad)
PAGE_LOAD_WAIT.click in interface SeleniumClientlocator - the element to click, specified using Selenium selector syntaxwaitForPageToLoad - whether to wait for the page to reload. Don't use this unless the page is completely
reloaded.if you would like to specify your own timeout.public void submit(String form, boolean waitForPageToLoad)
PAGE_LOAD_WAIT.submit in interface SeleniumClientform - to click, specified using Selenium selector syntaxwaitForPageToLoad - whether to wait for the page to reload. Don't use this unless the page is completely
reloaded.if you would like to specify your own timeout.public void click(String locator, long timeoutMillis)
click in interface SeleniumClientlocator - the element to click, specified using Selenium selector syntaxtimeoutMillis - the maximum number of milliseconds to wait for the page to load. Polling takes place
more frequently.if you would like to use the default timeoutpublic void clickAndWaitForAjaxWithJquery(String locator)
clickAndWaitForAjaxWithJquery in interface SeleniumClientlocator - the element to click, specified using Selenium selector syntaxpublic void clickAndWaitForAjaxWithJquery(String locator, long timeoutMillis)
clickAndWaitForAjaxWithJquery in interface SeleniumClientlocator - the element to click, specified using Selenium selector syntaxtimeoutMillis - the maximum number of milliseconds to wait for the ajax calls to finish.if you would like to use the default timeoutpublic void submit(String form, long timeoutMillis)
submit in interface SeleniumClientform - the form to submittimeoutMillis - the maximum number of milliseconds to wait for the page to load. Polling takes place
more frequently.if you would like to use the default timeoutpublic void keyPress(String locator, String key)
keyPress in interface SeleniumClientkeyPress in interface com.thoughtworks.selenium.SeleniumkeyPress in class com.thoughtworks.selenium.DefaultSeleniumlocator - Uses the Selenium locator syntaxkey - The key to be pressedpublic void typeWithFullKeyEvents(String locator, String string, boolean reset)
typeWithFullKeyEvents in interface SeleniumClientlocator - the Selenium locatorstring - the string to typereset - Should the field be reset first?public void typeWithFullKeyEvents(String locator, String string)
typeWithFullKeyEvents(String,String,boolean))}typeWithFullKeyEvents in interface SeleniumClientlocator - - the usual Selenium locatorstring - the string to type into a fieldpublic void simulateKeyPressForCharacter(String locator, Character character)
SeleniumClientsimulateKeyPressForCharacter in interface SeleniumClientlocator - - the usual Selenium locatorcharacter - - the character to sendpublic void simulateKeyPressForCharacter(String locator, Character character, Collection<KeyEventType> eventsToFire)
SeleniumClientsimulateKeyPressForCharacter in interface SeleniumClientlocator - - the usual Selenium locatorcharacter - - the character to sendeventsToFire - - a collection of the types of events to Firepublic void simulateKeyPressForSpecialKey(String locator, int keyCode)
SeleniumClientsimulateKeyPressForSpecialKey in interface SeleniumClientlocator - - the usual Selenium locatorkeyCode - - the code for the special Key can use java.awt.event.KeyEvent.XXX to find thesepublic void simulateKeyPressForSpecialKey(String locator, int keyCode, Collection<KeyEventType> eventsToFire)
SeleniumClientsimulateKeyPressForSpecialKey in interface SeleniumClientlocator - - the usual Selenium locatorkeyCode - - the code for the special Key can use java.awt.event.KeyEvent.XXX to find theseeventsToFire - - a collection of the types of events to Firepublic void generateKeyEvent(String locator, KeyEventType eventType, int keyCode, int characterCode, boolean shiftKey, boolean altKey, boolean controlKey, boolean metaKey)
SeleniumClientgenerateKeyEvent in interface SeleniumClientlocator - - the locator of the element to send the keyevent toeventType - - The type of key eventkeyCode - - the keyCode for the keyEventcharacterCode - - the character code for the key eventshiftKey - - Is the shift key down?altKey - - Is the alt/option key down?controlKey - - Is the control key down?metaKey - - Is the meta (aka the apple or windows) key down?public void toggleToKeyCode(boolean toKeyCode)
SeleniumClienttoggleToKeyCode in interface SeleniumClienttoKeyCode - - to set or not to set the keyCode in the eventpublic void toggleToCharacterCode(boolean toCharacterCode)
SeleniumClienttoggleToCharacterCode in interface SeleniumClienttoCharacterCode - - to set or not to set the characterCode in the eventpublic void selectOption(String selectName, String label)
select field.selectOption in interface SeleniumClientselectName - the select field namelabel - the label to selectpublic void selectOptionAndWaitForAjaxWithJquery(String selectName, String label)
select field. If the field calls executes an ajax call onchange of
the value, this method will wait for that ajax method to finish.selectOptionAndWaitForAjaxWithJquery in interface SeleniumClientselectName - the select field namelabel - the label to selectpublic void check(String name, String value)
check in interface SeleniumClientpublic void clickLinkWithText(String text, boolean waitForPageToLoad)
clickLinkWithText in interface SeleniumClientpublic void clickButton(String buttonText, boolean waitForPageToLoad)
clickButton in interface SeleniumClientpublic void clickButtonAndWaitForAjaxWithJquery(String buttonText)
clickButtonAndWaitForAjaxWithJquery in interface SeleniumClientpublic void clickButtonWithName(String buttonName, boolean waitForPageToLoad)
clickButtonWithName in interface SeleniumClientpublic void clickButtonWithNameAndWaitForAjaxWithJquery(String buttonName)
clickButtonWithNameAndWaitForAjaxWithJquery in interface SeleniumClientpublic void clickElementWithTitle(String title)
clickElementWithTitle in interface SeleniumClientpublic void clickElementWithTitleAndWaitForAjaxWithJquery(String title)
clickElementWithTitleAndWaitForAjaxWithJquery in interface SeleniumClientpublic void clickElementWithClass(String className)
clickElementWithClass in interface SeleniumClientpublic void clickElementWithClassAndWaitForAjaxWithJquery(String className)
clickElementWithClassAndWaitForAjaxWithJquery in interface SeleniumClientpublic void clickElementWithCss(String cssSelector)
clickElementWithCss in interface SeleniumClientpublic void clickElementWithCssAndWaitForAjaxWithJquery(String cssSelector)
clickElementWithCssAndWaitForAjaxWithJquery in interface SeleniumClientpublic void clickElementWithXpath(String xpath)
clickElementWithXpath in interface SeleniumClientpublic void clickElementWithXpathAndWaitForAjaxWithJquery(String xpath)
clickElementWithXpathAndWaitForAjaxWithJquery in interface SeleniumClientpublic void typeInElementWithName(String elementName, String text)
typeInElementWithName in interface SeleniumClientpublic void typeInElementWithCss(String cssSelector, String text)
typeInElementWithCss in interface SeleniumClientpublic boolean hasJquery()
hasJquery in interface SeleniumClientpublic void start()
start in interface SeleniumClientstart in interface com.thoughtworks.selenium.Seleniumstart in class com.thoughtworks.selenium.DefaultSeleniumpublic void evaluate(String command)
VisualComparableClientevaluate in interface VisualComparableClientcommand - a string of javascript to send to the client.public Object execute(String command, Object... arguments)
execute in interface VisualComparableClientcommand - a string of javascript to send to the client.arguments - Selenium does not accept additional arguments. These will be ignored.public void captureEntirePageScreenshot(String filePath)
captureEntirePageScreenshot in interface VisualComparableClientpublic boolean resizeScreen(ScreenResolution resolution, boolean refreshAfterResize)
resizeScreen in interface VisualComparableClientpublic void refreshAndWait()
refreshAndWait in interface VisualComparableClientpublic boolean waitForJQuery(long waitTimeMillis)
waitForJQuery in interface VisualComparableClientwaitTimeMillis - the time to wait for everything to finish.public ScreenElement getElementAtPoint(int x, int y)
getElementAtPoint in interface VisualComparableClientCopyright © 2015 Atlassian. All rights reserved.