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
FieldsModifier and TypeFieldDescriptionprotected org.openqa.selenium.WebDriverSpecifies retry count, which is used to run same test several times. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringCombines a base URL with an URI to create a final URL.protected ObjectexecuteScript(String script, Object... args) Executes the given JavaScript in the context of the currently selected frame or window.org.openqa.selenium.WebElementfindElement(org.openqa.selenium.By by) List<org.openqa.selenium.WebElement>findElements(org.openqa.selenium.By by) Return a reference to the relatedTestBenchCommandExecutorinstance.org.openqa.selenium.SearchContextGet a reference or a new instance of the SearchContext applicable to this classorg.openqa.selenium.WebDriverReturns theWebDriverinstance previously specified bysetDriver(org.openqa.selenium.WebDriver), or (if the previously provided WebDriver instance was not already aTestBenchDriverProxyinstance) aTestBenchDriverProxythat wraps that driver.voidsetDriver(org.openqa.selenium.WebDriver driver) Sets the activeWebDriverthat is used by this this caseConvenience method the returnTestBenchCommandsfor the defaultWebDriverinstance.protected <T> TwaitUntil(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> TwaitUntil(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, waitMethods 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 returnTestBenchCommandsfor the defaultWebDriverinstance.- 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 theWebDriverinstance previously specified bysetDriver(org.openqa.selenium.WebDriver), or (if the previously provided WebDriver instance was not already aTestBenchDriverProxyinstance) aTestBenchDriverProxythat wraps that driver. -
setDriver
public void setDriver(org.openqa.selenium.WebDriver driver) Sets the activeWebDriverthat is used by this this case- Parameters:
driver- The WebDriver instance to set.
-
getContext
public org.openqa.selenium.SearchContext getContext()Description copied from interface:HasSearchContextGet a reference or a new instance of the SearchContext applicable to this class- Specified by:
getContextin interfaceHasSearchContext- Returns:
- a
SearchContextinstance
-
getCommandExecutor
Description copied from interface:HasTestBenchCommandExecutorReturn a reference to the relatedTestBenchCommandExecutorinstance.- Specified by:
getCommandExecutorin interfaceHasTestBenchCommandExecutor- Returns:
- the
TestBenchCommandExecutorinstance
-
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 theTestBenchElementto 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
WebElementasTestBenchElement.- 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.NotFoundExceptions are ignored by default.Use e.g. as
waitUntil(ExpectedConditions.presenceOfElementLocated(by), 10);- Type Parameters:
T- The return type of theExpectedConditionand 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.NotFoundExceptions are ignored by default.Use e.g. as
waitUntil(ExpectedConditions.presenceOfElementLocated(by));- Type Parameters:
T- The return type of theExpectedConditionand 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
-