Package org.fluentlenium.core.proxy
Class AbstractLocatorHandler<T>
- java.lang.Object
-
- org.fluentlenium.core.proxy.AbstractLocatorHandler<T>
-
- Type Parameters:
T- type of underlying object.
- All Implemented Interfaces:
java.lang.reflect.InvocationHandler,LocatorHandler<T>
- Direct Known Subclasses:
ComponentHandler,ListHandler
public abstract class AbstractLocatorHandler<T> extends java.lang.Object implements java.lang.reflect.InvocationHandler, LocatorHandler<T>
Abstract proxy handler supporting lazy loading and hooks onWebElement.
-
-
Field Summary
Fields Modifier and Type Field Description protected HookChainBuilderhookChainBuilderprotected java.util.List<HookDefinition<?>>hookDefinitionsprotected java.util.List<FluentHook>hooksprotected org.openqa.selenium.support.pagefactory.ElementLocatorlocatorprotected Tproxyprotected Tresult
-
Constructor Summary
Constructors Constructor Description AbstractLocatorHandler(org.openqa.selenium.support.pagefactory.ElementLocator locator)Creates a new locator handler.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanaddListener(ProxyElementListener listener)Add a listener for this locator handler.booleanequals(java.lang.Object obj)protected voidfireProxyElementFound(T result)Fire proxy element found event.protected voidfireProxyElementSearch()Fire proxy element search event.protected abstract org.openqa.selenium.WebElementgetElement()Get the underlying element.org.openqa.selenium.support.pagefactory.ElementLocatorgetHookLocator()Retrieve the element locator used by this proxy, with hooks applied.protected java.lang.StringgetLazyToString()Get string representation of not already found element.org.openqa.selenium.support.pagefactory.ElementLocatorgetLocator()Retrieve the element locator used by this proxy, without any hook applied.TgetLocatorResult()Get the actual result of the locator, if result is not defined and not stale.abstract TgetLocatorResultImpl()Get the actual result of the locator.protected static java.lang.reflect.MethodgetMethod(java.lang.Class<?> declaringClass, java.lang.String name, java.lang.Class... types)Get declared method.inthashCode()java.lang.Objectinvoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)protected abstract booleanisStale()Get the stale status of the element.booleanloaded()Check if this handler has loaded it's result.org.openqa.selenium.NoSuchElementExceptionnoSuchElement()Builds aNoSuchElementExceptionwith a message matching this locator handler.voidnow()If result is not loaded, load result immediately.booleanpresent()Check if the result is present.java.lang.StringproxyToString(java.lang.String elementToString)Get string representation of the proxybooleanremoveListener(ProxyElementListener listener)Removes a proxy element listener.voidreset()Reset the loaded data.protected abstract java.util.List<org.openqa.selenium.WebElement>resultToList(T result)Convert result to a list of selenium element.voidsetHooks(HookChainBuilder hookChainBuilder, java.util.List<HookDefinition<?>> hookDefinitions)Apply this hook list.voidsetProxy(T proxy)Set the proxy using this handler.java.lang.StringtoString()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.fluentlenium.core.proxy.LocatorHandler
getInvocationTarget, getMessageContext
-
-
-
-
Field Detail
-
hookChainBuilder
protected HookChainBuilder hookChainBuilder
-
hookDefinitions
protected java.util.List<HookDefinition<?>> hookDefinitions
-
proxy
protected T proxy
-
locator
protected final org.openqa.selenium.support.pagefactory.ElementLocator locator
-
result
protected T result
-
hooks
protected java.util.List<FluentHook> hooks
-
-
Method Detail
-
getMethod
protected static java.lang.reflect.Method getMethod(java.lang.Class<?> declaringClass, java.lang.String name, java.lang.Class... types)Get declared method.- Parameters:
declaringClass- declaring classname- method nametypes- argument types- Returns:
- method
-
addListener
public boolean addListener(ProxyElementListener listener)
Description copied from interface:LocatorHandlerAdd a listener for this locator handler.- Specified by:
addListenerin interfaceLocatorHandler<T>- Parameters:
listener- listener to add, which will be notified when result is searched and found- Returns:
- true if the listener was added, false otherwise
-
removeListener
public boolean removeListener(ProxyElementListener listener)
Description copied from interface:LocatorHandlerRemoves a proxy element listener.- Specified by:
removeListenerin interfaceLocatorHandler<T>- Parameters:
listener- listener to remove- Returns:
- true if the listener was removed, false otherwise
-
fireProxyElementSearch
protected void fireProxyElementSearch()
Fire proxy element search event.
-
fireProxyElementFound
protected void fireProxyElementFound(T result)
Fire proxy element found event.- Parameters:
result- found element
-
resultToList
protected abstract java.util.List<org.openqa.selenium.WebElement> resultToList(T result)
Convert result to a list of selenium element.- Parameters:
result- found result- Returns:
- list of selenium element
-
setProxy
public void setProxy(T proxy)
Set the proxy using this handler.- Parameters:
proxy- proxy using this handler
-
getLocatorResultImpl
public abstract T getLocatorResultImpl()
Get the actual result of the locator.- Returns:
- result of the locator
-
getLocatorResult
public T getLocatorResult()
Get the actual result of the locator, if result is not defined and not stale.It also raise events.
- Specified by:
getLocatorResultin interfaceLocatorHandler<T>- Returns:
- result of the locator
-
isStale
protected abstract boolean isStale()
Get the stale status of the element.- Returns:
- true if element is stale, false otherwise
-
getElement
protected abstract org.openqa.selenium.WebElement getElement()
Get the underlying element.- Returns:
- underlying element
-
noSuchElement
public org.openqa.selenium.NoSuchElementException noSuchElement()
Builds aNoSuchElementExceptionwith a message matching this locator handler.- Specified by:
noSuchElementin interfaceLocatorHandler<T>- Returns:
- no such element exception
-
setHooks
public void setHooks(HookChainBuilder hookChainBuilder, java.util.List<HookDefinition<?>> hookDefinitions)
Description copied from interface:LocatorHandlerApply this hook list.- Specified by:
setHooksin interfaceLocatorHandler<T>- Parameters:
hookChainBuilder- hook chain builderhookDefinitions- hook definitions
-
getLocator
public org.openqa.selenium.support.pagefactory.ElementLocator getLocator()
Description copied from interface:LocatorHandlerRetrieve the element locator used by this proxy, without any hook applied.- Specified by:
getLocatorin interfaceLocatorHandler<T>- Returns:
- element locator
-
getHookLocator
public org.openqa.selenium.support.pagefactory.ElementLocator getHookLocator()
Description copied from interface:LocatorHandlerRetrieve the element locator used by this proxy, with hooks applied.- Specified by:
getHookLocatorin interfaceLocatorHandler<T>- Returns:
- element locator wrapped with hooks
-
loaded
public boolean loaded()
Description copied from interface:LocatorHandlerCheck if this handler has loaded it's result.- Specified by:
loadedin interfaceLocatorHandler<T>- Returns:
- true if the result is loaded, false otherwise
-
present
public boolean present()
Description copied from interface:LocatorHandlerCheck if the result is present.- Specified by:
presentin interfaceLocatorHandler<T>- Returns:
- true if result is present, false otherwise
-
reset
public void reset()
Description copied from interface:LocatorHandlerReset the loaded data.- Specified by:
resetin interfaceLocatorHandler<T>
-
now
public void now()
Description copied from interface:LocatorHandlerIf result is not loaded, load result immediately. If it's already loaded, it has no effect.- Specified by:
nowin interfaceLocatorHandler<T>
-
invoke
public java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.Throwable- Specified by:
invokein interfacejava.lang.reflect.InvocationHandler- Throws:
java.lang.Throwable
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
getLazyToString
protected java.lang.String getLazyToString()
Get string representation of not already found element.- Returns:
- string representation of not already found element
-
proxyToString
public java.lang.String proxyToString(java.lang.String elementToString)
Get string representation of the proxy- Parameters:
elementToString- string representation of the underlying element- Returns:
- string representation of the proxy
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-