Assertion or Verification?
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:
| Command |
Target |
Value |
| open |
/download/ |
|
| assertTitle |
Downloads |
|
| verifyText |
//h2 |
Downloads |
| assertTable |
1.2.1 |
Selenium IDE |
| verifyTable |
1.2.2 |
June 3, 2008 |
| verifyTable |
1.2.3 |
1.0 beta 2 |
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 text is present in the
expected location. The test case then “asserts” the first column in the second
row of the first table contains the expected value, and only if this passed will
the remaining cells in that row be “verified”.
verifyTextPresent
The command
verifyTextPresent is used to verify
specific text exists
somewhere on the page. It takes a single argument–the text pattern to be
verified. For example:
| Command |
Target |
Value |
| verifyTextPresent |
Marketing Analysis |
|
This would cause Selenium to search for, and verify, that the text string
“Marketing Analysis” appears somewhere on the page currently being tested. Use
verifyTextPresent when you are interested in only the text
itself being present on the page. Do not use this when you also need to test
where the text occurs on the page.
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.
| Command |
Target |
Value |
| verifyElementPresent |
//div/p/img |
|
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.
| Command |
Target |
Value |
| verifyElementPresent |
//div/p |
|
| verifyElementPresent |
//div/a |
|
| verifyElementPresent |
id=Login |
|
| verifyElementPresent |
link=Go to Marketing Research |
|
| verifyElementPresent |
//a[2] |
|
| verifyElementPresent |
//head/title |
|
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.
| Command |
Target |
Value |
| verifyText |
//table/tr/td/div/p |
This is my text and it occurs right after the div inside the table. |
No comments:
Post a Comment