Class InBrowserSinglton
- java.lang.Object
-
- com.github.loyada.jdollarx.singlebrowser.InBrowserSinglton
-
-
Field Summary
Fields Modifier and Type Field Description static org.openqa.selenium.WebDriverdriver
-
Constructor Summary
Constructors Constructor Description InBrowserSinglton()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.openqa.selenium.WebElementclickAt(Path el)Click on the location of the element that corresponds to the given path.static org.openqa.selenium.WebElementclickOn(Path el)Click on the element that corresponds to the given path.static org.openqa.selenium.WebElementcontextClick(Path el)Context click (right click) on the location of the element that corresponds to the given path.static intcountAll(Path el)Count number of elements that are currently present.static voiddoubleClickOn(Path el)Doubleclick on the element that corresponds to the given path.static Operations.DragAndDropdragAndDrop(Path path)Drag and drop in the browser.static org.openqa.selenium.WebElementfind(Path el)Equivalent to WebDriver.findElement().static List<org.openqa.selenium.WebElement>findAll(Path el)Equivalent to WebDriver.findElements().static <T> List<T>getAttributeOfAll(Path el, String attribute)Get a specific attribute of all the elements matching the given path.static List<String>getCssClasses(Path el)Get all classes of given Path element.static intgetImplicitTimeout()static longgetImplicitTimeoutInMillisec()static org.openqa.selenium.support.ui.SelectgetSelect(Path el)Get a Selenium select element, which provides a high level API to interacting with a "select" menu.static TimeUnitgetTimeoutUnit()static org.openqa.selenium.WebElementhoverOver(Path el)Hover over on the location of the element that corresponds to the given path.static booleanisCovered(Path el)Assuming the element exists, check if it is covered by another elementstatic booleanisDisplayed(Path el)Relies on Selenium WebElement::isDisplayed, thus non-atomic.static booleanisEnabled(Path el)Relies on Selenium WebElement::isEnabled, thus non-atomic.static booleanisPresent(Path el)static booleanisSelected(Path el)Relies on Selenium WebElement::isSelected, thus non-atomic.static IntegernumberOfAppearances(Path el)Typically should not be used directly.static Operations.KeysDownpressKeyDown(CharSequence thekey)Press key down in the browser, or on a specific element.static Operations.ReleaseKeyreleaseKey(CharSequence thekey)Release key in the browser, or on a specific element.static org.openqa.selenium.WebElementrightClick(Path el)Context click (right click) on the location of the element that corresponds to the given path.static Operations.Scrollscroll()scroll the browser.static Operations.ScrollElementscrollElement(Path el)scroll within the given element.static Operations.ScrollElementscrollElementWithStepOverride(Path el, int step)scroll within the given element.static org.openqa.selenium.WebElementscrollTo(Path el)scroll to the location of the element that corresponds to the given path.static Operations.KeysSendersendKeys(CharSequence... charsToSend)send keys to the browser, or to a specific element.static voidsetImplicitTimeout(int implicitTimeout, TimeUnit unit)Manager implicit timeoutsstatic intwaitUntilStable(Path el, int waitBetweenChecksInMillis)
-
-
-
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 <T> List<T> 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 findattribute- - 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 instancestep- 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 APIunit- similar to Selenium API
-
getImplicitTimeout
public static int getImplicitTimeout()
-
getTimeoutUnit
public static TimeUnit getTimeoutUnit()
-
getImplicitTimeoutInMillisec
public static long getImplicitTimeoutInMillisec()
-
-