# Assertion or Verification?

Domains:

Choosing between "assert" and "verify" comes down to convenience and management of failures. There’s very little point checking that the first paragraph on the page is the correct one if your test has already failed when checking that the browser is displaying the expected page. If you're not on the correct page, you'll probably want to abort your test case so that you can investigate the cause and fix the issue(s) promptly. On the other hand, you may want to check many attributes of a page without aborting the test case on the first failure as this will allow you to review all failures on the page and take the appropriate action. Effectively an "assert" will fail the test and abort the current test case, whereas a "verify" will fail the test and continue to run the test case.

The best use of this feature is to logically group your test commands, and start each group with an "assert" followed by one or more "verify" test commands. An example follows:

The above example first opens a page and then "asserts" that the correct page is loaded by comparing the title with the expected value. Only if this passes will the following command run and "verify" that the image is present in the expected location.

The above example first opens a page and then "asserts" that the correct page is loaded by comparing the title with the expected value. Only if this passes will the following command run and "verify" that the image is present in the expected location.

### verifyElementPresent

Use this command when you must test for the presence of a specific UI element, rather than its content. This verification does not check the text, only the HTML tag. One common use is to check for the presence of an image.

This command verifies that an image, specified by the existence of an <img> HTML tag, is present on the page, and that it follows a <div> tag and a <p> tag. The first (and only) parameter is a locator for telling the Selenese command how to find the element. Locators are explained in the next section.

verifyElementPresent can be used to check the existence of any HTML tag within the page. You can check the existence of links, paragraphs, divisions <div>, etc. Here are a few more examples.

These examples illustrate the variety of ways a UI element may be tested. Again, locators are explained in the next section.

### verifyText

Use verifyText when both the text and its UI element must be tested.verifyText must use a locator. If you choose an XPath or DOM locator, you can verify that specific text appears at a specific location on the page relative to other UI components on the page.

Page structure