CustomMatchers { public static Matcher<InBrowser> hasElement(final Path el) { return new TypeSafeMatcher<InBrowser>() { @Override public void describeTo(final Description description) { description.appendText("browser page contains " + el); } @Override protected void describeMismatchSafely(final InBrowser browser, final Description mismatchDescription) { mismatchDescription.appendText(CustomMatchersUtil.wrap(el) + " is absent"); } @Override protected boolean matchesSafely(final InBrowser browser) { return browser.isPresent(el); } }; }  static Matcher<InBrowser> hasElement(final Path el); static IsPresentNTimes isPresent(int nTimes); static IsPresent isPresent(); static HasText hasText(String text); static HasElements hasElements(Path path); static Matcher<Path> isPresentIn(final InBrowser browser); static Matcher<Path> isPresentIn(final Document document); static Matcher<Path> isDisplayedIn(final InBrowser browser); static Matcher<Path> isNotDisplayedIn(final InBrowser browser); static Matcher<Path> isSelectedIn(final InBrowser browser); static Matcher<Path> isEnabledIn(final InBrowser browser); static Matcher<InBrowser> hasNoElement(final Path el); static Matcher<Path> isAbsentFrom(final InBrowser browser); static Matcher<Path> isAbsentFrom(final Document document);  }
@Test public void hasElementFailed() { when(browser.find(any())).thenThrow(new NoSuchElementException("")); try { assertThat(browser, CustomMatchers.hasElement(div)); fail("should fail"); } catch (AssertionError e) { assertThat(e.getMessage(), is(equalTo("\nExpected: browser page contains div\n but: div is absent"))); } }