com.vaadin.testbench.
Class TestBenchTestCase
All Implemented Interfaces:
HasDriver
, HasElementQuery
, HasSearchContext
, HasTestBenchCommandExecutor
Direct Known Subclasses:
A superclass with some helpers to aid TestBench developers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.openqa.selenium.WebDriver
Specifies retry count, which is used to run same test several times.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected String
Combines a base URL with an URI to create a final URL.
protected Object
executeScript
(String script, Object... args) Executes the given JavaScript in the context of the currently selected frame or window.
org.openqa.selenium.WebElement
findElement
(org.openqa.selenium.By by) List<org.openqa.selenium.WebElement>
findElements
(org.openqa.selenium.By by) Return a reference to the related
TestBenchCommandExecutor
instance.org.openqa.selenium.SearchContext
Get a reference or a new instance of the SearchContext applicable to this class
org.openqa.selenium.WebDriver
Returns the
WebDriver
instance previously specified bysetDriver(org.openqa.selenium.WebDriver)
, or (if the previously provided WebDriver instance was not already aTestBenchDriverProxy
instance) aTestBenchDriverProxy
that wraps that driver.void
setDriver
(org.openqa.selenium.WebDriver driver) Sets the active
WebDriver
that is used by this this caseConvenience method the return
TestBenchCommands
for the defaultWebDriver
instance.protected <T> T
waitUntil
(org.openqa.selenium.support.ui.ExpectedCondition<T> condition) Waits up to 10 seconds for the given condition to become neither null nor false.
protected <T> T
waitUntil
(org.openqa.selenium.support.ui.ExpectedCondition<T> condition, long timeoutInSeconds) Waits the given number of seconds for the given condition to become neither null nor false.
<T extends TestBenchElement>
TDecorates the element with the specified Element type, making it possible to use component-specific API on elements found using standard Selenium API.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.vaadin.testbench.HasElementQuery
$, $
-
Field Details
-
maxAttempts
Specifies retry count, which is used to run same test several times. Can be changed by setting "com.vaadin.testbench.Parameters.maxAttempts" system property. Default: 1
-
driver
protected org.openqa.selenium.WebDriver driver
-
-
Constructor Details
-
TestBenchTestCase
public TestBenchTestCase()
-
-
Method Details
-
testBench
Convenience method the return
TestBenchCommands
for the defaultWebDriver
instance.Returns:
The driver cast to a TestBenchCommands instance.
-
concatUrl
Combines a base URL with an URI to create a final URL. This removes possible double slashes if the base URL ends with a slash and the URI begins with a slash.
Parameters:
baseUrl
- the base URLuri
- the URIReturns:
the URL resulting from the combination of base URL and URI
-
getDriver
public org.openqa.selenium.WebDriver getDriver()Returns the
WebDriver
instance previously specified bysetDriver(org.openqa.selenium.WebDriver)
, or (if the previously provided WebDriver instance was not already aTestBenchDriverProxy
instance) aTestBenchDriverProxy
that wraps that driver. -
setDriver
public void setDriver(org.openqa.selenium.WebDriver driver) Sets the active
WebDriver
that is used by this this caseParameters:
driver
- The WebDriver instance to set. -
getContext
public org.openqa.selenium.SearchContext getContext()Description copied from interface:
HasSearchContext
Get a reference or a new instance of the SearchContext applicable to this class
Specified by:
getContext
in interfaceHasSearchContext
Returns:
a
SearchContext
instance -
getCommandExecutor
Description copied from interface:
HasTestBenchCommandExecutor
Return a reference to the related
TestBenchCommandExecutor
instance.Specified by:
getCommandExecutor
in interfaceHasTestBenchCommandExecutor
Returns:
the
TestBenchCommandExecutor
instance -
findElement
public org.openqa.selenium.WebElement findElement(org.openqa.selenium.By by) -
findElements
-
wrap
public <T extends TestBenchElement> T wrap(Class<T> elementType, org.openqa.selenium.WebElement element) Decorates the element with the specified Element type, making it possible to use component-specific API on elements found using standard Selenium API.
Type Parameters:
T
- the type of theTestBenchElement
to returnParameters:
elementType
- The type (class) containing the API to decorate withelement
- The element instance to decorateReturns:
The element wrapped in an instance of the specified element type.
-
executeScript
Executes the given JavaScript in the context of the currently selected frame or window. The script fragment provided will be executed as the body of an anonymous function.
This method wraps any returned
WebElement
asTestBenchElement
.JavascriptExecutor.executeScript(String, Object...)
Parameters:
script
- the script to executeargs
- the arguments, available in the script asarguments[0]...arguments[N]
Returns:
whatever
JavascriptExecutor.executeScript(String, Object...)
returnsThrows:
UnsupportedOperationException
- if the underlying driver does not support JavaScript executionSee Also:
-
waitUntil
protected <T> T waitUntil(org.openqa.selenium.support.ui.ExpectedCondition<T> condition, long timeoutInSeconds) Waits the given number of seconds for the given condition to become neither null nor false.
NotFoundException
s are ignored by default.Use e.g. as
waitUntil(ExpectedConditions.presenceOfElementLocated(by), 10);
FluentWait.until(java.util.function.Function<? super T, V>)
ExpectedCondition
Type Parameters:
T
- The return type of theExpectedCondition
and this methodParameters:
condition
- Models a condition that might reasonably be expected to eventually evaluate to something that is neither null nor false.timeoutInSeconds
- The timeout in seconds for the wait.Returns:
The condition's return value if it returned something different from null or false before the timeout expired.
Throws:
org.openqa.selenium.TimeoutException
- If the timeout expires.See Also:
-
waitUntil
protected <T> T waitUntil(org.openqa.selenium.support.ui.ExpectedCondition<T> condition) Waits up to 10 seconds for the given condition to become neither null nor false.
NotFoundException
s are ignored by default.Use e.g. as
waitUntil(ExpectedConditions.presenceOfElementLocated(by));
FluentWait.until(java.util.function.Function<? super T, V>)
ExpectedCondition
Type Parameters:
T
- The return type of theExpectedCondition
and this methodParameters:
condition
- Models a condition that might reasonably be expected to eventually evaluate to something that is neither null nor false.Returns:
The condition's return value if it returned something different from null or false before the timeout expired.
Throws:
org.openqa.selenium.TimeoutException
- If 10 seconds passed.See Also:
-