Package com.vaadin.testbench
Class TestBenchElement
java.lang.Object
com.vaadin.testbench.TestBenchElement
- All Implemented Interfaces:
CanCompareScreenshots,HasCallFunction,HasDriver,HasElementQuery,HasPropertySettersGetters,HasSearchContext,HasTestBenchCommandExecutor,org.openqa.selenium.SearchContext,org.openqa.selenium.TakesScreenshot,org.openqa.selenium.WebElement,org.openqa.selenium.WrapsElement
- Direct Known Subclasses:
AccordionElement,AnchorElement,AppLayoutElement,AvatarElement,AvatarGroupElement,BigDecimalFieldElement,BoardElement,ButtonElement,CardElement,ChartElement,CheckboxElement,CheckboxGroupElement,ComboBoxElement,ConfirmDialogElement,ContextMenuElement,ContextMenuItemElement,ContextMenuOverlayElement,CookieConsentElement,CrudElement,CustomFieldElement,DashboardElement,DashboardSectionElement,DashboardWidgetElement,DatePickerElement,DatePickerElement.MonthCalendarElement,DatePickerElement.OverlayContentElement,DatePickerElement.WeekdayElement,DateTimePickerElement,DescriptionListElement,DetailsElement,DialogElement,DivElement,DrawerToggleElement,EmailFieldElement,EmphasisElement,FormItemElement,FormLayoutElement,GridElement,GridProElement,GridTHTDElement,GridTHTDElement,GridTRElement,GridTRElement,H1Element,H2Element,H3Element,H4Element,H5Element,H6Element,HorizontalLayoutElement,HrElement,IconElement,ImageElement,InputTextElement,IntegerFieldElement,LabelElement,ListBoxElement,ListItemElement,LoginFormElement,LoginOverlayElement,MarkdownElement,MasterDetailLayoutElement,MenuBarButtonElement,MenuBarElement,MenuBarItemElement,MessageElement,MessageInputElement,MessageListElement,MultiSelectComboBoxElement,NativeButtonElement,NativeDetailsElement,NativeLabelElement,NativeTableBodyElement,NativeTableCaptionElement,NativeTableCellElement,NativeTableElement,NativeTableFooterElement,NativeTableHeaderCellElement,NativeTableHeaderElement,NativeTableRowElement,NotificationElement,NumberFieldElement,OrderedListElement,ParagraphElement,PasswordFieldElement,PopoverElement,PreElement,ProgressBarElement,RadioButtonElement,RadioButtonGroupElement,RangeInputElement,RichTextEditorElement,RowElement,ScrollerElement,SelectElement,SelectElement,SelectElement.ItemElement,SideNavElement,SideNavItemElement,SpanElement,SplitLayoutElement,TabElement,TabsElement,TabSheetElement,TextAreaElement,TextFieldElement,TimePickerElement,TimePickerElement.TimePickerComboBoxElement,TimePickerElement.TimePickerOverlayElement,UnorderedListElement,UploadElement,VerticalLayoutElement,VirtualListElement
public class TestBenchElement
extends Object
implements org.openqa.selenium.WrapsElement, org.openqa.selenium.WebElement, HasDriver, CanCompareScreenshots, HasTestBenchCommandExecutor, HasElementQuery, HasPropertySettersGetters, HasCallFunction
TestBenchElement is a WebElement wrapper. It provides Vaadin specific helper
functionality. TestBenchElements are created when you search for elements
from TestBenchTestCase or a context relative search from TestBenchElement.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedTestBenchElement(org.openqa.selenium.WebElement webElement, TestBenchCommandExecutor commandExecutor) -
Method Summary
Modifier and TypeMethodDescriptioncallFunction(String methodName, Object... args) Invoke the given method on this element using the given arguments as arguments to the method.voidclear()voidclick()voidclick(int x, int y, org.openqa.selenium.Keys... modifiers) booleancompareScreen(BufferedImage reference, String referenceName) Tests that a screen shot is equal to the specified reference image.booleancompareScreen(File reference) Tests that a screen shot is equal to the specified reference image.booleancompareScreen(String referenceId) Tests that a screen shot is equal to the specified reference image.voidvoiddispatchEvent(String eventType) Dispatches (fires) a custom event of the given type on the element.voiddispatchEvent(String eventType, Map<String, Object> customEventInit) Dispatches (fires) a custom event of the given type on the element with the given propertiesvoidbooleanprotected ObjectexecuteScript(String script, Object... args) Executes the given JavaScript in the context of the currently selected frame or window.findElement(org.openqa.selenium.By by) List<org.openqa.selenium.WebElement>findElements(org.openqa.selenium.By by) voidfocus()Move browser focus to this ElementgetAttribute(String name) protected org.openqa.selenium.CapabilitiesReturns information about current browser usedGet list of immediate children of this element.Gets all the class names set for this element.Return a reference to the relatedTestBenchCommandExecutorinstance.org.openqa.selenium.SearchContextReturns this TestBenchElement cast to a SearchContext.getCssValue(String propertyName) @Nullable StringgetDomAttribute(String name) @Nullable StringgetDomProperty(String name) org.openqa.selenium.WebDriverReturn theWebDriverinstance associated with the implementing class instance.getId()Gets the id set for this element.org.openqa.selenium.PointGets the parent element of this element.getProperty(String... propertyNames) Gets a JavaScript property of the given element.getPropertyBoolean(String... propertyNames) Gets a JavaScript property of the given element as a boolean.getPropertyDouble(String... propertyNames) Gets a JavaScript property of the given element as a double.getPropertyElement(String... propertyNames) Gets a JavaScript property of the given element as a DOM element.getPropertyElements(String... propertyNames) Gets a JavaScript property of the given element as a list of DOM elements.getPropertyInteger(String... propertyNames) Gets a JavaScript property of the given element as an integer.getPropertyString(String... propertyNames) Gets a JavaScript property of the given element as a string.org.openqa.selenium.RectanglegetRect()<X> XgetScreenshotAs(org.openqa.selenium.OutputType<X> target) org.openqa.selenium.SearchContextDeprecated.This method is deprecated.org.openqa.selenium.DimensiongetSize()getText()org.openqa.selenium.WebElementbooleanhasAttribute(String attribute) Checks if the given attribute is present on the element.booleanhasClassName(String className) Checks if this element has the given class name.inthashCode()voidhover()Hover mouse pointer on this element.protected voidinit()This is run after initializing a TestBenchElement.protected voidinit(org.openqa.selenium.WebElement element, TestBenchCommandExecutor commandExecutor) TestBenchElement initialization function.protected booleanisChrome()Checks if the current test is running on Chrome.booleanbooleanReturns whether the Vaadin component, that this element represents, is enabled or not.protected booleanChecks if the current test is running on Firefox.booleanChecks if the current element is the focused element on the page.booleanReturns whether the Vaadin component, that this element represents, is having readonly attribute set or not.booleanvoidscroll(int scrollTop) Sets the number of pixels that an element's content is scrolled from the top.voidScrolls the element into the visible area of the browser windowvoidscrollLeft(int scrollLeft) Sets the number of pixels that an element's content is scrolled to the left.voidsendKeys(CharSequence... keysToSend) voidsetProperty(String name, Boolean value) Sets a JavaScript property of the given element.voidsetProperty(String name, Double value) Sets a JavaScript property of the given element.voidsetProperty(String name, Integer value) Sets a JavaScript property of the given element.voidsetProperty(String name, String value) Sets a JavaScript property of the given element.voidsubmit()protected voidprotected <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>
Tprotected static TestBenchElementwrapElement(org.openqa.selenium.WebElement element, TestBenchCommandExecutor commandExecutor) protected static List<TestBenchElement>wrapElements(List<org.openqa.selenium.WebElement> elements, TestBenchCommandExecutor commandExecutor) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.testbench.HasElementQuery
$, $Methods inherited from interface org.openqa.selenium.WebElement
getAccessibleName, getAriaRole
-
Constructor Details
-
TestBenchElement
protected TestBenchElement() -
TestBenchElement
protected TestBenchElement(org.openqa.selenium.WebElement webElement, TestBenchCommandExecutor commandExecutor)
-
-
Method Details
-
init
protected void init(org.openqa.selenium.WebElement element, TestBenchCommandExecutor commandExecutor) TestBenchElement initialization function. If a subclass of TestBenchElement needs to run some initialization code, it should overrideinit(), not this function.- Parameters:
element- WebElement to wrapcommandExecutor- TestBenchCommandExecutor instance
-
isChrome
protected boolean isChrome()Checks if the current test is running on Chrome.- Returns:
trueif the test is running on Chrome,falseotherwise
-
isFirefox
protected boolean isFirefox()Checks if the current test is running on Firefox.- Returns:
trueif the test is running on Firefox,falseotherwise
-
getCapabilities
protected org.openqa.selenium.Capabilities getCapabilities()Returns information about current browser used- Returns:
- information about current browser used
- See Also:
-
Capabilities
-
init
protected void init()This is run after initializing a TestBenchElement. This can be overridden in subclasses of TestBenchElement to run some initialization code. -
getWrappedElement
public org.openqa.selenium.WebElement getWrappedElement()- Specified by:
getWrappedElementin interfaceorg.openqa.selenium.WrapsElement
-
waitForVaadin
protected void waitForVaadin() -
getId
Gets the id set for this element.- Returns:
- String value, can be null
-
scroll
public void scroll(int scrollTop) Sets the number of pixels that an element's content is scrolled from the top.- Parameters:
scrollTop- value set to Element.scroll property
-
scrollLeft
public void scrollLeft(int scrollLeft) Sets the number of pixels that an element's content is scrolled to the left.- Parameters:
scrollLeft- value set to Element.scrollLeft property
-
isFocused
public boolean isFocused()Checks if the current element is the focused element on the page.- Returns:
trueif this element is the currently focused element,falseotherwise.
-
click
public void click()- Specified by:
clickin interfaceorg.openqa.selenium.WebElement
-
submit
public void submit()- Specified by:
submitin interfaceorg.openqa.selenium.WebElement
-
sendKeys
- Specified by:
sendKeysin interfaceorg.openqa.selenium.WebElement
-
clear
public void clear()- Specified by:
clearin interfaceorg.openqa.selenium.WebElement
-
getTagName
- Specified by:
getTagNamein interfaceorg.openqa.selenium.WebElement
-
getAttribute
- Specified by:
getAttributein interfaceorg.openqa.selenium.WebElement- Parameters:
name- The name of the attribute.- Returns:
- The attribute/ property's current value or null if the value is not set.
-
getDomAttribute
- Specified by:
getDomAttributein interfaceorg.openqa.selenium.WebElement
-
getDomProperty
- Specified by:
getDomPropertyin interfaceorg.openqa.selenium.WebElement
-
hasAttribute
Checks if the given attribute is present on the element.- Parameters:
attribute- the name of the attribute- Returns:
trueif the attribute is present,falseotherwise
-
isSelected
public boolean isSelected()- Specified by:
isSelectedin interfaceorg.openqa.selenium.WebElement
-
isEnabled
public boolean isEnabled()Returns whether the Vaadin component, that this element represents, is enabled or not.- Specified by:
isEnabledin interfaceorg.openqa.selenium.WebElement- Returns:
- true if the component is enabled.
-
isReadOnly
public boolean isReadOnly()Returns whether the Vaadin component, that this element represents, is having readonly attribute set or not.- Returns:
- true if the component has readonly attribute set.
-
getText
- Specified by:
getTextin interfaceorg.openqa.selenium.WebElement
-
findElements
- Specified by:
findElementsin interfaceorg.openqa.selenium.SearchContext- Specified by:
findElementsin interfaceorg.openqa.selenium.WebElement
-
findElement
- Specified by:
findElementin interfaceorg.openqa.selenium.SearchContext- Specified by:
findElementin interfaceorg.openqa.selenium.WebElement
-
isDisplayed
public boolean isDisplayed()- Specified by:
isDisplayedin interfaceorg.openqa.selenium.WebElement
-
getLocation
public org.openqa.selenium.Point getLocation()- Specified by:
getLocationin interfaceorg.openqa.selenium.WebElement
-
getSize
public org.openqa.selenium.Dimension getSize()- Specified by:
getSizein interfaceorg.openqa.selenium.WebElement
-
getCssValue
- Specified by:
getCssValuein interfaceorg.openqa.selenium.WebElement
-
click
public void click(int x, int y, org.openqa.selenium.Keys... modifiers) -
doubleClick
public void doubleClick() -
contextClick
public void contextClick() -
wrap
-
getCommandExecutor
Description copied from interface:HasTestBenchCommandExecutorReturn a reference to the relatedTestBenchCommandExecutorinstance.- Specified by:
getCommandExecutorin interfaceHasTestBenchCommandExecutor- Returns:
- the
TestBenchCommandExecutorinstance
-
getDriver
public org.openqa.selenium.WebDriver getDriver()Description copied from interface:HasDriverReturn theWebDriverinstance associated with the implementing class instance. This can be simply the class itself re-cast as a WebDriver, or a reference to some WebDriver obtainable by any other means. -
getContext
public org.openqa.selenium.SearchContext getContext()Returns this TestBenchElement cast to a SearchContext. Method provided for compatibility and consistency.- Specified by:
getContextin interfaceHasSearchContext- Returns:
- a
SearchContextinstance
-
focus
public void focus()Move browser focus to this Element -
wrapElements
protected static List<TestBenchElement> wrapElements(List<org.openqa.selenium.WebElement> elements, TestBenchCommandExecutor commandExecutor) -
wrapElement
protected static TestBenchElement wrapElement(org.openqa.selenium.WebElement element, TestBenchCommandExecutor commandExecutor) -
getScreenshotAs
public <X> X getScreenshotAs(org.openqa.selenium.OutputType<X> target) throws org.openqa.selenium.WebDriverException - Specified by:
getScreenshotAsin interfaceorg.openqa.selenium.TakesScreenshot- Throws:
org.openqa.selenium.WebDriverException
-
getRect
public org.openqa.selenium.Rectangle getRect()- Specified by:
getRectin interfaceorg.openqa.selenium.WebElement
-
getClassNames
Gets all the class names set for this element.- Returns:
- a set of class names
-
hasClassName
Checks if this element has the given class name.Matches only full class names, i.e. has ("foo") does not match class="foobar bafoo"
- Parameters:
className- the class name to check for- Returns:
trueif the element has the given class name,falseotherwise
-
equals
-
hashCode
public int hashCode() -
compareScreen
Description copied from interface:CanCompareScreenshotsTests that a screen shot is equal to the specified reference image. The comparison tolerance can be specified by setting the com.vaadin.testbench.block.error system property to a value between 0 and 1, where 0 == no changes are accepted and 1 == big changes are accepted. Note that specifying 1 doesn't mean that any reference image is accepted.- Specified by:
compareScreenin interfaceCanCompareScreenshots- Parameters:
referenceId- the ID of the reference image- Returns:
- true if the screenshot is considered equal to the reference image, false otherwise.
- Throws:
IOException- if there was a problem accessing the reference image
-
compareScreen
Description copied from interface:CanCompareScreenshotsTests that a screen shot is equal to the specified reference image. The comparison tolerance can be specified by setting the com.vaadin.testbench.block.error system property to a value between 0 and 1, where 0 == no changes are accepted and 1 == all changes are accepted.- Specified by:
compareScreenin interfaceCanCompareScreenshots- Parameters:
reference- the reference image file- Returns:
- true if the screenshot is considered equal to the reference image, false otherwise.
- Throws:
IOException- if there was a problem accessing the reference image
-
compareScreen
Description copied from interface:CanCompareScreenshotsTests that a screen shot is equal to the specified reference image. The comparison tolerance can be specified by setting the com.vaadin.testbench.block.error system property to a value between 0 and 1, where 0 == no changes are accepted and 1 == all changes are accepted.- Specified by:
compareScreenin interfaceCanCompareScreenshots- Parameters:
reference- the reference imagereferenceName- the filename of the reference image. Used when writing the error files.- Returns:
- true if the screenshot is considered equal to the reference image, false otherwise.
- Throws:
IOException- if there was a problem accessing the reference image
-
scrollIntoView
public void scrollIntoView()Scrolls the element into the visible area of the browser window -
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
-
setProperty
Description copied from interface:HasPropertySettersGettersSets a JavaScript property of the given element.- Specified by:
setPropertyin interfaceHasPropertySettersGetters- Parameters:
name- the name of the propertyvalue- the value to set
-
setProperty
Description copied from interface:HasPropertySettersGettersSets a JavaScript property of the given element.- Specified by:
setPropertyin interfaceHasPropertySettersGetters- Parameters:
name- the name of the propertyvalue- the value to set
-
setProperty
Description copied from interface:HasPropertySettersGettersSets a JavaScript property of the given element.- Specified by:
setPropertyin interfaceHasPropertySettersGetters- Parameters:
name- the name of the propertyvalue- the value to set
-
setProperty
Description copied from interface:HasPropertySettersGettersSets a JavaScript property of the given element.- Specified by:
setPropertyin interfaceHasPropertySettersGetters- Parameters:
name- the name of the propertyvalue- the value to set
-
getPropertyString
Description copied from interface:HasPropertySettersGettersGets a JavaScript property of the given element as a string.- Specified by:
getPropertyStringin interfaceHasPropertySettersGetters- Parameters:
propertyNames- the name of on or more properties, forming a property chain of typeproperty1.property2.property3- Returns:
- the value of the property
-
getPropertyBoolean
Description copied from interface:HasPropertySettersGettersGets a JavaScript property of the given element as a boolean.- Specified by:
getPropertyBooleanin interfaceHasPropertySettersGetters- Parameters:
propertyNames- the name of on or more properties, forming a property chain of typeproperty1.property2.property3- Returns:
- the value of the property
-
getPropertyElement
Description copied from interface:HasPropertySettersGettersGets a JavaScript property of the given element as a DOM element.- Specified by:
getPropertyElementin interfaceHasPropertySettersGetters- Parameters:
propertyNames- the name of on or more properties, forming a property chain of typeproperty1.property2.property3- Returns:
- the value of the property
-
getPropertyElements
Description copied from interface:HasPropertySettersGettersGets a JavaScript property of the given element as a list of DOM elements.- Specified by:
getPropertyElementsin interfaceHasPropertySettersGetters- Parameters:
propertyNames- the name of on or more properties, forming a property chain of typeproperty1.property2.property3- Returns:
- the value of the property
-
getPropertyDouble
Description copied from interface:HasPropertySettersGettersGets a JavaScript property of the given element as a double.- Specified by:
getPropertyDoublein interfaceHasPropertySettersGetters- Parameters:
propertyNames- the name of on or more properties, forming a property chain of typeproperty1.property2.property3- Returns:
- the value of the property
-
getPropertyInteger
Description copied from interface:HasPropertySettersGettersGets a JavaScript property of the given element as an integer.- Specified by:
getPropertyIntegerin interfaceHasPropertySettersGetters- Parameters:
propertyNames- the name of on or more properties, forming a property chain of typeproperty1.property2.property3- Returns:
- the value of the property
-
getProperty
Description copied from interface:HasPropertySettersGettersGets a JavaScript property of the given element.The return value needs to be cast manually to the correct type.
- Specified by:
getPropertyin interfaceHasPropertySettersGetters- Parameters:
propertyNames- the name of on or more properties, forming a property chain of typeproperty1.property2.property3- Returns:
- the value of the property
-
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...)
-
callFunction
Description copied from interface:HasCallFunctionInvoke the given method on this element using the given arguments as arguments to the method.- Specified by:
callFunctionin interfaceHasCallFunction- Parameters:
methodName- the method to invokeargs- the arguments to pass to the method- Returns:
- the value returned by the method
-
dispatchEvent
Dispatches (fires) a custom event of the given type on the element.The event is created without any parameters.
- Parameters:
eventType- the type of custom event to dispatch
-
dispatchEvent
Dispatches (fires) a custom event of the given type on the element with the given properties- Parameters:
eventType- the type of custom event to dispatchcustomEventInit- map with properties and values that will be used to initialize the event
-
getParent
Gets the parent element of this element.- Returns:
- The parent as TestBenchElement, can be null.
-
getShadowRoot
Deprecated.This method is deprecated. Use$instead to find elements in the shadow root.Not implemented. This method is not supported for theTestBenchElement. Use$instead to find elements in the shadow root. Example usage:TestBenchElement element = ...; TestBenchElement child = element.$(TestBenchElement.class).id("elementid");- Specified by:
getShadowRootin interfaceorg.openqa.selenium.WebElement- Returns:
- the
SearchContextrepresenting the shadow root.
-
getChildren
Get list of immediate children of this element.- Returns:
- List of TestBenchElements
-
hover
public void hover()Hover mouse pointer on this element. Note: This works well only if this element is atomic.
-