public class SeleniumHelper
Provides helper methods for Selenium functional tests.
Wraps counters for screenshots and other states which require initialization.
Passing browser at every method avoid handling of initialization of @Drone fields.
Most methods are non-static because they involve taking screenshots on failures which involves non-static screenshot counter.
| Modifier and Type | Class and Description |
|---|---|
static class |
SeleniumHelper.Companion |
class |
SeleniumHelper.TextToBePresentInElementWithText
Allows to retrieve the text parameter passed to
ExpectedConditions.textToBePresentInElement
as well as test the type which is useful for unit testing.
|
| Modifier and Type | Field and Description |
|---|---|
static SeleniumHelper.Companion |
Companion |
static java.lang.String |
PAGE_SOURCE_END_MARKER_DEFAULT |
static java.lang.String |
PAGE_SOURCE_START_MARKER_DEFAULT |
static java.lang.String |
SCREENSHOT_END_MARKER_DEFAULT |
static java.lang.String |
SCREENSHOT_START_MARKER_DEFAULT |
static int |
WEB_DRIVER_WAIT_TIMEOUT_DEFAULT |
| Constructor and Description |
|---|
SeleniumHelper(java.lang.String screenshotStartMarker,
java.lang.String screeenshotEndMarker,
java.lang.String pageSourceStartMarker,
java.lang.String pageSourceEndMarker,
int webDriverWaitTimeout,
java.io.File screenshotDir,
de.richtercloud.jsf.validation.service.ValidationService validationService)
Provides helper methods for Selenium functional tests.
|
SeleniumHelper(java.lang.String screenshotStartMarker,
java.lang.String screeenshotEndMarker,
java.lang.String pageSourceStartMarker,
java.lang.String pageSourceEndMarker,
int webDriverWaitTimeout,
java.io.File screenshotDir)
Provides helper methods for Selenium functional tests.
|
SeleniumHelper(int webDriverWaitTimeout)
Creates a new
SeleniumHelper using the defaults of
.SeleniumHelper and
.WEB_DRIVER_WAIT_TIMEOUT_DEFAULT for the web driver wait timeout |
SeleniumHelper()
Creates a new
SeleniumHelper using the defaults of
.SeleniumHelper and
.WEB_DRIVER_WAIT_TIMEOUT_DEFAULT for the web driver wait timeout |
SeleniumHelper(java.io.File screenshotDir) |
SeleniumHelper(int webDriverWaitTimeout,
java.io.File screenshotDir) |
| Modifier and Type | Method and Description |
|---|---|
void |
assertMessagesContains(org.openqa.selenium.WebDriver browser,
org.openqa.selenium.WebElement messages,
java.lang.String messageText,
boolean waitForMessageText)
Don't use JUnit 5 Assertions.fail or other methods since they confuse
jqwik tests
|
void |
assertMessagesContains(org.openqa.selenium.WebDriver browser,
org.openqa.selenium.WebElement messages,
java.lang.String messageText)
Don't use JUnit 5 Assertions.fail or other methods since they confuse
jqwik tests
|
void |
assertMessagesContainsAny(org.openqa.selenium.WebDriver browser,
org.openqa.selenium.WebElement messages,
java.util.Set<java.lang.String> texts)
Checks whether any string in
text is contained in the
p:messages element messages using
.webDriverWait
and returns after the first match or fails using
exception MessageTextNotContainedException if none of texts match. |
org.openqa.selenium.support.ui.FluentWait<org.openqa.selenium.WebDriver> |
createFluentWait(org.openqa.selenium.WebDriver webDriver)
Factory method for tests which has to be used until support for mocking
constructors via instrumentalisation with PowerMockito works in JUnit 5
(see comments in SeleniumHelperTest.testAssertMessagesContainsAny for
details and an issue report link).
|
org.openqa.selenium.support.ui.WebDriverWait |
createWebDriverWait(org.openqa.selenium.WebDriver webDriver,
long timeOutInSeconds) |
void |
handleWaitException(org.openqa.selenium.WebDriver browser,
java.lang.String description,
de.richtercloud.selenium.tools.WaitExceptionAction waitExceptionActions) |
void |
logDOMTree(org.openqa.selenium.JavascriptExecutor browser,
org.slf4j.Logger logger)
Logs the current state of the DOM tree by executing
return document.childNodes[1].outerHTML; in browser. |
void |
logPageSource(org.openqa.selenium.WebDriver browser,
org.slf4j.Logger logger) |
void |
logPageSourcePretty(org.openqa.selenium.WebDriver browser,
org.slf4j.Logger logger,
de.richtercloud.jsf.validation.service.ValidatorMessageSeverity validationMinimumLevel,
com.natpryce.hamkrest.Matcher<? super de.richtercloud.jsf.validation.service.ValidatorMessage> ignore)
Logs the page source retrieved from
browser to logger as
info message. |
void |
logPageSourcePretty(org.openqa.selenium.WebDriver browser,
org.slf4j.Logger logger,
de.richtercloud.jsf.validation.service.ValidatorMessageSeverity validationMinimumLevel)
Logs the page source retrieved from
browser to logger as
info message. |
void |
logPageSourcePretty(org.openqa.selenium.WebDriver browser,
org.slf4j.Logger logger)
Logs the page source retrieved from
browser to logger as
info message. |
void |
logPageSourceURLPretty(java.net.URL url,
org.slf4j.Logger logger,
de.richtercloud.jsf.validation.service.ValidatorMessageSeverity validationMinimumLevel,
com.natpryce.hamkrest.Matcher<? super de.richtercloud.jsf.validation.service.ValidatorMessage> ignore) |
static java.lang.String |
randomString(int length)
Wrapper around random string generation which allows to quickly avoid
temporary problems like Chrome Selenium driver not accepting unicode
characters outside Basic Multilingual Plane (BMP) (asked
https://stackoverflow.com/questions/46950897/how-to-produce-random-basic-multilingual-plane-bmp-strings-in-java
for inputs)
|
java.lang.String |
retrieveMessagesText(org.openqa.selenium.WebDriver browser,
org.openqa.selenium.WebElement messages) |
void |
screenshot(org.openqa.selenium.WebDriver browser,
java.lang.String description)
Takes a screenshot with description .NO_DESCRIPTION.
|
void |
screenshot(org.openqa.selenium.WebDriver browser)
Takes a screenshot with description .NO_DESCRIPTION.
|
void |
screenshotFullPage(org.openqa.selenium.WebDriver browser,
java.lang.String description) |
void |
screenshotFullPage(org.openqa.selenium.WebDriver browser) |
void |
validatePageSource(java.lang.String pageSource,
de.richtercloud.jsf.validation.service.ValidatorMessageSeverity minimumLevel,
com.natpryce.hamkrest.Matcher<? super de.richtercloud.jsf.validation.service.ValidatorMessage> ignore) |
void |
validatePageSource(java.lang.String pageSource,
de.richtercloud.jsf.validation.service.ValidatorMessageSeverity minimumLevel) |
void |
validatePageSource(java.lang.String pageSource) |
<V> void |
webDriverWait(org.openqa.selenium.WebDriver browser,
java.util.function.Function<? super org.openqa.selenium.WebDriver,V> condition) |
<V> void |
webDriverWait(org.openqa.selenium.WebDriver browser,
java.util.function.Function<? super org.openqa.selenium.WebDriver,V> condition,
java.lang.String exceptionScreenshotDescription) |
<V> void |
webDriverWait(org.openqa.selenium.WebDriver browser,
java.util.function.Function<? super org.openqa.selenium.WebDriver,V> condition,
java.lang.String exceptionScreenshotDescription,
int overrideWebDriverWaitTimout)
Creates a WebDriverWait and allows the timeout configuration in
this instance to be overridden (while other configuration parameters of
this instance can still be used).
|
<V> void |
webDriverWait(org.openqa.selenium.WebDriver browser,
java.util.function.Function<? super org.openqa.selenium.WebDriver,V> condition,
java.lang.String exceptionDescription,
de.richtercloud.selenium.tools.WaitExceptionAction waitExceptionActions)
Creates a WebDriverWait and allows the timeout configuration in
this instance to be overridden (while other configuration parameters of
this instance can still be used).
|
<V> void |
webDriverWait(org.openqa.selenium.WebDriver browser,
java.util.function.Function<? super org.openqa.selenium.WebDriver,V> condition,
java.lang.String exceptionDescription,
int overrideWebDriverWaitTimout,
de.richtercloud.selenium.tools.WaitExceptionAction waitExceptionActions)
Creates a WebDriverWait and allows the timeout configuration in
this instance to be overridden (while other configuration parameters of
this instance can still be used).
|
public static java.lang.String SCREENSHOT_START_MARKER_DEFAULT
public static java.lang.String SCREENSHOT_END_MARKER_DEFAULT
public static java.lang.String PAGE_SOURCE_START_MARKER_DEFAULT
public static java.lang.String PAGE_SOURCE_END_MARKER_DEFAULT
public static int WEB_DRIVER_WAIT_TIMEOUT_DEFAULT
public static SeleniumHelper.Companion Companion
public SeleniumHelper(java.lang.String screenshotStartMarker,
java.lang.String screeenshotEndMarker,
java.lang.String pageSourceStartMarker,
java.lang.String pageSourceEndMarker,
int webDriverWaitTimeout,
java.io.File screenshotDir,
de.richtercloud.jsf.validation.service.ValidationService validationService)
Provides helper methods for Selenium functional tests.
Wraps counters for screenshots and other states which require initialization.
Passing browser at every method avoid handling of initialization of @Drone fields.
Most methods are non-static because they involve taking screenshots on failures which involves non-static screenshot counter.
public SeleniumHelper(java.lang.String screenshotStartMarker,
java.lang.String screeenshotEndMarker,
java.lang.String pageSourceStartMarker,
java.lang.String pageSourceEndMarker,
int webDriverWaitTimeout,
java.io.File screenshotDir)
Provides helper methods for Selenium functional tests.
Wraps counters for screenshots and other states which require initialization.
Passing browser at every method avoid handling of initialization of @Drone fields.
Most methods are non-static because they involve taking screenshots on failures which involves non-static screenshot counter.
public SeleniumHelper(int webDriverWaitTimeout)
Creates a new SeleniumHelper using the defaults of
.SeleniumHelper and
.WEB_DRIVER_WAIT_TIMEOUT_DEFAULT for the web driver wait timeout
public SeleniumHelper()
Creates a new SeleniumHelper using the defaults of
.SeleniumHelper and
.WEB_DRIVER_WAIT_TIMEOUT_DEFAULT for the web driver wait timeout
public SeleniumHelper(java.io.File screenshotDir)
public SeleniumHelper(int webDriverWaitTimeout,
java.io.File screenshotDir)
public java.lang.String retrieveMessagesText(org.openqa.selenium.WebDriver browser,
org.openqa.selenium.WebElement messages)
public void assertMessagesContains(org.openqa.selenium.WebDriver browser,
org.openqa.selenium.WebElement messages,
java.lang.String messageText,
boolean waitForMessageText)
Don't use JUnit 5 Assertions.fail or other methods since they confuse jqwik tests
public void assertMessagesContains(org.openqa.selenium.WebDriver browser,
org.openqa.selenium.WebElement messages,
java.lang.String messageText)
Don't use JUnit 5 Assertions.fail or other methods since they confuse jqwik tests
public void assertMessagesContainsAny(org.openqa.selenium.WebDriver browser,
org.openqa.selenium.WebElement messages,
java.util.Set<java.lang.String> texts)
Checks whether any string in text is contained in the
p:messages element messages using
.webDriverWait
and returns after the first match or fails using
exception MessageTextNotContainedException if none of texts match.
Depending on the Selenium configuration this might a TimeoutException for
every non-matching string in texts which can be ignored.
Don't use JUnit 5 Assertions.fail or other methods since they confuse jqwik tests
browser - the web driver to usemessages - the messages element to investigatetexts - the texts to checkmessagestexts is null or
empty in order to be able to detect unexpected text conditions earlyexception MessageTextNotContainedExceptionpublic void screenshot(org.openqa.selenium.WebDriver browser,
java.lang.String description)
Takes a screenshot with description .NO_DESCRIPTION.
browser - the browser to take the screenshot from.public void screenshot(org.openqa.selenium.WebDriver browser)
Takes a screenshot with description .NO_DESCRIPTION.
browser - the browser to take the screenshot from.public void screenshotFullPage(org.openqa.selenium.WebDriver browser,
java.lang.String description)
public void screenshotFullPage(org.openqa.selenium.WebDriver browser)
public void validatePageSource(java.lang.String pageSource,
de.richtercloud.jsf.validation.service.ValidatorMessageSeverity minimumLevel,
com.natpryce.hamkrest.Matcher<? super de.richtercloud.jsf.validation.service.ValidatorMessage> ignore)
public void validatePageSource(java.lang.String pageSource,
de.richtercloud.jsf.validation.service.ValidatorMessageSeverity minimumLevel)
public void validatePageSource(java.lang.String pageSource)
public void logPageSource(org.openqa.selenium.WebDriver browser,
org.slf4j.Logger logger)
public void logPageSourcePretty(org.openqa.selenium.WebDriver browser,
org.slf4j.Logger logger,
de.richtercloud.jsf.validation.service.ValidatorMessageSeverity validationMinimumLevel,
com.natpryce.hamkrest.Matcher<? super de.richtercloud.jsf.validation.service.ValidatorMessage> ignore)
Logs the page source retrieved from browser to logger as
info message.
browser - the web driver to get the page source fromlogger - the logger to send the info message tovalidationMinimumLevel - only validation message with this level can
cause the page source to be considered invalidignore - allows to specify specific messages which ought to be
ignored or criteria to ignore a number of messagespublic void logPageSourcePretty(org.openqa.selenium.WebDriver browser,
org.slf4j.Logger logger,
de.richtercloud.jsf.validation.service.ValidatorMessageSeverity validationMinimumLevel)
Logs the page source retrieved from browser to logger as
info message.
browser - the web driver to get the page source fromlogger - the logger to send the info message tovalidationMinimumLevel - only validation message with this level can
cause the page source to be considered invalidpublic void logPageSourcePretty(org.openqa.selenium.WebDriver browser,
org.slf4j.Logger logger)
Logs the page source retrieved from browser to logger as
info message.
browser - the web driver to get the page source fromlogger - the logger to send the info message topublic void logPageSourceURLPretty(java.net.URL url,
org.slf4j.Logger logger,
de.richtercloud.jsf.validation.service.ValidatorMessageSeverity validationMinimumLevel,
com.natpryce.hamkrest.Matcher<? super de.richtercloud.jsf.validation.service.ValidatorMessage> ignore)
public void logDOMTree(org.openqa.selenium.JavascriptExecutor browser,
org.slf4j.Logger logger)
Logs the current state of the DOM tree by executing
return document.childNodes[1].outerHTML; in browser.
browser - the web driver to uselogger - the target loggerParserConfigurationException - if a parser
configuration error occurs during setup of pretty printing
dependenciesSAXException - if a SAX exception occurs during setup
of pretty printing dependenciespublic <V> void webDriverWait(org.openqa.selenium.WebDriver browser,
java.util.function.Function<? super org.openqa.selenium.WebDriver,V> condition)
public <V> void webDriverWait(org.openqa.selenium.WebDriver browser,
java.util.function.Function<? super org.openqa.selenium.WebDriver,V> condition,
java.lang.String exceptionScreenshotDescription)
public <V> void webDriverWait(org.openqa.selenium.WebDriver browser,
java.util.function.Function<? super org.openqa.selenium.WebDriver,V> condition,
java.lang.String exceptionScreenshotDescription,
int overrideWebDriverWaitTimout)
Creates a WebDriverWait and allows the timeout configuration in this instance to be overridden (while other configuration parameters of this instance can still be used).
browser - the web driver to usecondition - the condition to wait forexceptionScreenshotDescription - the timeout screenshot descriptionoverrideWebDriverWaitTimout - the wait timeoutpublic <V> void webDriverWait(org.openqa.selenium.WebDriver browser,
java.util.function.Function<? super org.openqa.selenium.WebDriver,V> condition,
java.lang.String exceptionDescription,
de.richtercloud.selenium.tools.WaitExceptionAction waitExceptionActions)
Creates a WebDriverWait and allows the timeout configuration in this instance to be overridden (while other configuration parameters of this instance can still be used).
browser - the web driver to usecondition - the condition to wait forexceptionDescription - the timeout screenshot descriptionwaitExceptionActions - the actions to take in case of an exception during waitpublic <V> void webDriverWait(org.openqa.selenium.WebDriver browser,
java.util.function.Function<? super org.openqa.selenium.WebDriver,V> condition,
java.lang.String exceptionDescription,
int overrideWebDriverWaitTimout,
de.richtercloud.selenium.tools.WaitExceptionAction waitExceptionActions)
Creates a WebDriverWait and allows the timeout configuration in this instance to be overridden (while other configuration parameters of this instance can still be used).
browser - the web driver to usecondition - the condition to wait forexceptionDescription - the timeout screenshot descriptionoverrideWebDriverWaitTimout - the wait timeoutwaitExceptionActions - the actions to take in case of an exception during waitpublic void handleWaitException(org.openqa.selenium.WebDriver browser,
java.lang.String description,
de.richtercloud.selenium.tools.WaitExceptionAction waitExceptionActions)
public org.openqa.selenium.support.ui.FluentWait<org.openqa.selenium.WebDriver> createFluentWait(org.openqa.selenium.WebDriver webDriver)
Factory method for tests which has to be used until support for mocking constructors via instrumentalisation with PowerMockito works in JUnit 5 (see comments in SeleniumHelperTest.testAssertMessagesContainsAny for details and an issue report link).
webDriver - the web driver to useFluentWait referencepublic org.openqa.selenium.support.ui.WebDriverWait createWebDriverWait(org.openqa.selenium.WebDriver webDriver,
long timeOutInSeconds)
public static java.lang.String randomString(int length)
Wrapper around random string generation which allows to quickly avoid temporary problems like Chrome Selenium driver not accepting unicode characters outside Basic Multilingual Plane (BMP) (asked https://stackoverflow.com/questions/46950897/how-to-produce-random-basic-multilingual-plane-bmp-strings-in-java for inputs)
length - the length of the produced string