public final class WebAssert extends Object
This class provides a collection of static assertion methods for testing
HTML page content, structure, and behavior. All assertion methods throw
AssertionError
when the expected condition is not met.
Common use cases include:
Modifier and Type | Method and Description |
---|---|
static void |
assertAllAccessKeyAttributesUnique(HtmlPage page)
Many HTML components can have an
accesskey attribute which defines a hot key for
keyboard navigation. |
static void |
assertAllIdAttributesUnique(HtmlPage page)
Verifies that all element IDs in the specified page are unique.
|
static void |
assertAllTabIndexAttributesSet(HtmlPage page)
Many HTML elements are "tabbable" and can have a
tabindex attribute
that determines the order in which the components are navigated when
pressing the tab key. |
static void |
assertElementNotPresent(HtmlPage page,
String id)
Verifies that the specified page does not contain an element with the specified ID.
|
static void |
assertElementNotPresentByXPath(HtmlPage page,
String xpath)
Verifies that the specified page does not contain an element matching the specified XPath
expression.
|
static void |
assertElementPresent(HtmlPage page,
String id)
Verifies that the specified page contains an element with the specified ID.
|
static void |
assertElementPresentByXPath(HtmlPage page,
String xpath)
Verifies that the specified page contains an element matching the specified XPath expression.
|
static void |
assertFormNotPresent(HtmlPage page,
String name)
Verifies that the specified page does not contain a form with the specified name.
|
static void |
assertFormPresent(HtmlPage page,
String name)
Verifies that the specified page contains a form with the specified name.
|
static void |
assertInputContainsValue(HtmlPage page,
String name,
String value)
Verifies that the input element with the specified name on the specified page contains the
specified value.
|
static void |
assertInputDoesNotContainValue(HtmlPage page,
String name,
String value)
Verifies that the input element with the specified name on the specified page does not
contain the specified value.
|
static void |
assertInputNotPresent(HtmlPage page,
String name)
Verifies that the specified page does not contain an input element with the specified name.
|
static void |
assertInputPresent(HtmlPage page,
String name)
Verifies that the specified page contains an input element with the specified name.
|
static void |
assertLinkNotPresent(HtmlPage page,
String id)
Verifies that the specified page does not contain a link with the specified ID.
|
static void |
assertLinkNotPresentWithText(HtmlPage page,
String text)
Verifies that the specified page does not contain a link with the specified text.
|
static void |
assertLinkPresent(HtmlPage page,
String id)
Verifies that the specified page contains a link with the specified ID.
|
static void |
assertLinkPresentWithText(HtmlPage page,
String text)
Verifies that the specified page contains a link with the specified text.
|
static void |
assertTextNotPresent(HtmlPage page,
String text)
Verifies that the specified page does not contain the specified text.
|
static void |
assertTextNotPresentInElement(HtmlPage page,
String text,
String id)
Verifies that the element on the specified page which matches the specified ID does not
contain the specified text.
|
static void |
assertTextPresent(HtmlPage page,
String text)
Verifies that the specified page contains the specified text.
|
static void |
assertTextPresentInElement(HtmlPage page,
String text,
String id)
Verifies that the element on the specified page which matches the specified ID contains the
specified text.
|
static void |
assertTitleContains(HtmlPage page,
String titlePortion)
Verifies that the specified page's title contains the specified substring.
|
static void |
assertTitleEquals(HtmlPage page,
String title)
Verifies that the specified page's title equals the specified expected title.
|
static void |
assertTitleMatches(HtmlPage page,
String regex)
Verifies that the specified page's title matches the specified regular expression.
|
static void |
notNull(String description,
Object object)
Assert that the specified parameter is not null.
|
public static void assertTitleEquals(HtmlPage page, String title)
page
- the page to checktitle
- the expected titleAssertionError
- if the page title does not match the expected titleNullPointerException
- if page or title is nullpublic static void assertTitleContains(HtmlPage page, String titlePortion)
page
- the page to checktitlePortion
- the substring which the page title is expected to containAssertionError
- if the page title does not contain the substringNullPointerException
- if page or titlePortion is nullpublic static void assertTitleMatches(HtmlPage page, String regex)
page
- the page to checkregex
- the regular expression that the page title is expected to matchAssertionError
- if the page title does not match the regular expressionNullPointerException
- if page or regex is nullpublic static void assertElementPresent(HtmlPage page, String id)
page
- the page to checkid
- the ID of an element expected in the pageAssertionError
- if no element with the specified ID is foundNullPointerException
- if page or id is nullpublic static void assertElementPresentByXPath(HtmlPage page, String xpath)
Example usage:
WebAssert.assertElementPresentByXPath(page, "//div[@class='error']");
WebAssert.assertElementPresentByXPath(page, "//input[@type='submit' and @value='Login']");
page
- the page to checkxpath
- the XPath expression which is expected to match an element in the pageAssertionError
- if no elements match the XPath expressionNullPointerException
- if page or xpath is nullpublic static void assertElementNotPresent(HtmlPage page, String id)
page
- the page to checkid
- the ID of an element which is expected to not exist on the pageAssertionError
- if an element with the specified ID is foundNullPointerException
- if page or id is nullpublic static void assertElementNotPresentByXPath(HtmlPage page, String xpath)
page
- the page to checkxpath
- the XPath expression which is expected to not match any element in the pageAssertionError
- if any elements match the XPath expressionpublic static void assertTextPresent(HtmlPage page, String text)
page
- the page to checktext
- the text to check forAssertionError
- if the page does not contain the specified textNullPointerException
- if page or text is nullpublic static void assertTextPresentInElement(HtmlPage page, String text, String id)
page
- the page to checktext
- the text to check forid
- the ID of the element which is expected to contain the specified textAssertionError
- if the element does not contain the specified textElementNotFoundException
- if no element with the specified ID existsNullPointerException
- if any parameter is nullpublic static void assertTextNotPresent(HtmlPage page, String text)
page
- the page to checktext
- the text to check forAssertionError
- if the page contains the specified textNullPointerException
- if page or text is nullpublic static void assertTextNotPresentInElement(HtmlPage page, String text, String id)
page
- the page to checktext
- the text to check forid
- the ID of the element which is expected to not contain the specified textpublic static void assertLinkPresent(HtmlPage page, String id)
page
- the page to checkid
- the ID of the link which the page is expected to containAssertionError
- if no link with the specified ID is foundassertLinkNotPresent(HtmlPage, String)
,
assertLinkPresentWithText(HtmlPage, String)
public static void assertLinkNotPresent(HtmlPage page, String id)
page
- the page to checkid
- the ID of the link which the page is expected to not containAssertionError
- if a link with the specified ID is foundassertLinkPresent(HtmlPage, String)
,
assertLinkNotPresentWithText(HtmlPage, String)
public static void assertLinkPresentWithText(HtmlPage page, String text)
page
- the page to checktext
- the text which a link in the specified page is expected to containpublic static void assertLinkNotPresentWithText(HtmlPage page, String text)
page
- the page to checktext
- the text which a link in the specified page is not expected to containpublic static void assertFormPresent(HtmlPage page, String name)
page
- the page to checkname
- the expected name of a form on the pageAssertionError
- if no form with the specified name is foundassertFormNotPresent(HtmlPage, String)
public static void assertFormNotPresent(HtmlPage page, String name)
page
- the page to checkname
- the name of a form which should not exist on the pageAssertionError
- if a form with the specified name is foundassertFormPresent(HtmlPage, String)
public static void assertInputPresent(HtmlPage page, String name)
page
- the page to checkname
- the name of the input element to look forAssertionError
- if no input element with the specified name is foundassertInputNotPresent(HtmlPage, String)
,
assertInputContainsValue(HtmlPage, String, String)
public static void assertInputNotPresent(HtmlPage page, String name)
page
- the page to checkname
- the name of the input element to look forAssertionError
- if an input element with the specified name is foundNullPointerException
- if page or name is nullpublic static void assertInputContainsValue(HtmlPage page, String name, String value)
page
- the page to checkname
- the name of the input element to checkvalue
- the value to check forpublic static void assertInputDoesNotContainValue(HtmlPage page, String name, String value)
page
- the page to checkname
- the name of the input element to checkvalue
- the value to check forpublic static void assertAllTabIndexAttributesSet(HtmlPage page)
Many HTML elements are "tabbable" and can have a tabindex
attribute
that determines the order in which the components are navigated when
pressing the tab key. To ensure good usability for keyboard navigation,
all tabbable elements should have the tabindex
attribute set.
This method verifies that all tabbable elements have a valid value set for
the tabindex
attribute. Valid values are positive integers,
0 (for default tab order), or -1 (to exclude from tab order).
The following elements are checked: a, area, button, input, object, select, textarea
page
- the page to checkAssertionError
- if any tabbable element has an invalid or missing tabindex attributepublic static void assertAllAccessKeyAttributesUnique(HtmlPage page)
accesskey
attribute which defines a hot key for
keyboard navigation. This method verifies that all the accesskey
attributes on the
specified page are unique.
Duplicate access keys can confuse users and make keyboard navigation unpredictable.
page
- the page to checkAssertionError
- if any access key is used more than once on the pagepublic static void assertAllIdAttributesUnique(HtmlPage page)
page
- the page to checkAssertionError
- if any element ID is used more than once on the pageNullPointerException
- if page is nullpublic static void notNull(String description, Object object)
description
- the description to pass into the NullPointerExceptionobject
- the object to check for nullNullPointerException
- if the object is nullCopyright © 2002–2025 Gargoyle Software Inc.. All rights reserved.