Package com.github.loyada.jdollarx
Class InBrowser
- java.lang.Object
-
- com.github.loyada.jdollarx.InBrowser
-
public class InBrowser extends Object
A wrapper around Selenium WebDriver, used for interaction with the browser. In case only a single instance of the browser is used,InBrowserSinglton
offers a simpler API.
-
-
Constructor Summary
Constructors Constructor Description InBrowser(org.openqa.selenium.WebDriver driver)
Creates a connection to a browser, using the given driver
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.openqa.selenium.WebElement
clickAt(Path el)
Click at the location the first element that fits the given path.org.openqa.selenium.WebElement
clickOn(Path el)
Click on the first element that fits the given path.org.openqa.selenium.WebElement
contextClick(Path el)
Context-click (right click) at the location the first element that fits the given path.int
countAll(Path el)
Count number of elements that are currently present.void
doubleClickOn(Path el)
Doubleclick the location of the first element that fits the given path.Operations.DragAndDrop
dragAndDrop(Path path)
Drag and drop in the browser.org.openqa.selenium.WebElement
find(Path el)
Finds an element in the browser, based on the xpath representing el.List<org.openqa.selenium.WebElement>
findAll(Path el)
Finds all elements in the browser, based on the xpath representing el.org.openqa.selenium.WebElement
findPageWithNumberOfOccurrences(Path el, int numberOfOccurrences, RelationOperator relationOperator)
Don't use this directly.org.openqa.selenium.WebElement
findPageWithout(Path el)
Finds an page in the browser, that does not contain the given pathstatic InBrowser
fromSingleton()
List<?>
getAttributeOfAll(Path el, String attribute)
Get a specific attribute of all the elements matching the given path.List<String>
getCssClasses(Path el)
Get all classes of given Path element.org.openqa.selenium.WebDriver
getDriver()
int
getImplicitTimeout()
long
getImplicitTimeoutInMillisec()
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.TimeUnit
getTimeoutUnit()
org.openqa.selenium.WebElement
hoverOver(Path el)
Hover over the location of the first element that fits the given pathboolean
isCovered(Path el)
Assuming the element exists, check if it is covered by another elementboolean
isDisplayed(Path el)
is the element present and displayed? Typically you should not use this method directly.boolean
isEnabled(Path el)
is the element present and enabled? Typically you should not use this method directly.boolean
isNotPresent(Path el)
is the element present? Typically you should not use this method directly.boolean
isPresent(Path el)
is the element present? Typically you should not use this method directly.boolean
isSelected(Path el)
is the element present and selected? Typically you should not use this method directly.Integer
numberOfAppearances(Path el)
Returns the number of elements in the browser that match the given path.Operations.KeysDown
pressKeyDown(CharSequence thekey)
Press key down in the browser, or on a specific element.Operations.ReleaseKey
releaseKey(CharSequence thekey)
Release key down in the browser, or on a specific element.org.openqa.selenium.WebElement
rightClick(Path el)
Context-click (right click) at the location the first element that fits the given path.Operations.Scroll
scroll()
scroll the browser.Operations.ScrollElement
scrollElement(Path wrapper)
Operations.ScrollElement
scrollElementWithStepOverride(Path wrapper, int step)
org.openqa.selenium.WebElement
scrollTo(Path el)
Scroll to the location of the first element that fits the given pathOperations.KeysSender
sendKeys(CharSequence... charsToSend)
send keys to the browser, or to a specific element.void
setImplicitTimeout(int implicitTimeout, TimeUnit unit)
-
-
-
Method Detail
-
fromSingleton
public static InBrowser fromSingleton()
-
getDriver
public org.openqa.selenium.WebDriver getDriver()
- Returns:
- the underlying WebDriver instance
-
find
public org.openqa.selenium.WebElement find(Path el)
Finds an element in the browser, based on the xpath representing el. It is similar to WebDriver.findElement(), If el also has a WebElement (ie: getUnderlyingSource() is not empty), then it looks inside that WebElement. This is useful also to integrate with existing WebDriver code.- Parameters:
el
- - the path to find- Returns:
- - A WebElement instance from selenium, or throws NoSuchElementException exception
-
findPageWithNumberOfOccurrences
public org.openqa.selenium.WebElement findPageWithNumberOfOccurrences(Path el, int numberOfOccurrences, RelationOperator relationOperator)
Don't use this directly. There are better ways to do equivalent operation.- Parameters:
el
- the path to findnumberOfOccurrences
- the base number to findrelationOperator
- whether we look for exactly the numberOfOccurrences, at least, or at most occurrences- Returns:
- the first WebElement found
-
findPageWithout
public org.openqa.selenium.WebElement findPageWithout(Path el)
Finds an page in the browser, that does not contain the given path- Parameters:
el
- - the path that must not appear in the page- Returns:
- returns the page element or raises NoSuchElementException
-
findAll
public List<org.openqa.selenium.WebElement> findAll(Path el)
Finds all elements in the browser, based on the xpath representing el. It is similar to WebDriver.findElements(), If el also has a WebElement (ie: getUnderlyingSource() is not empty), then it looks inside that WebElement. This is useful also to integrate with existing WebDriver code.- Parameters:
el
- - the path to find- Returns:
- - A list of WebElement from selenium, or throws NoSuchElementException exception
-
getAttributeOfAll
public 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 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 int countAll(Path el)
Count number of elements that are currently present.- Parameters:
el
- the element definition- Returns:
- number of elements
-
numberOfAppearances
public Integer numberOfAppearances(Path el)
Returns the number of elements in the browser that match the given path. Typically you should not use this method directly. Instead, use CustomMatchers.- Parameters:
el
- the element to find- Returns:
- the number of elements in the browser that match the given path
-
isPresent
public boolean isPresent(Path el)
is the element present? Typically you should not use this method directly. Instead, use CustomMatchers.- Parameters:
el
- the path to find- Returns:
- true if the element is present
-
isNotPresent
public boolean isNotPresent(Path el)
is the element present? Typically you should not use this method directly. Instead, use CustomMatchers.- Parameters:
el
- the path to find- Returns:
- true if it is not present
-
isEnabled
public boolean isEnabled(Path el)
is the element present and enabled? Typically you should not use this method directly. Instead, use CustomMatchers.- Parameters:
el
- the element- Returns:
- true if it is present and enabled
-
isSelected
public boolean isSelected(Path el)
is the element present and selected? Typically you should not use this method directly. Instead, use CustomMatchers.- Parameters:
el
- the element- Returns:
- true if it is present and selected
-
isDisplayed
public boolean isDisplayed(Path el)
is the element present and displayed? Typically you should not use this method directly. Instead, use CustomMatchers. Also, this is limited to checking the inlined css style, so it is quite limited.- Parameters:
el
- the element- Returns:
- true if it is present and selected
-
isCovered
public 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
-
clickOn
public org.openqa.selenium.WebElement clickOn(Path el)
Click on the first element that fits the given path. Only works for clickable elements. If the element is currently not clickable, will wait up to a second for it to be clickable.- Parameters:
el
- the element- Returns:
- the clicked on WebElement
-
clickAt
public org.openqa.selenium.WebElement clickAt(Path el)
Click at the location the first element that fits the given path. Does not require a clickable element.- Parameters:
el
- the element- Returns:
- the clicked on WebElement
-
contextClick
public org.openqa.selenium.WebElement contextClick(Path el)
Context-click (right click) at the location the first element that fits the given path. Does not require a clickable element.- Parameters:
el
- the element- Returns:
- the clicked on WebElement
-
rightClick
public org.openqa.selenium.WebElement rightClick(Path el)
Context-click (right click) at the location the first element that fits the given path. Does not require a clickable element.- Parameters:
el
- the element- Returns:
- the clicked on WebElement
-
hoverOver
public org.openqa.selenium.WebElement hoverOver(Path el)
Hover over the location of the first element that fits the given path- Parameters:
el
- the element- Returns:
- the clicked on WebElement
-
scrollTo
public org.openqa.selenium.WebElement scrollTo(Path el)
Scroll to the location of the first element that fits the given path- Parameters:
el
- the element- Returns:
- the clicked on WebElement
-
doubleClickOn
public void doubleClickOn(Path el)
Doubleclick the location of the first element that fits the given path.- Parameters:
el
- the element
-
sendKeys
public Operations.KeysSender sendKeys(CharSequence... charsToSend)
send keys to the browser, or to a specific element. Two flavors of use: browser.sendKeys("abc").toBrowser(); browser.sendKeys("abc").to(path);- Parameters:
charsToSend
- The characters to send. Can be "abc" or "a", "b", "c"- Returns:
- a KeySender instance that allows to send keys to the browser in general, or to a specific DOM element
-
pressKeyDown
public Operations.KeysDown pressKeyDown(CharSequence thekey)
Press key down in the browser, or on a specific element. Two flavors of use: browser.pressKeyDown(Keys.TAB).inBrowser(); browser.pressKeyDown(Keys.TAB).on(path);- Parameters:
thekey
- a key to press- Returns:
- returns a KeysDown instance that allows to press a key on the browser in general or on a specific DOM element
-
releaseKey
public Operations.ReleaseKey releaseKey(CharSequence thekey)
Release key down in the browser, or on a specific element. Two flavors of use:browser.releaseKey(Keys.TAB).inBrowser(); browser.releaseKey(Keys.TAB).on(path);
- Parameters:
thekey
- a key to release- Returns:
- returns a ReleaseKey instance that allows to release on the browser in general or on a specific DOM element
-
scroll
public 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 Operations.ScrollElement scrollElement(Path wrapper)
-
scrollElementWithStepOverride
public Operations.ScrollElement scrollElementWithStepOverride(Path wrapper, int step)
-
dragAndDrop
public Operations.DragAndDrop dragAndDrop(Path path)
Drag and drop in the browser. Several flavors of use: browser.dragAndDrop(source).to(target); browser.dragAndDrop(source).to(xCor, yCor);- Parameters:
path
- the source element- Returns:
- a DragAndDrop instance, that allows to drag and drop to a location or to another DOM element
-
getSelect
public 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 List<String> getCssClasses(Path el)
Get all classes of given Path element.- Parameters:
el
- the element to look for- Returns:
- a list of classes
-
setImplicitTimeout
public void setImplicitTimeout(int implicitTimeout, TimeUnit unit)
-
getImplicitTimeout
public int getImplicitTimeout()
-
getTimeoutUnit
public TimeUnit getTimeoutUnit()
-
getImplicitTimeoutInMillisec
public long getImplicitTimeoutInMillisec()
-
-