Class LocatorProxies


  • public final class LocatorProxies
    extends Object
    Utility class to create proxies of WebElement, Component, FluentList and List of Components based on their locators.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean addProxyListener​(Object proxy, ProxyElementListener listener)
      Add a proxy listener for this proxy.
      static org.openqa.selenium.WebElement createWebElement​(Supplier<org.openqa.selenium.WebElement> elementSupplier)
      Create a WebElement proxy from an element supplier.
      static org.openqa.selenium.WebElement createWebElement​(org.openqa.selenium.support.pagefactory.ElementLocator locator)
      Create a WebElement proxy from an element locator.
      static org.openqa.selenium.WebElement createWebElement​(org.openqa.selenium.WebElement element)
      Create a WebElement proxy from an existing element.
      static List<org.openqa.selenium.WebElement> createWebElementList​(Supplier<List<org.openqa.selenium.WebElement>> elementsSupplier)
      Create a list of WebElement proxies from a supplier of element list.
      static List<org.openqa.selenium.WebElement> createWebElementList​(List<org.openqa.selenium.WebElement> elements)
      Create a list of WebElement proxies from an existing element list.
      static List<org.openqa.selenium.WebElement> createWebElementList​(org.openqa.selenium.support.pagefactory.ElementLocator locator)
      Create a list of WebElement proxies from a locator of element list.
      static org.openqa.selenium.WebElement first​(List<org.openqa.selenium.WebElement> proxy)
      Creates a proxy element matching the first element of the list.
      static LocatorHandler getLocatorHandler​(Object proxy)
      Get the proxy locator handler.
      static <T> T getLocatorResult​(T proxy)
      Get the underlying result of a proxy, through locator handler.
      static String getMessageContext​(Object proxy)
      Get the message context of given proxy.
      static org.openqa.selenium.WebElement index​(List<org.openqa.selenium.WebElement> proxy, int index)
      Creates a proxy element matching the n-th element of the list.
      static org.openqa.selenium.WebElement last​(List<org.openqa.selenium.WebElement> proxy)
      Creates a proxy element matching the last element of the list.
      static boolean loaded​(Object proxy)
      Check if this proxy has loaded it's result.
      static org.openqa.selenium.NoSuchElementException noSuchElement​(Object proxy)
      Build a NoSuchElementException using message provided by proxy.
      static void now​(Object proxy)
      If result is not loaded, load result immediatly.
      static boolean present​(Object proxy)
      Check if the proxy element is present.
      static boolean removeProxyListener​(Object proxy, ProxyElementListener listener)
      Removes a proxy element listener.
      static void reset​(Object proxy)
      Reset the proxy locator handler.
      static void setHooks​(Object proxy, HookChainBuilder hookChainBuilder, List<HookDefinition<?>> hookDefinitions)
      Apply this hook list.
    • Method Detail

      • noSuchElement

        public static org.openqa.selenium.NoSuchElementException noSuchElement​(Object proxy)
        Build a NoSuchElementException using message provided by proxy.
        Parameters:
        proxy - proxy
        Returns:
        NoSuchElementException No such element exception
      • getMessageContext

        public static String getMessageContext​(Object proxy)
        Get the message context of given proxy.
        Parameters:
        proxy - proxy
        Returns:
        message context
      • getLocatorHandler

        public static LocatorHandler getLocatorHandler​(Object proxy)
        Get the proxy locator handler.
        Parameters:
        proxy - proxy object
        Returns:
        locator handler, or null if not found
      • getLocatorResult

        public static <T> T getLocatorResult​(T proxy)
        Get the underlying result of a proxy, through locator handler.
        Type Parameters:
        T - type of the result
        Parameters:
        proxy - proxy object
        Returns:
        result
        See Also:
        LocatorHandler.getLocatorResult()
      • present

        public static boolean present​(Object proxy)
        Check if the proxy element is present.
        Parameters:
        proxy - proxy object
        Returns:
        true if result is present, false otherwise
        See Also:
        LocatorStatusHandler.present()
      • now

        public static void now​(Object proxy)
        If result is not loaded, load result immediatly. If it's already loaded, it has no effect.
        Parameters:
        proxy - proxy object
        See Also:
        LocatorHandler.now()
      • loaded

        public static boolean loaded​(Object proxy)
        Check if this proxy has loaded it's result.
        Parameters:
        proxy - proxy object
        Returns:
        true if the result is loaded, false otherwise
      • addProxyListener

        public static boolean addProxyListener​(Object proxy,
                                               ProxyElementListener listener)
        Add a proxy listener for this proxy.
        Parameters:
        proxy - proxy object
        listener - listener to add, which will be notified when result is searched and found
        Returns:
        true if the listener was added, false otherwise
      • removeProxyListener

        public static boolean removeProxyListener​(Object proxy,
                                                  ProxyElementListener listener)
        Removes a proxy element listener.
        Parameters:
        proxy - proxy object
        listener - listener to remove
        Returns:
        true if the listener was removed, false otherwise
      • createWebElement

        public static org.openqa.selenium.WebElement createWebElement​(org.openqa.selenium.WebElement element)
        Create a WebElement proxy from an existing element.
        Parameters:
        element - existing element
        Returns:
        proxy
      • createWebElement

        public static org.openqa.selenium.WebElement createWebElement​(Supplier<org.openqa.selenium.WebElement> elementSupplier)
        Create a WebElement proxy from an element supplier.
        Parameters:
        elementSupplier - element supplier
        Returns:
        proxy
      • createWebElement

        public static org.openqa.selenium.WebElement createWebElement​(org.openqa.selenium.support.pagefactory.ElementLocator locator)
        Create a WebElement proxy from an element locator.
        Parameters:
        locator - element locator
        Returns:
        proxy
      • createWebElementList

        public static List<org.openqa.selenium.WebElement> createWebElementList​(List<org.openqa.selenium.WebElement> elements)
        Create a list of WebElement proxies from an existing element list.
        Parameters:
        elements - existing element list
        Returns:
        proxy
      • createWebElementList

        public static List<org.openqa.selenium.WebElement> createWebElementList​(Supplier<List<org.openqa.selenium.WebElement>> elementsSupplier)
        Create a list of WebElement proxies from a supplier of element list.
        Parameters:
        elementsSupplier - supplier of element list
        Returns:
        proxy
      • createWebElementList

        public static List<org.openqa.selenium.WebElement> createWebElementList​(org.openqa.selenium.support.pagefactory.ElementLocator locator)
        Create a list of WebElement proxies from a locator of element list.
        Parameters:
        locator - locator of element list
        Returns:
        proxy
      • setHooks

        public static void setHooks​(Object proxy,
                                    HookChainBuilder hookChainBuilder,
                                    List<HookDefinition<?>> hookDefinitions)
        Apply this hook list.
        Parameters:
        proxy - proxy object
        hookChainBuilder - hook chain builder
        hookDefinitions - hook definitions
      • first

        public static org.openqa.selenium.WebElement first​(List<org.openqa.selenium.WebElement> proxy)
        Creates a proxy element matching the first element of the list.
        Parameters:
        proxy - list of element
        Returns:
        proxy element matching the first element
      • last

        public static org.openqa.selenium.WebElement last​(List<org.openqa.selenium.WebElement> proxy)
        Creates a proxy element matching the last element of the list.
        Parameters:
        proxy - list of element
        Returns:
        proxy element matching the last element
      • index

        public static org.openqa.selenium.WebElement index​(List<org.openqa.selenium.WebElement> proxy,
                                                           int index)
        Creates a proxy element matching the n-th element of the list.
        Parameters:
        proxy - list of element
        index - index to match
        Returns:
        proxy element matching the n-th element