Skip to main content

Element Validations

Difference between assertThat() and verifyThat():

Assertions and Verification testing are important components in GUI automation testing. Each one performs a specific role:

  1. In Assertions, if the assert is not met, test case execution will be aborted and the rest of the test cases will be skipped, with the test case execution result marked as failed. Assertions are used as checkpoints for testing or validating business-critical transactions. This type of assertion is called Hard Assertion.
  2. In Verifications, even if the verification is not met, test case execution will continue to run until the last test is executed. The errors that may be found will be reported at the end of the test suite. This type of verification is called Soft Assertion.

Text Validations

text().isEqualTo()

Validates that the text of the element exactly matches the expected value.

driver.element().assertThat(elementLocator).text().isEqualTo("Expected Text").perform();
driver.element().verifyThat(elementLocator).text().isEqualTo("Expected Text").perform();

text().equalsIgnoringCaseSensitivity()

Validates that the text of the element matches the expected value without considering case sensitivity (capital or lowercase letters).

driver.element().assertThat(elementLocator).text().equalsIgnoringCaseSensitivity("Expected Text").perform();
driver.element().verifyThat(elementLocator).text().equalsIgnoringCaseSensitivity("Expected Text").perform();

textTrimmed()

Validates against the provided element's text attribute after it's trimmed (all leading and trailing whitespace removed).

driver.element().assertThat(elementLocator).textTrimmed().equalsIgnoringCaseSensitivity("Expected Text").perform();
driver.element().verifyThat(elementLocator).textTrimmed().equalsIgnoringCaseSensitivity("Expected Text").perform();

Element Existence

exists()

Use this to check that the target element exists

driver.element().assertThat(elementLocator).exists().perform();
driver.element().verifyThat(elementLocator).exists().perform();

doesNotExist()

Use this to check that the target element does not exist

driver.element().assertThat(elementLocator).doesNotExist().perform();
driver.element().verifyThat(elementLocator).doesNotExist().perform();

Element States

isChecked()

Use this to check against the provided elements checked attribute

driver.element().assertThat(elementLocator).isChecked().perform();
driver.element().verifyThat(elementLocator).isChecked().perform();

isNotChecked()

Use this to check against the provided elements checked attribute

driver.element().assertThat(elementLocator).isNotChecked().perform();
driver.element().verifyThat(elementLocator).isNotChecked().perform();

isDisabled()

Use this to check that the element is disabled.

driver.element().assertThat(elementLocator).isDisabled().perform();
driver.element().verifyThat(elementLocator).isDisabled().perform();

isEnabled()

Use this to check that the element is enabled.

driver.element().assertThat(elementLocator).isEnabled().perform();
driver.element().verifyThat(elementLocator).isEnabled().perform();

isVisible()

Use this to check that the element is visible.

driver.element().assertThat(elementLocator).isVisible().perform();
driver.element().verifyThat(elementLocator).isVisible().perform();

isHidden()

Use this to check that the element is hidden.

driver.element().assertThat(elementLocator).isHidden().perform();
driver.element().verifyThat(elementLocator).isHidden().perform();

isSelected()

Use this to check against the provided elements selected attribute

driver.element().assertThat(elementLocator).isSelected().perform();
driver.element().verifyThat(elementLocator).isSelected().perform();

isNotSelected()

Use this to check against the provided elements selected attribute

driver.element().assertThat(elementLocator).isNotSelected().perform();
driver.element().verifyThat(elementLocator).isNotSelected().perform();

Attributes Validations

attribute()

Use this to check against a certain element attribute

driver.element().assertThat(elementLocator).attribute("name").isEqualTo("expected value").perform();
driver.element().verifyThat(elementLocator).attribute("name").isEqualTo("expected value").perform();