CustomMatchers¶
-
public class
CustomMatchers
¶ A collection of Hamcrest custom matchers, that are optimized to be as atomic as possible when interacting with the browser or a W3C document, and return useful error messages in case of a failure.
Methods¶
hasElement¶
hasElements¶
-
public static HasElements
hasElements
(Path path)¶ Successful if element is present in the browser or a W3C document. Useful especially when you have a reference count. This matcher is optimized. For example:
assertThat(browser, hasElements(path).present(5).times()); assertThat(browser, hasElements(path).present(5).timesOrMore()); assertThat(document, hasElements(path).present(5).timesOrLess());
Parameters: - path – The path of the elements to find
Returns: a matcher for the number of times an element is present.
hasNoElement¶
-
public static Matcher<InBrowser>
hasNoElement
(Path el)¶ Successful if given browser has no elements that correspond to the given path. The implementation of this is optimized. For example:
assertThat( browser, hasNoElement(path));
Parameters: - el –
- the path that is expected not to exist in the browser
Returns: a matcher that is successful if the element does not appear in the browser
- el –
hasText¶
isAbsentFrom¶
-
public static Matcher<Path>
isAbsentFrom
(InBrowser browser)¶ Successful if given browser has no elements that correspond to the given path. Equivalent to hasNoElement() matcher. This is much better than doing not(isPresent()), because in case of success (i.e. the element is not there), it will return immidiately, while the isPresent() will block until timeout is reached. For example:
assertThat( path, isAbsentFrom(browser));
Parameters: - browser – the browser instance to look in
Returns: a matcher that is successful if the element does not appear in the browser
isAbsentFrom¶
-
public static Matcher<Path>
isAbsentFrom
(Document document)¶ Successful if given document has no elements that correspond to the given path. For example:
assertThat( path, isAbsentFrom(doc));
Parameters: - document –
- a W3C document
Returns: a matcher that is successful if the element does not appear in the document
- document –
isDisplayedIn¶
-
public static Matcher<Path>
isDisplayedIn
(InBrowser browser)¶ Successful if given element is present and displayed in the browser. Relies on WebElement.isDisplayed(), thus non-atomic. For example:
assertThat( path, isDisplayedIn(browser));
Parameters: - browser – the browser instance to look in
Returns: a matcher that checks if an element is displayed in the browser
isEnabledIn¶
-
public static Matcher<Path>
isEnabledIn
(InBrowser browser)¶ Successful if given element is present and enabled in the browser. Relies on WebElement.isEnabled(), thus non-atomic. For example:
assertThat( path, isEnabledIn(browser));
Parameters: - browser – the browser instance to look in
Returns: a matcher that checks if an element is enabled in the browser
isNotDisplayedIn¶
-
public static Matcher<Path>
isNotDisplayedIn
(InBrowser browser)¶ Successful if given element is either not present, or present and not displayed in the browser. Relies on WebElement.isDisplayed(), thus non-atomic. For example:
assertThat( path, isNotDisplayedIn(browser));
Parameters: - browser – the browser instance to look in
Returns: a matcher that checks if an element is displayed in the browser
isPresent¶
-
public static IsPresentNTimes
isPresent
(int nTimes)¶ Successful if the the element appears the expected number of times in the browser or W3C document. This matcher is optimized. Example use for browser interaction:
InBrowser browser = new InBrowser(driver); assertThat( myElement, ispresent(5).timesOrMoreIn(browser)); assertThat( myElement, ispresent(5).timesIn(browser)); assertThat( myElement, ispresent(5).timesOrLessIn(browser));
Same examples apply in case you have a Document (org.w3c.dom.Document).
Parameters: - nTimes –
- the reference number of times to be matched against. See examples.
Returns: a matcher that matches the number of times an element is present. See examples in the description.
- nTimes –
isPresent¶
isPresentIn¶
isPresentIn¶
isSelectedIn¶
-
public static Matcher<Path>
isSelectedIn
(InBrowser browser)¶ Successful if given element is present and selected in the browser. Relies on WebElement.isSelected(), thus non-atomic. For example:
assertThat( path, isSelectedIn(browser));
Parameters: - browser – the browser instance to look in
Returns: a matcher that checks if an element is selected in the browser