Package com.vaadin.testbench
Class TestBenchTestCase
java.lang.Object
com.vaadin.testbench.TestBenchTestCase
- All Implemented Interfaces:
HasDriver
,HasElementQuery
,HasSearchContext
,HasTestBenchCommandExecutor
- Direct Known Subclasses:
ParallelTest
public abstract class TestBenchTestCase
extends Object
implements HasDriver, HasTestBenchCommandExecutor, HasElementQuery
A superclass with some helpers to aid TestBench developers.
-
Field Summary
Modifier and TypeFieldDescriptionprotected org.openqa.selenium.WebDriver
Specifies retry count, which is used to run same test several times. -
Constructor Summary
-
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 relatedTestBenchCommandExecutor
instance.org.openqa.selenium.SearchContext
Get a reference or a new instance of the SearchContext applicable to this classorg.openqa.selenium.WebDriver
Returns theWebDriver
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 activeWebDriver
that is used by this this caseConvenience method the returnTestBenchCommands
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 returnTestBenchCommands
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 URI- Returns:
- the URL resulting from the combination of base URL and URI
-
getDriver
public org.openqa.selenium.WebDriver getDriver()Returns theWebDriver
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 activeWebDriver
that is used by this this case- Parameters:
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 relatedTestBenchCommandExecutor
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 return- Parameters:
elementType
- The type (class) containing the API to decorate withelement
- The element instance to decorate- Returns:
- 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
.- Parameters:
script
- the script to executeargs
- the arguments, available in the script asarguments[0]...arguments[N]
- Returns:
- whatever
JavascriptExecutor.executeScript(String, Object...)
returns - Throws:
UnsupportedOperationException
- if the underlying driver does not support JavaScript execution- See Also:
-
JavascriptExecutor.executeScript(String, Object...)
-
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);
- Type Parameters:
T
- The return type of theExpectedCondition
and this method- Parameters:
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:
-
FluentWait.until(java.util.function.Function<? super T, V>)
ExpectedCondition
-
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));
- Type Parameters:
T
- The return type of theExpectedCondition
and this method- Parameters:
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:
-
FluentWait.until(java.util.function.Function<? super T, V>)
ExpectedCondition
-