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.internal.WrapsElement, org.openqa.selenium.SearchContext, org.openqa.selenium.TakesScreenshot, org.openqa.selenium.WebElement
Direct Known Subclasses:
AnchorElement, AppLayoutElement, BoardElement, ButtonElement, ChartElement, CheckboxElement, ComboBoxElement, ConfirmDialogElement, CookieConsentElement, CrudElement, DatePickerElement, DescriptionListElement, DialogElement, DivElement, EmphasisElement, FormLayoutElement, GridElement, GridTHTDElement, GridTRElement, H1Element, H2Element, H3Element, H4Element, H5Element, H6Element, HorizontalLayoutElement, HrElement, ImageElement, InputTextElement, IronListElement, LabelElement, ListItemElement, MenuItemElement, NativeButtonElement, NotificationElement, OrderedListElement, ParagraphElement, PasswordFieldElement, ProgressBarElement, RadioButtonElement, RadioButtonGroupElement, RowElement, SelectElement, SpanElement, SplitLayoutElement, TabElement, TabsElement, TextAreaElement, TextFieldElement, UnorderedListElement, UploadElement, VerticalLayoutElement
public class TestBenchElement extends Object implements org.openqa.selenium.internal.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
Constructors Modifier Constructor and Description protected
TestBenchElement()
protected
TestBenchElement(org.openqa.selenium.WebElement webElement, TestBenchCommandExecutor commandExecutor)
-
Method Summary
All Methods Modifier and Type Method and Description Object
callFunction(String methodName, Object... args)
Invoke the given method on this element using the given arguments as arguments to the method.
void
clear()
void
click()
void
click(int x, int y, org.openqa.selenium.Keys... modifiers)
boolean
compareScreen(BufferedImage reference, String referenceName)
Tests that a screen shot is equal to the specified reference image.
boolean
compareScreen(File reference)
Tests that a screen shot is equal to the specified reference image.
boolean
compareScreen(String referenceId)
Tests that a screen shot is equal to the specified reference image.
void
contextClick()
void
dispatchEvent(String eventType)
Dispatches (fires) a custom event of the given type on the element.
void
doubleClick()
boolean
equals(Object obj)
protected Object
executeScript(String script, Object... args)
Executes the given JavaScript in the context of the currently selected frame or window.
TestBenchElement
findElement(org.openqa.selenium.By by)
List<org.openqa.selenium.WebElement>
findElements(org.openqa.selenium.By by)
void
focus()
Move browser focus to this Element
String
getAttribute(String name)
protected org.openqa.selenium.Capabilities
getCapabilities()
Returns information about current browser used
Set<String>
getClassNames()
Gets all the class names set for this element.
TestBenchCommandExecutor
getCommandExecutor()
Return a reference to the related
TestBenchCommandExecutor
instance.org.openqa.selenium.SearchContext
getContext()
Returns this TestBenchElement cast to a SearchContext.
String
getCssValue(String propertyName)
org.openqa.selenium.WebDriver
getDriver()
Return the
WebDriver
instance associated with the implementing class instance.org.openqa.selenium.Point
getLocation()
Object
getProperty(String... propertyNames)
Gets a JavaScript property of the given element.
Boolean
getPropertyBoolean(String... propertyNames)
Gets a JavaScript property of the given element as a boolean.
Double
getPropertyDouble(String... propertyNames)
Gets a JavaScript property of the given element as a double.
TestBenchElement
getPropertyElement(String... propertyNames)
Gets a JavaScript property of the given element as a DOM element.
List<TestBenchElement>
getPropertyElements(String... propertyNames)
Gets a JavaScript property of the given element as a list of DOM elements.
Integer
getPropertyInteger(String... propertyNames)
Gets a JavaScript property of the given element as an integer.
String
getPropertyString(String... propertyNames)
Gets a JavaScript property of the given element as a string.
org.openqa.selenium.Rectangle
getRect()
<X> X
getScreenshotAs(org.openqa.selenium.OutputType<X> target)
org.openqa.selenium.Dimension
getSize()
String
getTagName()
String
getText()
org.openqa.selenium.WebElement
getWrappedElement()
boolean
hasAttribute(String attribute)
Checks if the given attribute is present on the element.
boolean
hasClassName(String className)
Checks if this element has the given class name.
int
hashCode()
protected void
init()
This is run after initializing a TestBenchElement.
protected void
init(org.openqa.selenium.WebElement element, TestBenchCommandExecutor commandExecutor)
TestBenchElement initialization function.
protected boolean
isChrome()
Checks if the current test is running on Chrome.
boolean
isDisplayed()
boolean
isEnabled()
Returns whether the Vaadin component, that this element represents, is enabled or not.
protected boolean
isFirefox()
Checks if the current test is running on Firefox.
protected boolean
isIE()
Checks if the current test is running on Internet Explorer.
boolean
isSelected()
void
scroll(int scrollTop)
Sets the number of pixels that an element's content is scrolled from the top.
void
scrollIntoView()
Scrolls the element into the visible area of the browser window
void
scrollLeft(int scrollLeft)
Sets the number of pixels that an element's content is scrolled to the left.
void
sendKeys(CharSequence... keysToSend)
void
setProperty(String name, Boolean value)
Sets a JavaScript property of the given element.
void
setProperty(String name, Double value)
Sets a JavaScript property of the given element.
void
setProperty(String name, Integer value)
Sets a JavaScript property of the given element.
void
setProperty(String name, String value)
Sets a JavaScript property of the given element.
void
submit()
protected void
waitForVaadin()
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>
Twrap(Class<T> elementType)
protected static TestBenchElement
wrapElement(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, wait
-
Methods inherited from interface com.vaadin.testbench.HasElementQuery
$, $
-
-
-
-
Constructor Detail
-
TestBenchElement
protected TestBenchElement()
-
TestBenchElement
protected TestBenchElement(org.openqa.selenium.WebElement webElement, TestBenchCommandExecutor commandExecutor)
-
-
Method Detail
-
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 override
init()
, not this function.Parameters:
element
- WebElement to wrapcommandExecutor
- TestBenchCommandExecutor instance
-
isChrome
protected boolean isChrome()
Checks if the current test is running on Chrome.
Returns:
true
if the test is running on Chrome,false
otherwise
-
isIE
protected boolean isIE()
Checks if the current test is running on Internet Explorer.
Returns:
true
if the test is running on Internet Explorer,false
otherwise
-
isFirefox
protected boolean isFirefox()
Checks if the current test is running on Firefox.
Returns:
true
if the test is running on Firefox,false
otherwise
-
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:
getWrappedElement
in interfaceorg.openqa.selenium.internal.WrapsElement
-
waitForVaadin
protected void waitForVaadin()
-
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
-
click
public void click()
Specified by:
click
in interfaceorg.openqa.selenium.WebElement
-
submit
public void submit()
Specified by:
submit
in interfaceorg.openqa.selenium.WebElement
-
sendKeys
public void sendKeys(CharSequence... keysToSend)
Specified by:
sendKeys
in interfaceorg.openqa.selenium.WebElement
-
clear
public void clear()
Specified by:
clear
in interfaceorg.openqa.selenium.WebElement
-
getTagName
public String getTagName()
Specified by:
getTagName
in interfaceorg.openqa.selenium.WebElement
-
getAttribute
public String getAttribute(String name)
Specified by:
getAttribute
in interfaceorg.openqa.selenium.WebElement
-
hasAttribute
public boolean hasAttribute(String attribute)
Checks if the given attribute is present on the element.
Parameters:
attribute
- the name of the attributeReturns:
true
if the attribute is present,false
otherwise
-
isSelected
public boolean isSelected()
Specified by:
isSelected
in interfaceorg.openqa.selenium.WebElement
-
isEnabled
public boolean isEnabled()
Returns whether the Vaadin component, that this element represents, is enabled or not.
Specified by:
isEnabled
in interfaceorg.openqa.selenium.WebElement
Returns:
true if the component is enabled.
-
getText
public String getText()
Specified by:
getText
in interfaceorg.openqa.selenium.WebElement
-
findElements
public List<org.openqa.selenium.WebElement> findElements(org.openqa.selenium.By by)
Specified by:
findElements
in interfaceorg.openqa.selenium.SearchContext
Specified by:
findElements
in interfaceorg.openqa.selenium.WebElement
-
findElement
public TestBenchElement findElement(org.openqa.selenium.By by)
Specified by:
findElement
in interfaceorg.openqa.selenium.SearchContext
Specified by:
findElement
in interfaceorg.openqa.selenium.WebElement
-
isDisplayed
public boolean isDisplayed()
Specified by:
isDisplayed
in interfaceorg.openqa.selenium.WebElement
-
getLocation
public org.openqa.selenium.Point getLocation()
Specified by:
getLocation
in interfaceorg.openqa.selenium.WebElement
-
getSize
public org.openqa.selenium.Dimension getSize()
Specified by:
getSize
in interfaceorg.openqa.selenium.WebElement
-
getCssValue
public String getCssValue(String propertyName)
Specified by:
getCssValue
in 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
public <T extends TestBenchElement> T wrap(Class<T> elementType)
-
getCommandExecutor
public TestBenchCommandExecutor getCommandExecutor()
Description copied from interface:
HasTestBenchCommandExecutor
Return a reference to the related
TestBenchCommandExecutor
instance.Specified by:
getCommandExecutor
in interfaceHasTestBenchCommandExecutor
Returns:
-
getDriver
public org.openqa.selenium.WebDriver getDriver()
Description copied from interface:
HasDriver
Return the
WebDriver
instance 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:
getContext
in interfaceHasSearchContext
Returns:
a
SearchContext
instance
-
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:
getScreenshotAs
in interfaceorg.openqa.selenium.TakesScreenshot
Throws:
org.openqa.selenium.WebDriverException
-
getRect
public org.openqa.selenium.Rectangle getRect()
Specified by:
getRect
in interfaceorg.openqa.selenium.WebElement
-
getClassNames
public Set<String> getClassNames()
Gets all the class names set for this element.
Returns:
a set of class names
-
hasClassName
public boolean hasClassName(String className)
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 forReturns:
true
if the element has the given class name,false
otherwise
-
compareScreen
public boolean compareScreen(String referenceId) throws IOException
Description copied from interface:
CanCompareScreenshots
Tests 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:
compareScreen
in interfaceCanCompareScreenshots
Parameters:
referenceId
- the ID of the reference imageReturns:
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
public boolean compareScreen(File reference) throws IOException
Description copied from interface:
CanCompareScreenshots
Tests 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:
compareScreen
in interfaceCanCompareScreenshots
Parameters:
reference
- the reference image fileReturns:
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
public boolean compareScreen(BufferedImage reference, String referenceName) throws IOException
Description copied from interface:
CanCompareScreenshots
Tests 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:
compareScreen
in 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.
NotFoundException
s 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.
NotFoundException
s 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
-
setProperty
public void setProperty(String name, String value)
Description copied from interface:
HasPropertySettersGetters
Sets a JavaScript property of the given element.
Specified by:
setProperty
in interfaceHasPropertySettersGetters
Parameters:
name
- the name of the propertyvalue
- the value to set
-
setProperty
public void setProperty(String name, Boolean value)
Description copied from interface:
HasPropertySettersGetters
Sets a JavaScript property of the given element.
Specified by:
setProperty
in interfaceHasPropertySettersGetters
Parameters:
name
- the name of the propertyvalue
- the value to set
-
setProperty
public void setProperty(String name, Double value)
Description copied from interface:
HasPropertySettersGetters
Sets a JavaScript property of the given element.
Specified by:
setProperty
in interfaceHasPropertySettersGetters
Parameters:
name
- the name of the propertyvalue
- the value to set
-
setProperty
public void setProperty(String name, Integer value)
Description copied from interface:
HasPropertySettersGetters
Sets a JavaScript property of the given element.
Specified by:
setProperty
in interfaceHasPropertySettersGetters
Parameters:
name
- the name of the propertyvalue
- the value to set
-
getPropertyString
public String getPropertyString(String... propertyNames)
Description copied from interface:
HasPropertySettersGetters
Gets a JavaScript property of the given element as a string.
Specified by:
getPropertyString
in interfaceHasPropertySettersGetters
Parameters:
propertyNames
- the name of on or more properties, forming a property chain of typeproperty1.property2.property3
-
getPropertyBoolean
public Boolean getPropertyBoolean(String... propertyNames)
Description copied from interface:
HasPropertySettersGetters
Gets a JavaScript property of the given element as a boolean.
Specified by:
getPropertyBoolean
in interfaceHasPropertySettersGetters
Parameters:
propertyNames
- the name of on or more properties, forming a property chain of typeproperty1.property2.property3
-
getPropertyElement
public TestBenchElement getPropertyElement(String... propertyNames)
Description copied from interface:
HasPropertySettersGetters
Gets a JavaScript property of the given element as a DOM element.
Specified by:
getPropertyElement
in interfaceHasPropertySettersGetters
Parameters:
propertyNames
- the name of on or more properties, forming a property chain of typeproperty1.property2.property3
-
getPropertyElements
public List<TestBenchElement> getPropertyElements(String... propertyNames)
Description copied from interface:
HasPropertySettersGetters
Gets a JavaScript property of the given element as a list of DOM elements.
Specified by:
getPropertyElements
in interfaceHasPropertySettersGetters
Parameters:
propertyNames
- the name of on or more properties, forming a property chain of typeproperty1.property2.property3
-
getPropertyDouble
public Double getPropertyDouble(String... propertyNames)
Description copied from interface:
HasPropertySettersGetters
Gets a JavaScript property of the given element as a double.
Specified by:
getPropertyDouble
in interfaceHasPropertySettersGetters
Parameters:
propertyNames
- the name of on or more properties, forming a property chain of typeproperty1.property2.property3
-
getPropertyInteger
public Integer getPropertyInteger(String... propertyNames)
Description copied from interface:
HasPropertySettersGetters
Gets a JavaScript property of the given element as an integer.
Specified by:
getPropertyInteger
in interfaceHasPropertySettersGetters
Parameters:
propertyNames
- the name of on or more properties, forming a property chain of typeproperty1.property2.property3
-
getProperty
public Object getProperty(String... propertyNames)
Description copied from interface:
HasPropertySettersGetters
Gets a JavaScript property of the given element.
The return value needs to be cast manually to the correct type.
Specified by:
getProperty
in interfaceHasPropertySettersGetters
Parameters:
propertyNames
- the name of on or more properties, forming a property chain of typeproperty1.property2.property3
-
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
WebElement
asTestBenchElement
.Parameters:
script
- the script to executeargs
- the arguments, available in the script asarguments[0]...arguments[N]
Returns:
whatever
JavascriptExecutor.executeScript(String, Object...)
returnsThrows:
UnsupportedOperationException
- if the underlying driver does not support JavaScript executionSee Also:
JavascriptExecutor.executeScript(String, Object...)
-
callFunction
public Object callFunction(String methodName, Object... args)
Description copied from interface:
HasCallFunction
Invoke the given method on this element using the given arguments as arguments to the method.
Specified by:
callFunction
in interfaceHasCallFunction
Parameters:
methodName
- the method to invokeargs
- the arguments to pass to the methodReturns:
the value returned by the method
-
dispatchEvent
public void dispatchEvent(String eventType)
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
-
-