AssertsUtil - dn0000001/test-automation GitHub Wiki
The AssertsUtil class contains custom matchers not part of org.hamcrest.Matchers but are useful.
Custom Matchers:
- Regular Expression matcher - AssertsUtil.matchesRegex
- Does NOT match Regular Expression matcher - AssertsUtil.doesNotMatchRegex
- Contains string ignoring case matcher - AssertsUtil.containsStringIgnoringCase
- Does not contain string ignoring case matcher - AssertsUtil.doesNotContainStringIgnoringCase
- Starts with ignoring case matcher - AssertsUtil.startsWithIgnoringCase
- Ends with ignoring case matcher - AssertsUtil.endsWithIgnoringCase
- Is Element Displayed matcher - AssertsUtil.isElementDisplayed
- Is Element Disabled matcher - AssertsUtil.isElementDisabled
- Is Element Enabled matcher - AssertsUtil.isElementEnabled
- Is Element Ready matcher - AssertsUtil.isElementReady
- Is Element Removed matcher - AssertsUtil.isElementRemoved
- Is Page Component Displayed matcher - AssertsUtil.isComponentDisplayed
- Is Page Component Disabled matcher - AssertsUtil.isComponentDisabled
- Is Page Component Enabled matcher - AssertsUtil.isComponentEnabled
- Is Page Component Ready matcher - AssertsUtil.isComponentReady
- Is Page Component Removed matcher - AssertsUtil.isComponentRemoved
Usage Examples:
-
Using the regular expression matcher
// Verify that the word 'something' is in the actual text
assertThat("Testing Something Interesting", AssertsUtil.matchesRegex(".*Something.*"));
-
Using the does not match regular expression matcher
// Verify that the word 'boring' is NOT in the actual text
assertThat("Testing Something Interesting", AssertsUtil.doesNotMatchRegex(".*boring.*"));
-
Using contains string ignoring case matcher
// Verify that the word 'test' ignoring case is in the actual text
assertThat("Testing Something Interesting", AssertsUtil.containsStringIgnoringCase("test"));
-
Using does not contain string ignoring case matcher
// Verify that the word 'boring' ignoring case is NOT in the actual text
assertThat("Testing Something Interesting", AssertsUtil.doesNotContainStringIgnoringCase("boring"));
-
Using starts with ignoring case matcher
// Verify that the word 'test' ignoring case is at the start of the actual text
assertThat("Testing Something Interesting", AssertsUtil.startsWithIgnoringCase("test"));
-
Using ends with ignoring case matcher
// Verify that the word 'interesting' ignoring case is at the end of the actual text
assertThat("Testing Something Interesting", AssertsUtil.endsWithIgnoringCase("interesting"));
-
Using element displayed matcher
// Verify that the element is displayed
assertThat("Element is displayed", element, AssertsUtil.isElementDisplayed());
-
Using element disabled matcher
// Verify that the element is disabled
assertThat("Element is disabled", element, AssertsUtil.isElementDisabled());
-
Using element enabled matcher
// Verify that the element is enabled
assertThat("Element is enabled", element, AssertsUtil.isElementEnabled());
-
Using element ready matcher
// Verify that the element is ready
assertThat("Element is ready", element, AssertsUtil.isElementReady());
-
Using element removed matcher
// Verify that the element is removed
assertThat("Element is removed", element, AssertsUtil.isElementRemoved());
-
Using page component displayed matcher
// Verify that the page component is displayed
assertThat("Page component is displayed", component, AssertsUtil.isComponentDisplayed());
-
Using page component disabled matcher
// Verify that the page component is disabled
assertThat("Page component is disabled", component, AssertsUtil.isComponentDisabled());
-
Using page component enabled matcher
// Verify that the page component is enabled
assertThat("Page component is enabled", component, AssertsUtil.isComponentEnabled());
-
Using page component ready matcher
// Verify that the page component is ready
assertThat("Page component is ready", component, AssertsUtil.isComponentReady());
-
Using page component removed matcher
// Verify that the page component is removed
assertThat("Page component is removed", component, AssertsUtil.isComponentRemoved());