Class CapybaraPortingLayerImpl
- All Implemented Interfaces:
CapybaraPortingLayer
- Direct Known Subclasses:
AbstractJUnitTest,Control,KeycloakUtils,PageAreaImpl,PageObject,PendingScript,PendingSignature,Script,SlaveController
- Author:
- Kohsuke Kawaguchi
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classprotected class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.openqa.selenium.WebDriverWebDriverthat subtypes use to talk to the server.com.google.inject.InjectorAccess to the rest of the world.static final Stringprotected ElasticTimeFields inherited from interface org.jenkinsci.test.acceptance.po.CapybaraPortingLayer
by -
Constructor Summary
ConstructorsConstructorDescriptionCapybaraPortingLayerImpl(com.google.inject.Injector injector) Some subtypes are constructed via Guice, in which case injection is done by outside this class. -
Method Summary
Modifier and TypeMethodDescriptionList<org.openqa.selenium.WebElement>all(org.openqa.selenium.By selector) Finds all the elements that match the selector.voidblur(org.openqa.selenium.WebElement e) Sends a blur event to the provided elementvoidChecks the specified checkbox.voidcheck(org.openqa.selenium.WebElement e) Checks the checkbox.voidcheck(org.openqa.selenium.WebElement e, boolean state) Sets the state of the checkbox to the specified value.org.openqa.selenium.WebElementSelect radio button by its name, id, or label text.voidclickButton(String text) voidvoidconfirmAlert(int timeout) Confirms an alert giving it some time to appearvoidelasticSleep(long ms) executeScript(String javaScript, Object... args) Executes JavaScript.voidorg.openqa.selenium.WebElementfind(org.openqa.selenium.By selector) Returns the first visible element that matches the selector.protected <T> TfindCaption(Class<?> type, Function<String, T> finder) protected <T> TfindCaption(Class<?> type, CapybaraPortingLayerImpl.Finder<T> call) org.openqa.selenium.WebElementfindIfNotVisible(org.openqa.selenium.By selector) Returns the first element that matches the selector even if not visible.Get a string representing the current URL that the browser is looking at.Get a string representing the current URL with fragment part that the browser is looking at.org.openqa.selenium.WebElementgetElement(org.openqa.selenium.By selector) Works likefind(org.openqa.selenium.By)but instead of throwing an exception, this method returns null.static StringgetPageContent(org.openqa.selenium.WebDriver driver) Get visible text on the page.Get all text of the page including markup.static StringgetPageSource(org.openqa.selenium.WebDriver driver) getPath(org.openqa.selenium.WebElement e) Resolves the path attribute from the element, handling radio buttons and checkboxes.voidhandleAlert(Consumer<org.openqa.selenium.Alert> action) protected static booleanisHiddenOrStale(org.openqa.selenium.WebElement we) protected static booleanisStale(org.openqa.selenium.WebElement element) Returnstrueif the webElement is stale (that is accessing it would cause aStaleElementReferenceExceptionto be thrownorg.openqa.selenium.WebElementlast(org.openqa.selenium.By selector) Picks up the last visible element that matches given selector.org.openqa.selenium.WebElementlastIfNotVisible(org.openqa.selenium.By selector) Picks up the last visible element that matches given selector.protected <T> TnewInstance(Class<T> type, Object... args) Finds matching constructor and invoke it.Obtains a resource in a wrapper.voidrunThenConfirmAlert(Runnable runnable) voidrunThenConfirmAlert(Runnable runnable, int timeout) Do something that triggers an alert then giving it some time to appearvoidrunThenHandleAlert(Runnable runnable, Consumer<org.openqa.selenium.Alert> action) voidrunThenHandleAlert(Runnable runnable, Consumer<org.openqa.selenium.Alert> action, int timeoutSeconds) voidrunThenHandleDialog(Runnable runnable) Helper to execute something that shows a confirmation dialog with a "Yes" button or a classical browser confirm Executes the runnable, wait for "Yes" button of the modal dialog and presses the "Yes" button" In case the runnable opens a classical browse dialog this is accepted.voidrunThenHandleInputDialog(Runnable runnable, String input, String buttonLabel) Executes the runnable, then attempts to writeinputin a dialog's input field and click the button with the specified labelbuttonLabel.voidrunThenHandleUserPrompt(Runnable runnable) voidsleep(long ms) Thread.sleep that masks exception.protected final org.openqa.selenium.WebDriverNavigates the browser to the page.waitFor()org.openqa.selenium.WebElementwaitFor(org.openqa.selenium.By selector) Wait until the element that matches the given selector appears.org.openqa.selenium.WebElementwaitFor(org.openqa.selenium.By selector, int timeoutSec) Wait until the element that matches the given selector appears.<MatcherT,SubjectT extends MatcherT>
voidwaitFor(SubjectT item, org.hamcrest.Matcher<MatcherT> matcher, int timeout) Wait until a matcher matches.<T> Wait<T>waitFor(T subject) Default waiting object configured with default timing.<T> TwaitForCond(Callable<T> block) Deprecated.<T> TwaitForCond(Callable<T> block, int timeoutSec) Deprecated.
-
Field Details
-
LABEL_TO_INPUT_XPATH
- See Also:
-
driver
@Inject protected org.openqa.selenium.WebDriver driverWebDriverthat subtypes use to talk to the server. -
injector
@Inject public com.google.inject.Injector injectorAccess to the rest of the world. -
time
-
-
Constructor Details
-
CapybaraPortingLayerImpl
public CapybaraPortingLayerImpl(com.google.inject.Injector injector) Some subtypes are constructed via Guice, in which case injection is done by outside this class. The injector parameter should be null for that case.Some subtypes are constructed programmatically. In that case, non-null injector must be supplied.
-
-
Method Details
-
getCurrentUrl
Get a string representing the current URL that the browser is looking at.- Returns:
- The URL of the page currently loaded in the browser
-
getCurrentUrlWithFragment
Get a string representing the current URL with fragment part that the browser is looking at.- Returns:
- The URL with fragment part of the page currently loaded in the browser.
-
visit
Navigates the browser to the page.- Parameters:
url- URL relative to the context path of Jenkins, such as "/about" or "/job/foo/configure".
-
clickButton
- Specified by:
clickButtonin interfaceCapybaraPortingLayer
-
choose
Select radio button by its name, id, or label text.- Specified by:
choosein interfaceCapybaraPortingLayer
-
waitFor
Default waiting object configured with default timing.- Specified by:
waitForin interfaceCapybaraPortingLayer- See Also:
-
waitFor
- Specified by:
waitForin interfaceCapybaraPortingLayer
-
waitFor
public org.openqa.selenium.WebElement waitFor(org.openqa.selenium.By selector, int timeoutSec) Wait until the element that matches the given selector appears.- Specified by:
waitForin interfaceCapybaraPortingLayer
-
waitFor
public org.openqa.selenium.WebElement waitFor(org.openqa.selenium.By selector) Description copied from interface:CapybaraPortingLayerWait until the element that matches the given selector appears.- Specified by:
waitForin interfaceCapybaraPortingLayer
-
waitForCond
Deprecated.Repeated evaluate the given predicate until it returns true.If it times out, an exception will be thrown.
- Specified by:
waitForCondin interfaceCapybaraPortingLayertimeoutSec- 0 if left to the default value
-
waitForCond
Deprecated.- Specified by:
waitForCondin interfaceCapybaraPortingLayer
-
waitFor
public <MatcherT,SubjectT extends MatcherT> void waitFor(SubjectT item, org.hamcrest.Matcher<MatcherT> matcher, int timeout) Description copied from interface:CapybaraPortingLayerWait until a matcher matches.- Specified by:
waitForin interfaceCapybaraPortingLayer
-
find
public org.openqa.selenium.WebElement find(org.openqa.selenium.By selector) Returns the first visible element that matches the selector.- Specified by:
findin interfaceCapybaraPortingLayer- Throws:
org.openqa.selenium.NoSuchElementException- if the element is not found.- See Also:
-
findIfNotVisible
public org.openqa.selenium.WebElement findIfNotVisible(org.openqa.selenium.By selector) Returns the first element that matches the selector even if not visible.- Specified by:
findIfNotVisiblein interfaceCapybaraPortingLayer- Throws:
org.openqa.selenium.NoSuchElementException- if the element is not found.- See Also:
-
getElement
public org.openqa.selenium.WebElement getElement(org.openqa.selenium.By selector) Works likefind(org.openqa.selenium.By)but instead of throwing an exception, this method returns null.- Specified by:
getElementin interfaceCapybaraPortingLayer
-
fillIn
- Specified by:
fillInin interfaceCapybaraPortingLayer
-
check
public void check(org.openqa.selenium.WebElement e) Checks the checkbox.- Specified by:
checkin interfaceCapybaraPortingLayer
-
check
public void check(org.openqa.selenium.WebElement e, boolean state) Sets the state of the checkbox to the specified value.- Specified by:
checkin interfaceCapybaraPortingLayer
-
getPath
Resolves the path attribute from the element, handling radio buttons and checkboxes.- Parameters:
e- the element to retrieve the path from.- Returns:
- the path attribute if it exists.
-
blur
public void blur(org.openqa.selenium.WebElement e) Sends a blur event to the provided element- Specified by:
blurin interfaceCapybaraPortingLayer
-
all
Finds all the elements that match the selector.Note that this method inherits the same restriction of the
WebDriver.findElements(org.openqa.selenium.By), in that its execution is not synchronized with the JavaScript execution of the browser.For example, if you click something that's expected to populate additional DOM elements, and then call
all()to find them, then all() can execute before those additional DOM elements are populated, thereby failing to find the elements you are looking for.In contrast,
find(org.openqa.selenium.By)do not have this problem, because it waits until the element that matches the criteria appears.So if you are using this method, think carefully. Perhaps you can use
find(org.openqa.selenium.By)to achieve what you are looking for (by making the query more specific), or perhaps you can combine this withwaitForCond(java.util.concurrent.Callable)so that if you don't find the elements you are looking for in the list, you'll retry.- Specified by:
allin interfaceCapybaraPortingLayer
-
last
public org.openqa.selenium.WebElement last(org.openqa.selenium.By selector) Picks up the last visible element that matches given selector.- Specified by:
lastin interfaceCapybaraPortingLayer
-
lastIfNotVisible
public org.openqa.selenium.WebElement lastIfNotVisible(org.openqa.selenium.By selector) Picks up the last visible element that matches given selector.- Specified by:
lastIfNotVisiblein interfaceCapybaraPortingLayer
-
isStale
protected static boolean isStale(org.openqa.selenium.WebElement element) Returnstrueif the webElement is stale (that is accessing it would cause aStaleElementReferenceExceptionto be thrown- Parameters:
element- the element to check.- Returns:
trueiff the element is stale.
-
isHiddenOrStale
protected static boolean isHiddenOrStale(org.openqa.selenium.WebElement we) -
executeScript
Executes JavaScript.- Specified by:
executeScriptin interfaceCapybaraPortingLayer
-
clickLink
- Specified by:
clickLinkin interfaceCapybaraPortingLayer- Parameters:
locator- Text, ID, or link.
-
check
Checks the specified checkbox.- Specified by:
checkin interfaceCapybaraPortingLayer
-
runThenHandleDialog
Helper to execute something that shows a confirmation dialog with a "Yes" button or a classical browser confirm Executes the runnable, wait for "Yes" button of the modal dialog and presses the "Yes" button" In case the runnable opens a classical browse dialog this is accepted.- Parameters:
runnable-
-
runThenHandleInputDialog
Executes the runnable, then attempts to writeinputin a dialog's input field and click the button with the specified labelbuttonLabel. If an alert appears, instead the runnable is re-run, the input written to the alert, then the alert is submitted.- Parameters:
runnable- the runnable to run that causes a dialog to appearinput- the text to input into the dialog or alertbuttonLabel- the button of the dialog to click
-
handleAlert
-
runThenHandleAlert
-
runThenHandleAlert
-
runThenHandleUserPrompt
-
confirmAlert
public void confirmAlert(int timeout) Description copied from interface:CapybaraPortingLayerConfirms an alert giving it some time to appear- Specified by:
confirmAlertin interfaceCapybaraPortingLayer- Parameters:
timeout- Maximum time to wait for the alert to appear, in seconds
-
runThenConfirmAlert
-
runThenConfirmAlert
Description copied from interface:CapybaraPortingLayerDo something that triggers an alert then giving it some time to appear- Specified by:
runThenConfirmAlertin interfaceCapybaraPortingLayer- Parameters:
runnable- Something that will trigger the alerttimeout- Maximum time to wait for the alert to appear, in seconds
-
sleep
public void sleep(long ms) Thread.sleep that masks exception. -
elasticSleep
public void elasticSleep(long ms) -
newInstance
Finds matching constructor and invoke it.This is often useful for binding
PageAreaby taking the concrete type as a parameter. -
findCaption
-
findCaption
-
getPageSource
-
getPageSource
Description copied from interface:CapybaraPortingLayerGet all text of the page including markup.- Specified by:
getPageSourcein interfaceCapybaraPortingLayer
-
getPageContent
Get visible text on the page. -
resource
Obtains a resource in a wrapper.
-