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
Fields Modifier and Type Field Description protected org.openqa.selenium.WebDriverdriverRetryRulemaxAttemptsSpecifies retry count, which is used to run same test several times.static StringtestbenchVersion
-
Constructor Summary
Constructors Constructor Description TestBenchTestCase()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected StringconcatUrl(String baseUrl, String uri)Combines 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)TestBenchCommandExecutorgetCommandExecutor()Return a reference to the relatedTestBenchCommandExecutorinstance.org.openqa.selenium.SearchContextgetContext()Get a reference or a new instance of the SearchContext applicable to this classorg.openqa.selenium.WebDrivergetDriver()Returns 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 caseTestBenchCommandstestBench()Convenience 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>
Twrap(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.-
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 Detail
-
testbenchVersion
public static final String testbenchVersion
-
maxAttempts
public RetryRule 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
-
-
Method Detail
-
testBench
public TestBenchCommands testBench()
Convenience method the returnTestBenchCommandsfor the defaultWebDriverinstance.- Returns:
- The driver cast to a TestBenchCommands instance.
-
concatUrl
protected String concatUrl(String baseUrl, String uri)
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
public TestBenchCommandExecutor getCommandExecutor()
Description copied from interface:HasTestBenchCommandExecutorReturn a reference to the relatedTestBenchCommandExecutorinstance.- Specified by:
getCommandExecutorin interfaceHasTestBenchCommandExecutor- Returns:
-
findElement
public org.openqa.selenium.WebElement findElement(org.openqa.selenium.By by)
-
findElements
public List<org.openqa.selenium.WebElement> findElements(org.openqa.selenium.By by)
-
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.- 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
protected Object executeScript(String script, Object... args)
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);- 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));- 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
-
-