CustomMatchers { public static Matcher<Path> isDisplayedIn(final InBrowser browser) { return new TypeSafeMatcher<Path>() { private Path el; @Override public void describeTo(final Description description) { description.appendText(el + " is displayed"); } @Override protected void describeMismatchSafely(final Path el, final Description mismatchDescription) { mismatchDescription.appendText(el + " is not displayed"); } @Override protected boolean matchesSafely(final Path el) { this.el = el; Wait<WebDriver> wait = getWaiter(browser); try { wait.until(ExpectedConditions.visibilityOf(browser.find(el))); return true; } catch (Throwable e) { return false; } } }; }  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 isDisplayedFailed() { when(browser.isDisplayed(div)).thenReturn(false); try { assertThat(div, CustomMatchers.isDisplayedIn(browser)); fail("should fail"); } catch (AssertionError e) { assertThat(e.getMessage(), is(equalTo("\nExpected: div is displayed\n but: div is not displayed"))); } }