Package com.vaadin.flow.testutil
Class TestBenchHelpers
java.lang.Object
com.vaadin.testbench.TestBenchTestCase
com.vaadin.testbench.parallel.ParallelTest
com.vaadin.flow.testutil.TestBenchHelpers
- All Implemented Interfaces:
com.vaadin.testbench.HasDriver,com.vaadin.testbench.HasElementQuery,com.vaadin.testbench.HasSearchContext,com.vaadin.testbench.HasTestBenchCommandExecutor
- Direct Known Subclasses:
AbstractParallelTestBenchTest,AbstractTestBenchTest
public class TestBenchHelpers
extends com.vaadin.testbench.parallel.ParallelTest
Helpers for running testbench tests.
- Since:
- 1.0
-
Field Summary
Fields inherited from class com.vaadin.testbench.parallel.ParallelTest
screenshotOnFailureFields inherited from class com.vaadin.testbench.TestBenchTestCase
driver, maxAttempts -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static voidassertEquals(org.openqa.selenium.WebElement expectedElement, org.openqa.selenium.WebElement actualElement) Assert that the two elements are equal.voidblur()Calls theblur()function on the current active element of the page, if any.protected voidChecks browser's log entries, throws an error for any client-side error and logs any client-side warnings.protected voidcheckLogsForErrors(Predicate<String> acceptableMessagePredicate) Checks browser's log entries, throws an error for any client-side error and logs any client-side warnings.protected voidclickElementWithJs(String elementId) Clicks on the element, using JS.protected voidclickElementWithJs(org.openqa.selenium.WebElement element) Clicks on the element, using JS.voiddrag(org.openqa.selenium.WebElement source) Simulate only a drag ofsource.voiddragAndDrop(org.openqa.selenium.WebElement source, org.openqa.selenium.WebElement target) Simulate DnD ofsourceelement into thetargetelement.voiddragElementOver(org.openqa.selenium.WebElement source, org.openqa.selenium.WebElement target) Simulate a drag ofsourceelement and over thetargetelement.protected ObjectexecuteScript(String script, Object... args) Executes the given JavaScript.protected List<org.openqa.selenium.logging.LogEntry> getLogEntries(Level level) Gets the log entries from the browser that have the given logging level or higher.protected intGets current scroll position on x axis.protected intGets current scroll position on y axis.protected booleanhasCssClass(org.openqa.selenium.WebElement element, String className) Checks if the given element has the given class name.booleanisElementPresent(org.openqa.selenium.By by) Returns true if an element can be found from the driver with given selector.protected voidscrollBy(int deltaX, int deltaY) Scrolls the page by given amount of x and y deltas.protected voidscrollIntoViewAndClick(org.openqa.selenium.WebElement element) Scrolls the page to the element specified and clicks it.protected voidscrollToElement(org.openqa.selenium.WebElement element) Scrolls the page to the element given using javascript.protected voidIf dev server start in progress wait until it's started.protected voidwaitForElementNotPresent(org.openqa.selenium.By by) protected voidwaitForElementPresent(org.openqa.selenium.By by) protected voidwaitForElementVisible(org.openqa.selenium.By by) protected <T> voidwaitUntilNot(org.openqa.selenium.support.ui.ExpectedCondition<T> condition) Waits up to 10s for the given condition to become false.protected <T> voidwaitUntilNot(org.openqa.selenium.support.ui.ExpectedCondition<T> condition, long timeoutInSeconds) Waits the given number of seconds for the given condition to become false.Methods inherited from class com.vaadin.testbench.parallel.ParallelTest
getDefaultCapabilities, getDesiredCapabilities, getHubHostname, getHubURL, getRunLocallyBrowser, getRunLocallyBrowserVersion, getRunOnHub, setDesiredCapabilities, setupMethods inherited from class com.vaadin.testbench.TestBenchTestCase
concatUrl, findElement, findElements, getCommandExecutor, getContext, getDriver, setDriver, testBench, waitUntil, waitUntil, wrapMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.testbench.HasElementQuery
$, $
-
Constructor Details
-
TestBenchHelpers
public TestBenchHelpers()
-
-
Method Details
-
waitUntilNot
protected <T> void waitUntilNot(org.openqa.selenium.support.ui.ExpectedCondition<T> condition) Waits up to 10s for the given condition to become false. Use e.g. aswaitUntilNot(ExpectedCondition).- Type Parameters:
T- the return type of the expected condition- Parameters:
condition- the condition to wait for to become false
-
isElementPresent
public boolean isElementPresent(org.openqa.selenium.By by) Returns true if an element can be found from the driver with given selector.- Parameters:
by- the selector used to find element- Returns:
- true if the element can be found
-
dragAndDrop
public void dragAndDrop(org.openqa.selenium.WebElement source, org.openqa.selenium.WebElement target) Simulate DnD ofsourceelement into thetargetelement.- Parameters:
source-target-
-
drag
public void drag(org.openqa.selenium.WebElement source) Simulate only a drag ofsource.- Parameters:
source-
-
dragElementOver
public void dragElementOver(org.openqa.selenium.WebElement source, org.openqa.selenium.WebElement target) Simulate a drag ofsourceelement and over thetargetelement.- Parameters:
source-target-
-
waitUntilNot
protected <T> void waitUntilNot(org.openqa.selenium.support.ui.ExpectedCondition<T> condition, long timeoutInSeconds) Waits the given number of seconds for the given condition to become false. Use e.g. aswaitUntilNot(ExpectedCondition).- Type Parameters:
T- the return type of the expected condition- Parameters:
condition- the condition to wait for to become falsetimeoutInSeconds- the number of seconds to wait
-
waitForElementPresent
protected void waitForElementPresent(org.openqa.selenium.By by) -
waitForElementNotPresent
protected void waitForElementNotPresent(org.openqa.selenium.By by) -
waitForElementVisible
protected void waitForElementVisible(org.openqa.selenium.By by) -
hasCssClass
Checks if the given element has the given class name. Matches only full class names, i.e. has ("foo") does not match class="foobar"- Parameters:
element- the element to testclassName- the class names to match- Returns:
trueif matches,falseif not
-
assertEquals
protected static void assertEquals(org.openqa.selenium.WebElement expectedElement, org.openqa.selenium.WebElement actualElement) Assert that the two elements are equal.Can be removed if https://dev.vaadin.com/ticket/18484 is fixed.
- Parameters:
expectedElement- the expected elementactualElement- the actual element
-
executeScript
Executes the given JavaScript.To send arguments to the script, you can use the
argumentsvariable.
For example:executeScript("window.alert(arguments[0]);", "Alert message!");.To be able to use the return value of the JavaScript, you must explicitly declare a
returnstatement.
For example:executeScript("return window.name;");.- Overrides:
executeScriptin classcom.vaadin.testbench.TestBenchTestCase- Parameters:
script- the script to executeargs- optional arguments for the script- Returns:
- whatever
JavascriptExecutor.executeScript(String, Object...)returns
-
scrollBy
protected void scrollBy(int deltaX, int deltaY) Scrolls the page by given amount of x and y deltas. Actual scroll values can be different if any delta is bigger then the corresponding document dimension.- Parameters:
deltaX- the offset in pixels to scroll horizontallydeltaY- the offset in pixels to scroll vertically
-
scrollToElement
protected void scrollToElement(org.openqa.selenium.WebElement element) Scrolls the page to the element given using javascript. Standard Selenium api does not work for current newest Chrome and ChromeDriver.- Parameters:
element- the element to scroll to, notnull
-
scrollIntoViewAndClick
protected void scrollIntoViewAndClick(org.openqa.selenium.WebElement element) Scrolls the page to the element specified and clicks it.- Parameters:
element- the element to scroll to and click
-
getScrollX
protected int getScrollX()Gets current scroll position on x axis.- Returns:
- current scroll position on x axis.
-
getScrollY
protected int getScrollY()Gets current scroll position on y axis.- Returns:
- current scroll position on y axis.
-
clickElementWithJs
Clicks on the element, using JS. This method is more convenient then SeleniumfindElement(By.id(urlId)).click(), because Selenium method changes scroll position, which is not always needed.- Parameters:
elementId- id of the
-
clickElementWithJs
protected void clickElementWithJs(org.openqa.selenium.WebElement element) Clicks on the element, using JS. This method is more convenient then Seleniumelement.click(), because Selenium method changes scroll position, which is not always needed.- Parameters:
element- the element to be clicked on
-
getLogEntries
Gets the log entries from the browser that have the given logging level or higher.- Parameters:
level- the minimum severity of logs included- Returns:
- log entries from the browser
-
checkLogsForErrors
Checks browser's log entries, throws an error for any client-side error and logs any client-side warnings.- Parameters:
acceptableMessagePredicate- allows to ignore log entries whose message is accaptable- Throws:
AssertionError- if an error is found in the browser logs
-
checkLogsForErrors
protected void checkLogsForErrors()Checks browser's log entries, throws an error for any client-side error and logs any client-side warnings.- Throws:
AssertionError- if an error is found in the browser logs
-
waitForDevServer
protected void waitForDevServer()If dev server start in progress wait until it's started. Otherwise return immidiately. -
blur
public void blur()Calls theblur()function on the current active element of the page, if any.
-