public static void assertThrowsAssertionError(Consumer<Void> functionThatThrowsException, String expectedMessage) { try { functionThatThrowsException.accept(null); fail("A SeleniumQueryAssertionError was expected but not thrown."); } catch (SeleniumQueryAssertionError e) { assertEquals(expectedMessage, e.getMessage()); } }
@Test @JavaScriptEnabledOnly public void matches__pattern_fails_assertThat() { try { $(".visibleDiv").assertThat().html().matches(Matchers.containsString("isibleDix")); fail(); } catch (SeleniumQueryAssertionError e) { assertEquals("Failed assertion $(\".visibleDiv\").assertThat().html().matches(<a string containing \"isibleDix\">).\n\n" + "expected: <html() to be <a string containing \"isibleDix\">>\n" + "but: <html() was \"!visibleDiv!\">", e.getMessage()); } }
@Test @JavaScriptEnabledOnly public void matches__NOT_pattern_fails_assertThat() { try { $(".visibleDiv").assertThat().html().not().matches(Matchers.containsString("isibleDi")); fail(); } catch (SeleniumQueryAssertionError e) { assertEquals("Failed assertion $(\".visibleDiv\").assertThat().html().not().matches(<a string containing \"isibleDi\">).\n\n" + "expected: <html() not to be <a string containing \"isibleDi\">>\n" + "but: <html() was \"!visibleDiv!\">", e.getMessage()); } }
@Test public void matches__pattern_fails_assertThat() { try { $("div").assertThat().text().matches(zzzPattern); fail(); } catch (SeleniumQueryAssertionError e) { assertEquals("Failed assertion $(\"div\").assertThat().text().matches(\"Z{3}\").\n\n" + "expected: <text() to match Pattern \"Z{3}\">\n" + "but: <text() was \"aaa bbb\">", e.getMessage()); } }
@Test public void matches__NOT_pattern_fails_assertThat() { try { $("div").assertThat().text().not().matches(abCaseInsensitive); fail(); } catch (SeleniumQueryAssertionError e) { assertEquals("Failed assertion $(\"div\").assertThat().text().not().matches(\"A{3} B{3}\").\n\n" + "expected: <text() not to match Pattern \"A{3} B{3}\">\n" + "but: <text() was \"aaa bbb\">", e.getMessage()); } }