Skip to content

Commit 8525aab

Browse files
committed
improve WebAssert, fix error messages, more detailed tests
1 parent 1e259e7 commit 8525aab

File tree

2 files changed

+128
-215
lines changed

2 files changed

+128
-215
lines changed

src/main/java/org/htmlunit/WebAssert.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private WebAssert() {
6363
*/
6464
public static void assertTitleEquals(final HtmlPage page, final String title) {
6565
final String s = page.getTitleText();
66-
if (!s.equals(title)) {
66+
if (!title.equals(s)) {
6767
final String msg = "Actual page title '" + s + "' does not match expected page title '" + title + "'.";
6868
throw new AssertionError(msg);
6969
}
@@ -157,7 +157,7 @@ public static void assertElementNotPresent(final HtmlPage page, final String id)
157157
catch (final ElementNotFoundException e) {
158158
return;
159159
}
160-
final String msg = "The page contains an element with ID '" + id + "'.";
160+
final String msg = "The page contains an element with ID '" + id + "' but should not.";
161161
throw new AssertionError(msg);
162162
}
163163

@@ -173,7 +173,8 @@ public static void assertElementNotPresentByXPath(final HtmlPage page, final Str
173173
final List<?> elements = page.getByXPath(xpath);
174174
if (!elements.isEmpty()) {
175175
final String msg = "The page contains " + elements.size()
176-
+ " element(s) matching the XPath expression '" + xpath + "'.";
176+
+ " element(s) matching the XPath expression '"
177+
+ xpath + "' but should not contain any.";
177178
throw new AssertionError(msg);
178179
}
179180
}
@@ -229,7 +230,7 @@ public static void assertTextPresentInElement(final HtmlPage page, final String
229230
*/
230231
public static void assertTextNotPresent(final HtmlPage page, final String text) {
231232
if (page.asNormalizedText().contains(text)) {
232-
final String msg = "The page contains the text '" + text + "'.";
233+
final String msg = "The page contains the text '" + text + "' but should not.";
233234
throw new AssertionError(msg);
234235
}
235236
}
@@ -246,7 +247,7 @@ public static void assertTextNotPresentInElement(final HtmlPage page, final Stri
246247
try {
247248
final HtmlElement element = page.getHtmlElementById(id);
248249
if (element.asNormalizedText().contains(text)) {
249-
final String msg = "The element with ID '" + id + "' contains the text '" + text + "'.";
250+
final String msg = "The element with ID '" + id + "' contains the text '" + text + "' but should not.";
250251
throw new AssertionError(msg);
251252
}
252253
}
@@ -289,7 +290,7 @@ public static void assertLinkNotPresent(final HtmlPage page, final String id) {
289290
try {
290291
page.getDocumentElement().getOneHtmlElementByAttribute("a", DomElement.ID_ATTRIBUTE, id);
291292
// Not expected.
292-
final String msg = "The page contains a link with ID '" + id + "'.";
293+
final String msg = "The page contains a link with ID '" + id + "' but should not.";
293294
throw new AssertionError(msg);
294295
}
295296
catch (final ElementNotFoundException expected) {
@@ -333,7 +334,7 @@ public static void assertLinkNotPresentWithText(final HtmlPage page, final Strin
333334
}
334335
}
335336
if (found) {
336-
final String msg = "The page contains a link with text '" + text + "'.";
337+
final String msg = "The page contains a link with text '" + text + "' but should not.";
337338
throw new AssertionError(msg);
338339
}
339340
}
@@ -371,7 +372,7 @@ public static void assertFormNotPresent(final HtmlPage page, final String name)
371372
catch (final ElementNotFoundException e) {
372373
return;
373374
}
374-
final String msg = "The page contains a form named '" + name + "'.";
375+
final String msg = "The page contains a form named '" + name + "' but should not.";
375376
throw new AssertionError(msg);
376377
}
377378

0 commit comments

Comments
 (0)