public class TestBenchElement extends Object implements org.openqa.selenium.internal.WrapsElement, org.openqa.selenium.WebElement, HasDriver, CanCompareScreenshots, HasTestBenchCommandExecutor, HasElementQuery, HasPropertySettersGetters, HasCallFunction
Modifier | Constructor and Description |
---|---|
protected |
TestBenchElement() |
protected |
TestBenchElement(org.openqa.selenium.WebElement webElement,
TestBenchCommandExecutor commandExecutor) |
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> |
wrap(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) |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
$, $
protected TestBenchElement()
protected TestBenchElement(org.openqa.selenium.WebElement webElement, TestBenchCommandExecutor commandExecutor)
protected void init(org.openqa.selenium.WebElement element, TestBenchCommandExecutor commandExecutor)
init()
, not this function.element
- WebElement to wrapcommandExecutor
- TestBenchCommandExecutor instanceprotected boolean isChrome()
true
if the test is running on Chrome,
false
otherwiseprotected boolean isIE()
true
if the test is running on Internet Explorer,
false
otherwiseprotected boolean isFirefox()
true
if the test is running on Firefox,
false
otherwiseprotected org.openqa.selenium.Capabilities getCapabilities()
Capabilities
protected void init()
public org.openqa.selenium.WebElement getWrappedElement()
getWrappedElement
in interface org.openqa.selenium.internal.WrapsElement
protected void waitForVaadin()
public void scroll(int scrollTop)
scrollTop
- value set to Element.scroll propertypublic void scrollLeft(int scrollLeft)
scrollLeft
- value set to Element.scrollLeft propertypublic void click()
click
in interface org.openqa.selenium.WebElement
public void submit()
submit
in interface org.openqa.selenium.WebElement
public void sendKeys(CharSequence... keysToSend)
sendKeys
in interface org.openqa.selenium.WebElement
public void clear()
clear
in interface org.openqa.selenium.WebElement
public String getTagName()
getTagName
in interface org.openqa.selenium.WebElement
public String getAttribute(String name)
getAttribute
in interface org.openqa.selenium.WebElement
public boolean hasAttribute(String attribute)
attribute
- the name of the attributetrue
if the attribute is present, false
otherwisepublic boolean isSelected()
isSelected
in interface org.openqa.selenium.WebElement
public boolean isEnabled()
isEnabled
in interface org.openqa.selenium.WebElement
public String getText()
getText
in interface org.openqa.selenium.WebElement
public List<org.openqa.selenium.WebElement> findElements(org.openqa.selenium.By by)
findElements
in interface org.openqa.selenium.SearchContext
findElements
in interface org.openqa.selenium.WebElement
public TestBenchElement findElement(org.openqa.selenium.By by)
findElement
in interface org.openqa.selenium.SearchContext
findElement
in interface org.openqa.selenium.WebElement
public boolean isDisplayed()
isDisplayed
in interface org.openqa.selenium.WebElement
public org.openqa.selenium.Point getLocation()
getLocation
in interface org.openqa.selenium.WebElement
public org.openqa.selenium.Dimension getSize()
getSize
in interface org.openqa.selenium.WebElement
public String getCssValue(String propertyName)
getCssValue
in interface org.openqa.selenium.WebElement
public void click(int x, int y, org.openqa.selenium.Keys... modifiers)
public void doubleClick()
public void contextClick()
public <T extends TestBenchElement> T wrap(Class<T> elementType)
public TestBenchCommandExecutor getCommandExecutor()
HasTestBenchCommandExecutor
TestBenchCommandExecutor
instance.getCommandExecutor
in interface HasTestBenchCommandExecutor
public org.openqa.selenium.WebDriver getDriver()
HasDriver
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.public org.openqa.selenium.SearchContext getContext()
getContext
in interface HasSearchContext
SearchContext
instancepublic void focus()
protected static List<TestBenchElement> wrapElements(List<org.openqa.selenium.WebElement> elements, TestBenchCommandExecutor commandExecutor)
protected static TestBenchElement wrapElement(org.openqa.selenium.WebElement element, TestBenchCommandExecutor commandExecutor)
public <X> X getScreenshotAs(org.openqa.selenium.OutputType<X> target) throws org.openqa.selenium.WebDriverException
getScreenshotAs
in interface org.openqa.selenium.TakesScreenshot
org.openqa.selenium.WebDriverException
public org.openqa.selenium.Rectangle getRect()
getRect
in interface org.openqa.selenium.WebElement
public Set<String> getClassNames()
public boolean hasClassName(String className)
Matches only full class names, i.e. has ("foo") does not match class="foobar bafoo"
className
- the class name to check fortrue
if the element has the given class name,
false
otherwisepublic boolean compareScreen(String referenceId) throws IOException
CanCompareScreenshots
compareScreen
in interface CanCompareScreenshots
referenceId
- the ID of the reference imageIOException
- if there was a problem accessing the reference imagepublic boolean compareScreen(File reference) throws IOException
CanCompareScreenshots
compareScreen
in interface CanCompareScreenshots
reference
- the reference image fileIOException
- if there was a problem accessing the reference imagepublic boolean compareScreen(BufferedImage reference, String referenceName) throws IOException
CanCompareScreenshots
compareScreen
in interface CanCompareScreenshots
reference
- the reference imagereferenceName
- the filename of the reference image. Used when writing the
error files.IOException
- if there was a problem accessing the reference imagepublic void scrollIntoView()
protected <T> T waitUntil(org.openqa.selenium.support.ui.ExpectedCondition<T> condition, long timeoutInSeconds)
NotFoundException
s are ignored by
default.
Use e.g. as
waitUntil(ExpectedConditions.presenceOfElementLocated(by), 10);
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.org.openqa.selenium.TimeoutException
- If the timeout expires.FluentWait.until(java.util.function.Function<? super T, V>)
,
ExpectedCondition
protected <T> T waitUntil(org.openqa.selenium.support.ui.ExpectedCondition<T> condition)
NotFoundException
s are ignored by default.
Use e.g. as
waitUntil(ExpectedConditions.presenceOfElementLocated(by));
condition
- Models a condition that might reasonably be expected to
eventually evaluate to something that is neither null nor
false.org.openqa.selenium.TimeoutException
- If 10 seconds passed.FluentWait.until(java.util.function.Function<? super T, V>)
,
ExpectedCondition
public void setProperty(String name, String value)
HasPropertySettersGetters
setProperty
in interface HasPropertySettersGetters
name
- the name of the propertyvalue
- the value to setpublic void setProperty(String name, Boolean value)
HasPropertySettersGetters
setProperty
in interface HasPropertySettersGetters
name
- the name of the propertyvalue
- the value to setpublic void setProperty(String name, Double value)
HasPropertySettersGetters
setProperty
in interface HasPropertySettersGetters
name
- the name of the propertyvalue
- the value to setpublic void setProperty(String name, Integer value)
HasPropertySettersGetters
setProperty
in interface HasPropertySettersGetters
name
- the name of the propertyvalue
- the value to setpublic String getPropertyString(String... propertyNames)
HasPropertySettersGetters
getPropertyString
in interface HasPropertySettersGetters
propertyNames
- the name of on or more properties, forming a property chain of
type property1.property2.property3
public Boolean getPropertyBoolean(String... propertyNames)
HasPropertySettersGetters
getPropertyBoolean
in interface HasPropertySettersGetters
propertyNames
- the name of on or more properties, forming a property chain of
type property1.property2.property3
public TestBenchElement getPropertyElement(String... propertyNames)
HasPropertySettersGetters
getPropertyElement
in interface HasPropertySettersGetters
propertyNames
- the name of on or more properties, forming a property chain of
type property1.property2.property3
public List<TestBenchElement> getPropertyElements(String... propertyNames)
HasPropertySettersGetters
getPropertyElements
in interface HasPropertySettersGetters
propertyNames
- the name of on or more properties, forming a property chain of
type property1.property2.property3
public Double getPropertyDouble(String... propertyNames)
HasPropertySettersGetters
getPropertyDouble
in interface HasPropertySettersGetters
propertyNames
- the name of on or more properties, forming a property chain of
type property1.property2.property3
public Integer getPropertyInteger(String... propertyNames)
HasPropertySettersGetters
getPropertyInteger
in interface HasPropertySettersGetters
propertyNames
- the name of on or more properties, forming a property chain of
type property1.property2.property3
public Object getProperty(String... propertyNames)
HasPropertySettersGetters
The return value needs to be cast manually to the correct type.
getProperty
in interface HasPropertySettersGetters
propertyNames
- the name of on or more properties, forming a property chain of
type property1.property2.property3
protected Object executeScript(String script, Object... args)
This method wraps any returned WebElement
as
TestBenchElement
.
script
- the script to executeargs
- the arguments, available in the script as
arguments[0]...arguments[N]
JavascriptExecutor.executeScript(String, Object...)
returnsUnsupportedOperationException
- if the underlying driver does not support JavaScript
executionJavascriptExecutor.executeScript(String, Object...)
public Object callFunction(String methodName, Object... args)
HasCallFunction
callFunction
in interface HasCallFunction
methodName
- the method to invokeargs
- the arguments to pass to the methodpublic void dispatchEvent(String eventType)
The event is created without any parameters.
eventType
- the type of custom event to dispatchCopyright © 2019. All rights reserved.