Class InBrowserSinglton


  • public final class InBrowserSinglton
    extends Object
    A simplified API built to interact with a single instance of a running browser. See InBrowser for an API that supports multiple browser instances.
    • Field Detail

      • driver

        public static org.openqa.selenium.WebDriver driver
    • Constructor Detail

      • InBrowserSinglton

        public InBrowserSinglton()
    • Method Detail

      • find

        public static org.openqa.selenium.WebElement find​(Path el)
        Equivalent to WebDriver.findElement(). If the Path contains a WebElement than it will look for an element inside that WebElement. Otherwise it looks starting at the top level. It also alters the xpath if needed to search from top level correctly.
        Parameters:
        el - a Path instance
        Returns:
        returns a WebElement or throws an ElementNotFoundException
      • findAll

        public static List<org.openqa.selenium.WebElement> findAll​(Path el)
        Equivalent to WebDriver.findElements(). If the Path contains a WebElement than it will look for an element inside that WebElement. Otherwise it looks starting at the top level. It also alters the xpath if needed to search from top level correctly.
        Parameters:
        el - a Path instance
        Returns:
        a list of WebElements.
      • getAttributeOfAll

        public static List<?> getAttributeOfAll​(Path el,
                                                String attribute)
        Get a specific attribute of all the elements matching the given path. The implementation is optimized, and avoids multiple round trips to browser.
        Parameters:
        el - the elements to find
        attribute - - the attribute to extract
        Returns:
        a list of string/int. In case the el is not found, it returns an empty list.
      • countAll

        public static int countAll​(Path el)
        Count number of elements that are currently present.
        Parameters:
        el - the element definition
        Returns:
        number of elements
      • numberOfAppearances

        public static Integer numberOfAppearances​(Path el)
        Typically should not be used directly. There are usually better options.
        Parameters:
        el - a Path instance
        Returns:
        tbe number of appearances of an element.
      • isPresent

        public static boolean isPresent​(Path el)
        Parameters:
        el - a Path instance
        Returns:
        true if the element is present.
      • isEnabled

        public static boolean isEnabled​(Path el)
        Relies on Selenium WebElement::isEnabled, thus non-atomic.
        Parameters:
        el - the path of the element to find
        Returns:
        true if the element is present and enabled
      • isCovered

        public static boolean isCovered​(Path el)
        Assuming the element exists, check if it is covered by another element
        Parameters:
        el - the wanted element
        Returns:
        is it covered
      • isSelected

        public static boolean isSelected​(Path el)
        Relies on Selenium WebElement::isSelected, thus non-atomic.
        Parameters:
        el - the path of the element to find
        Returns:
        true if the element is present and selected
      • isDisplayed

        public static boolean isDisplayed​(Path el)
        Relies on Selenium WebElement::isDisplayed, thus non-atomic.
        Parameters:
        el - the path of the element to find
        Returns:
        true if the element is present and displayed
      • clickOn

        public static org.openqa.selenium.WebElement clickOn​(Path el)
        Click on the element that corresponds to the given path. Requires the element to be clickable.
        Parameters:
        el - a Path instance
        Returns:
        the WebElement clicked on
      • clickAt

        public static org.openqa.selenium.WebElement clickAt​(Path el)
        Click on the location of the element that corresponds to the given path.
        Parameters:
        el - a Path instance
        Returns:
        the WebElement clicked at
      • contextClick

        public static org.openqa.selenium.WebElement contextClick​(Path el)
        Context click (right click) on the location of the element that corresponds to the given path.
        Parameters:
        el - a Path instance
        Returns:
        the WebElement clicked at
      • rightClick

        public static org.openqa.selenium.WebElement rightClick​(Path el)
        Context click (right click) on the location of the element that corresponds to the given path.
        Parameters:
        el - a Path instance
        Returns:
        the WebElement clicked at
      • hoverOver

        public static org.openqa.selenium.WebElement hoverOver​(Path el)
        Hover over on the location of the element that corresponds to the given path.
        Parameters:
        el - a Path instance
        Returns:
        the WebElement found
      • scrollTo

        public static org.openqa.selenium.WebElement scrollTo​(Path el)
        scroll to the location of the element that corresponds to the given path.
        Parameters:
        el - a Path instance
        Returns:
        the WebElement found
      • scroll

        public static Operations.Scroll scroll()
        scroll the browser. Several flavors of use:
         
            browser.scroll().to(path);
            browser.scroll().left(50);
            browser.scroll().right(50);
            browser.scroll().up(50);
            browser.scroll().down(50);
         
         
        Returns:
        a Scroll instance that allows to scroll by offset or to a location of a DOM element
      • scrollElement

        public static Operations.ScrollElement scrollElement​(Path el)
        scroll within the given element. Useful especially when working with grids.
        Parameters:
        el - a Path instance
        Returns:
        the WebElement found
      • scrollElementWithStepOverride

        public static Operations.ScrollElement scrollElementWithStepOverride​(Path el,
                                                                             int step)
        scroll within the given element. Useful especially when working with grids.
        Parameters:
        el - a Path instance
        step - step size override
        Returns:
        the WebElement found
      • doubleClickOn

        public static void doubleClickOn​(Path el)
        Doubleclick on the element that corresponds to the given path. Requires the element to be clickable.
        Parameters:
        el - a Path instance
      • sendKeys

        public static Operations.KeysSender sendKeys​(CharSequence... charsToSend)
        send keys to the browser, or to a specific element. Two flavors of use:
        
              sendKeys("abc").toBrowser();
              sendKeys("abc").to(path);
             
         
        Parameters:
        charsToSend - the keys to send. Can be "abc", or "a", "b", "c"
        Returns:
        a KeySender instance that allows to send to the browser in general or to a specific element in the DOM
      • pressKeyDown

        public static Operations.KeysDown pressKeyDown​(CharSequence thekey)
        Press key down in the browser, or on a specific element. Two flavors of use:
        
         pressKeyDown(Keys.TAB).inBrowser();
         pressKeyDown(Keys.TAB).on(path);
             
         
        Parameters:
        thekey - the key to press
        Returns:
        a KeysDown instance that allows to send to the browser in general or to a specific element in the DOM. See example.
      • releaseKey

        public static Operations.ReleaseKey releaseKey​(CharSequence thekey)
        Release key in the browser, or on a specific element. Two flavors of use:
        
         releaseKey(Keys.TAB).inBrowser();
         releaseKey(Keys.TAB).on(path);
             
         
        Parameters:
        thekey - the key to release
        Returns:
        a ReleaseKey instance that allows to send to the browser in general or to a specific element in the DOM. See example.
      • dragAndDrop

        public static Operations.DragAndDrop dragAndDrop​(Path path)
        Drag and drop in the browser. Several flavors of use:
        
         dragAndDrop(source).to(target);
         dragAndDrop(source).to(xCor, yCor);
             
         
        Parameters:
        path - the path of the element to drag and drop
        Returns:
        a DragAndDrop instance that allows to drag and drop to another element or to another location
      • getSelect

        public static org.openqa.selenium.support.ui.Select getSelect​(Path el)
        Get a Selenium select element, which provides a high level API to interacting with a "select" menu. Since the Selenium API is good enough, there was no need to create a specialized dollarx version.
        Parameters:
        el - - must be a "select" path, with "option" elements for the various selectable options.
        Returns:
        org.openqa.selenium.support.ui.Select instance
      • getCssClasses

        public static List<String> getCssClasses​(Path el)
        Get all classes of given Path element.
        Parameters:
        el - the element to look for
        Returns:
        a list of classes
      • waitUntilStable

        public static int waitUntilStable​(Path el,
                                          int waitBetweenChecksInMillis)
      • setImplicitTimeout

        public static void setImplicitTimeout​(int implicitTimeout,
                                              TimeUnit unit)
        Manager implicit timeouts
        Parameters:
        implicitTimeout - similar to Selenium API
        unit - similar to Selenium API
      • getImplicitTimeout

        public static int getImplicitTimeout()
      • getTimeoutUnit

        public static TimeUnit getTimeoutUnit()
      • getImplicitTimeoutInMillisec

        public static long getImplicitTimeoutInMillisec()