CustomMatchers¶
-
public final 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. This is a simplified API, relevant when there is a singleton browser.
Methods¶
hasText¶
-
public static Matcher<Path>
hasText
(String text)¶ Successful if element has the text equal to the given parameter in the browser/document. Note that internally it creates a new path that includes the “hasText” constraint, and then searches for it, so it is atomic. Example use:
assertThat( path, hasText("John"));
Parameters: - text – the text to equal to (case insensitive)
Returns: a custom Hamcrest matcher
isAbsent¶
-
public static Matcher<Path>
isAbsent
()¶ Successful if the browser has no elements that correspond to the given path. The implementation of this is optimized. 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, isAbsent());
Returns: a matcher that is successful if an element does not appear in the browser.
isDisplayed¶
isEnabled¶
isNotDisplayed¶
-
public static Matcher<Path>
isNotDisplayed
()¶ 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, isNotDisplayed());
Returns: a matcher that checks if an element is displayed in the browser
isNotSelected¶
isPresent¶
-
public static IsPresentNTimes
isPresent
(int nTimes)¶ Successful if the the element appears the expected number of times in the browser. This matcher is optimized. Example use for browser interaction:
assertThat( path, ispresent(5).timesOrMore()); assertThat( path, ispresent(5).times()); assertThat( path, ispresent(5).timesOrLess());
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 –