Class PrimeSelenium


  • public final class PrimeSelenium
    extends Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void clearInput​(org.openqa.selenium.WebElement input, boolean isAjaxified)
      Clears the input field of text.
      static <T extends org.openqa.selenium.WebElement>
      T
      createFragment​(Class<T> fragmentClass, org.openqa.selenium.By by)
      Creates the PrimeFaces Selenium component for the selector.
      static <T extends org.openqa.selenium.WebElement>
      T
      createFragment​(Class<T> fragmentClass, org.openqa.selenium.WebElement element)
      Creates the PrimeFaces Selenium component for the element.
      static void disableAnimations()
      Globally disable all CSS and jQuery animations.
      static void enableAnimations()
      Globally enable all CSS and jQuery animations.
      static <T> T executeScript​(boolean isAjaxified, String script, Object... args)
      Executes JavaScript in the browser and will wait if the request is an AJAX request.
      static <T> T executeScript​(String script, Object... args)
      Executes JavaScript in the browser.
      static String getBaseUrl()  
      static org.openqa.selenium.Capabilities getCapabilities()
      Get Capabilities of WebDriver.
      static String getUrl​(String url)
      Gets the URL of the page.
      static String getUrl​(AbstractPrimePage page)
      Gets the URL of the page.
      static org.openqa.selenium.WebDriver getWebDriver()
      Gets the current Selenium WebDriver.
      static <T extends AbstractPrimePage>
      T
      goTo​(Class<T> pageClass)
      Goto a particular page.
      static void goTo​(String partialUrl)
      Goto a particular page.
      static void goTo​(AbstractPrimePage page)
      Goto a particular page.
      static <T> T guardAjax​(String script, Object... args)
      Guard the widget script which fires an AJAX request and means wait until it has completed before returning.
      static <T> T guardAjax​(T target)
      Guard the AJAX request which means wait until it has completed before returning.
      static <T> T guardAjax​(T target, int delayInMilliseconds)
      Guard the AJAX request which means wait until it has completed before returning.
      static <T> T guardHttp​(T target)
      Guard the HTTP request which means wait until it has completed before returning.
      static boolean hasCssClass​(org.openqa.selenium.WebElement element, String... cssClass)
      Checks a WebElement if it has a CSS class or classes.
      static boolean isChrome()
      Is the current WebDriver a Chrome driver?
      static boolean isElementClickable​(org.openqa.selenium.WebElement element)
      Is this element clickable?
      static boolean isElementDisplayed​(org.openqa.selenium.By by)
      Is the Element displayed on the page?
      static boolean isElementDisplayed​(org.openqa.selenium.WebElement element)
      Is the Element displayed on the page?
      static boolean isElementEnabled​(org.openqa.selenium.By by)
      Is the Element enabled on the page?
      static boolean isElementEnabled​(org.openqa.selenium.WebElement element)
      Is the Element enabled on the page?
      static boolean isElementPresent​(org.openqa.selenium.By by)
      Is the Element present on the page?
      static boolean isElementPresent​(org.openqa.selenium.WebElement element)
      Is the Element present on the page?
      static boolean isFirefox()
      Is the current WebDriver a Firefox driver?
      static boolean isHeadless()
      Is this driver running headless?
      static boolean isMacOs()
      Are we running on MacOS?
      static boolean isSafari()
      Is the current WebDriver a Safari driver?
      static boolean isVisibleInViewport​(org.openqa.selenium.WebElement element)
      Is the Element visible in the current viewport??
      static void setHiddenInput​(org.openqa.selenium.WebElement input, String value)
      Sets a value to a hidden input.
      static void wait​(int milliseconds)
      Waits specified amount of milliseconds.
      static org.openqa.selenium.support.ui.WebDriverWait waitDocumentLoad()
      Wait until the document is loaded.
      static org.openqa.selenium.support.ui.WebDriverWait waitGui()
      Wait will ignore instances of NotFoundException that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others.
    • Method Detail

      • getWebDriver

        public static org.openqa.selenium.WebDriver getWebDriver()
        Gets the current Selenium WebDriver.
        Returns:
        the WebDriver currently being used
      • createFragment

        public static <T extends org.openqa.selenium.WebElement> T createFragment​(Class<T> fragmentClass,
                                                                                  org.openqa.selenium.By by)
        Creates the PrimeFaces Selenium component for the selector.
        Type Parameters:
        T - the type of component returned
        Parameters:
        fragmentClass - the component class to create like InputText.class
        by - the selector to find the component by
        Returns:
        the component
      • createFragment

        public static <T extends org.openqa.selenium.WebElement> T createFragment​(Class<T> fragmentClass,
                                                                                  org.openqa.selenium.WebElement element)
        Creates the PrimeFaces Selenium component for the element.
        Type Parameters:
        T - the type of component returned
        Parameters:
        fragmentClass - the component class to create like InputText.class
        element - the WebElement to bind this component class to
        Returns:
        the component
      • goTo

        public static void goTo​(String partialUrl)
        Goto a particular page.
        Parameters:
        partialUrl - the partial URL
      • getUrl

        public static String getUrl​(String url)
        Gets the URL of the page.
        Parameters:
        url - the URL to construct
        Returns:
        the full URL
      • getBaseUrl

        public static String getBaseUrl()
      • hasCssClass

        public static boolean hasCssClass​(org.openqa.selenium.WebElement element,
                                          String... cssClass)
        Checks a WebElement if it has a CSS class or classes. If more than one is listed then ALL must be found on the element.
        Parameters:
        element - the element to check
        cssClass - the CSS class or classes to look for
        Returns:
        true if this element has the CSS class
      • isElementPresent

        public static boolean isElementPresent​(org.openqa.selenium.By by)
        Is the Element present on the page?
        Parameters:
        by - the selector
        Returns:
        true if present
      • isElementPresent

        public static boolean isElementPresent​(org.openqa.selenium.WebElement element)
        Is the Element present on the page?
        Parameters:
        element - the WebElement to check
        Returns:
        true if present
      • isElementDisplayed

        public static boolean isElementDisplayed​(org.openqa.selenium.By by)
        Is the Element displayed on the page?
        Parameters:
        by - the selector
        Returns:
        true if displayed
      • isElementDisplayed

        public static boolean isElementDisplayed​(org.openqa.selenium.WebElement element)
        Is the Element displayed on the page?
        Parameters:
        element - the WebElement to check
        Returns:
        true if displayed
      • isVisibleInViewport

        public static boolean isVisibleInViewport​(org.openqa.selenium.WebElement element)
        Is the Element visible in the current viewport??
        Parameters:
        element - the WebElement to check
        Returns:
        true if visible
      • isElementEnabled

        public static boolean isElementEnabled​(org.openqa.selenium.By by)
        Is the Element enabled on the page?
        Parameters:
        by - the selector
        Returns:
        true if enabled
      • isElementEnabled

        public static boolean isElementEnabled​(org.openqa.selenium.WebElement element)
        Is the Element enabled on the page?
        Parameters:
        element - the WebElement to check
        Returns:
        true if enabled
      • isElementClickable

        public static boolean isElementClickable​(org.openqa.selenium.WebElement element)
        Is this element clickable?
        Parameters:
        element - the WebElement to check for clickable
        Returns:
        true if clickable false if not
      • guardHttp

        public static <T> T guardHttp​(T target)
        Guard the HTTP request which means wait until it has completed before returning.
        Type Parameters:
        T - the type
        Parameters:
        target - the target to guard
        Returns:
        the type
      • guardAjax

        public static <T> T guardAjax​(T target)
        Guard the AJAX request which means wait until it has completed before returning.
        Type Parameters:
        T - the type of element
        Parameters:
        target - the element to guard
        Returns:
        the element
      • guardAjax

        public static <T> T guardAjax​(T target,
                                      int delayInMilliseconds)
        Guard the AJAX request which means wait until it has completed before returning. This introduces a delay because some client side activity uses "setTimeout" Javascript to delay the execution of AJAX.
        Type Parameters:
        T - the element type
        Parameters:
        target - the element to guard
        delayInMilliseconds - how long to delay before expecting an AJAX event
        Returns:
        the element
      • guardAjax

        public static <T> T guardAjax​(String script,
                                      Object... args)
        Guard the widget script which fires an AJAX request and means wait until it has completed before returning.
        Type Parameters:
        T - the return type
        Parameters:
        script - the script to execute
        args - any arguments to the script
        Returns:
        the result of running the JavaScript
      • executeScript

        public static <T> T executeScript​(String script,
                                          Object... args)
        Executes JavaScript in the browser.
        Type Parameters:
        T - the return type
        Parameters:
        script - the script to execute
        args - any arguments to the script
        Returns:
        the result of running the JavaScript
      • executeScript

        public static <T> T executeScript​(boolean isAjaxified,
                                          String script,
                                          Object... args)
        Executes JavaScript in the browser and will wait if the request is an AJAX request.
        Type Parameters:
        T - the return type
        Parameters:
        isAjaxified - true if this is an AJAX request, false if regular script
        script - the script to execute
        args - any arguments to the script
        Returns:
        the result of running the JavaScript
      • waitGui

        public static org.openqa.selenium.support.ui.WebDriverWait waitGui()
        Wait will ignore instances of NotFoundException that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others. You can add more to the ignore list by calling ignoring(exceptions to add).
        Returns:
        the WebDriverWait
      • waitDocumentLoad

        public static org.openqa.selenium.support.ui.WebDriverWait waitDocumentLoad()
        Wait until the document is loaded.
        Returns:
        the WebDriverWait
      • disableAnimations

        public static void disableAnimations()
        Globally disable all CSS and jQuery animations.
      • enableAnimations

        public static void enableAnimations()
        Globally enable all CSS and jQuery animations.
      • setHiddenInput

        public static void setHiddenInput​(org.openqa.selenium.WebElement input,
                                          String value)
        Sets a value to a hidden input.
        Parameters:
        input - the WebElement input to set
        value - the value to set
        See Also:
        Stack Overflow
      • clearInput

        public static void clearInput​(org.openqa.selenium.WebElement input,
                                      boolean isAjaxified)
        Clears the input field of text.
        Parameters:
        input - the WebElement input to set
        isAjaxified - true if using AJAX
        See Also:
        Safari Hack
      • isChrome

        public static boolean isChrome()
        Is the current WebDriver a Chrome driver?
        Returns:
        true if Chrome, false if any other browser
      • isFirefox

        public static boolean isFirefox()
        Is the current WebDriver a Firefox driver?
        Returns:
        true if Firefox, false if any other browser
      • isSafari

        public static boolean isSafari()
        Is the current WebDriver a Safari driver?
        Returns:
        true if Safari, false if any other browser
      • isMacOs

        public static boolean isMacOs()
        Are we running on MacOS?
        Returns:
        true if MacOS
      • isHeadless

        public static boolean isHeadless()
        Is this driver running headless? Meaning without a UI.
        Returns:
        true if headless, false if not
      • wait

        public static void wait​(int milliseconds)
        Waits specified amount of milliseconds.
        Parameters:
        milliseconds - how many milliseconds to wait
      • getCapabilities

        public static org.openqa.selenium.Capabilities getCapabilities()
        Get Capabilities of WebDriver.
        Returns:
        Returns Capabilities of WebDriver