Class CapybaraPortingLayerImpl
- All Implemented Interfaces:
CapybaraPortingLayer
- Direct Known Subclasses:
AbstractJUnitTest
,Control
,KeycloakUtils
,PageAreaImpl
,PageObject
,PendingScript
,PendingSignature
,Script
,SlaveController
- Author:
- Kohsuke Kawaguchi
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
protected class
-
Field Summary
Modifier and TypeFieldDescriptionprotected org.openqa.selenium.WebDriver
WebDriver
that subtypes use to talk to the server.com.google.inject.Injector
Access to the rest of the world.static final String
protected ElasticTime
Fields inherited from interface org.jenkinsci.test.acceptance.po.CapybaraPortingLayer
by
-
Constructor Summary
ConstructorDescriptionCapybaraPortingLayerImpl
(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.void
blur
(org.openqa.selenium.WebElement e) Sends a blur event to the provided elementvoid
Checks the specified checkbox.void
check
(org.openqa.selenium.WebElement e) Checks the checkbox.void
check
(org.openqa.selenium.WebElement e, boolean state) Sets the state of the checkbox to the specified value.org.openqa.selenium.WebElement
Select radio button by its name, id, or label text.void
clickButton
(String text) void
void
confirmAlert
(int timeout) Confirms an alert giving it some time to appearvoid
elasticSleep
(long ms) executeScript
(String javaScript, Object... args) Executes JavaScript.void
org.openqa.selenium.WebElement
find
(org.openqa.selenium.By selector) Returns the first visible element that matches the selector.protected <T> T
findCaption
(Class<?> type, Function<String, T> finder) protected <T> T
findCaption
(Class<?> type, CapybaraPortingLayerImpl.Finder<T> call) org.openqa.selenium.WebElement
findIfNotVisible
(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.WebElement
getElement
(org.openqa.selenium.By selector) Works likefind(org.openqa.selenium.By)
but instead of throwing an exception, this method returns null.static String
getPageContent
(org.openqa.selenium.WebDriver driver) Get visible text on the page.Get all text of the page including markup.static String
getPageSource
(org.openqa.selenium.WebDriver driver) getPath
(org.openqa.selenium.WebElement e) Resolves the path attribute from the element, handling radio buttons and checkboxes.void
handleAlert
(Consumer<org.openqa.selenium.Alert> action) protected static boolean
isHiddenOrStale
(org.openqa.selenium.WebElement we) protected static boolean
isStale
(org.openqa.selenium.WebElement element) Returnstrue
if the webElement is stale (that is accessing it would cause aStaleElementReferenceException
to be thrownorg.openqa.selenium.WebElement
last
(org.openqa.selenium.By selector) Picks up the last visible element that matches given selector.org.openqa.selenium.WebElement
lastIfNotVisible
(org.openqa.selenium.By selector) Picks up the last visible element that matches given selector.protected <T> T
newInstance
(Class<T> type, Object... args) Finds matching constructor and invoke it.Obtains a resource in a wrapper.void
runThenConfirmAlert
(Runnable runnable) void
runThenConfirmAlert
(Runnable runnable, int timeout) Do something that triggers an alert then giving it some time to appearvoid
runThenHandleAlert
(Runnable runnable, Consumer<org.openqa.selenium.Alert> action) void
runThenHandleAlert
(Runnable runnable, Consumer<org.openqa.selenium.Alert> action, int timeoutSeconds) void
runThenHandleDialog
(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.void
sleep
(long ms) Thread.sleep that masks exception.protected final org.openqa.selenium.WebDriver
Navigates the browser to the page.waitFor()
org.openqa.selenium.WebElement
waitFor
(org.openqa.selenium.By selector) Wait until the element that matches the given selector appears.org.openqa.selenium.WebElement
waitFor
(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> T
waitForCond
(Callable<T> block) Deprecated.<T> T
waitForCond
(Callable<T> block, int timeoutSec) Deprecated.
-
Field Details
-
LABEL_TO_INPUT_XPATH
- See Also:
-
driver
@Inject protected org.openqa.selenium.WebDriver driverWebDriver
that 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:
clickButton
in interfaceCapybaraPortingLayer
-
choose
Select radio button by its name, id, or label text.- Specified by:
choose
in interfaceCapybaraPortingLayer
-
waitFor
Default waiting object configured with default timing.- Specified by:
waitFor
in interfaceCapybaraPortingLayer
- See Also:
-
waitFor
- Specified by:
waitFor
in 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:
waitFor
in interfaceCapybaraPortingLayer
-
waitFor
public org.openqa.selenium.WebElement waitFor(org.openqa.selenium.By selector) Description copied from interface:CapybaraPortingLayer
Wait until the element that matches the given selector appears.- Specified by:
waitFor
in interfaceCapybaraPortingLayer
-
waitForCond
Deprecated.Repeated evaluate the given predicate until it returns true.If it times out, an exception will be thrown.
- Specified by:
waitForCond
in interfaceCapybaraPortingLayer
timeoutSec
- 0 if left to the default value
-
waitForCond
Deprecated.- Specified by:
waitForCond
in interfaceCapybaraPortingLayer
-
waitFor
public <MatcherT,SubjectT extends MatcherT> void waitFor(SubjectT item, org.hamcrest.Matcher<MatcherT> matcher, int timeout) Description copied from interface:CapybaraPortingLayer
Wait until a matcher matches.- Specified by:
waitFor
in interfaceCapybaraPortingLayer
-
find
public org.openqa.selenium.WebElement find(org.openqa.selenium.By selector) Returns the first visible element that matches the selector.- Specified by:
find
in 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:
findIfNotVisible
in 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:
getElement
in interfaceCapybaraPortingLayer
-
fillIn
- Specified by:
fillIn
in interfaceCapybaraPortingLayer
-
check
public void check(org.openqa.selenium.WebElement e) Checks the checkbox.- Specified by:
check
in interfaceCapybaraPortingLayer
-
check
public void check(org.openqa.selenium.WebElement e, boolean state) Sets the state of the checkbox to the specified value.- Specified by:
check
in 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:
blur
in 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:
all
in 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:
last
in 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:
lastIfNotVisible
in interfaceCapybaraPortingLayer
-
isStale
protected static boolean isStale(org.openqa.selenium.WebElement element) Returnstrue
if the webElement is stale (that is accessing it would cause aStaleElementReferenceException
to be thrown- Parameters:
element
- the element to check.- Returns:
true
iff the element is stale.
-
isHiddenOrStale
protected static boolean isHiddenOrStale(org.openqa.selenium.WebElement we) -
executeScript
Executes JavaScript.- Specified by:
executeScript
in interfaceCapybaraPortingLayer
-
clickLink
- Specified by:
clickLink
in interfaceCapybaraPortingLayer
- Parameters:
locator
- Text, ID, or link.
-
check
Checks the specified checkbox.- Specified by:
check
in 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
-
-
handleAlert
-
runThenHandleAlert
-
runThenHandleAlert
-
confirmAlert
public void confirmAlert(int timeout) Description copied from interface:CapybaraPortingLayer
Confirms an alert giving it some time to appear- Specified by:
confirmAlert
in interfaceCapybaraPortingLayer
- Parameters:
timeout
- Maximum time to wait for the alert to appear, in seconds
-
runThenConfirmAlert
-
runThenConfirmAlert
Description copied from interface:CapybaraPortingLayer
Do something that triggers an alert then giving it some time to appear- Specified by:
runThenConfirmAlert
in 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
PageArea
by taking the concrete type as a parameter. -
findCaption
-
findCaption
-
getPageSource
-
getPageSource
Description copied from interface:CapybaraPortingLayer
Get all text of the page including markup.- Specified by:
getPageSource
in interfaceCapybaraPortingLayer
-
getPageContent
Get visible text on the page. -
resource
Obtains a resource in a wrapper.
-