We’ve already studied how several types of store can be useful in Selenium IDE automated testing, as well as other commands like click, type, open, or select. This time around, to wrap up the list of commonly used commands, let’s see how different kinds of verify form the checkpoints in our tests.
Note: verify commands have the same function as their assert counterparts. Their only difference is that verify commands allow the test to run the next command even if the verification test fails, while assert commands stop then and there.
- verifyText. If we want to check the correctness of text copies displayed on a page, we can use the verifyText command. We just need to target the element location of the copy and then add the pattern to which the copy will be compared with.
Selenium IDE lights up with colors when running verification (or assertion) tests: green for a successful test and ..
red for a failed test. In our failed test example below, you may notice that the pattern in the test and the copy displayed in the page do not match.
- verifyEval. We can run verification checks on texts/copies using the verifyEval command too, though this means that our test will have more lines because the pattern to which the copy will be compared is not written together with the verifyEval command. In its place is either a ‘true’ or ‘false’ result value, which will be compared to the result of the check that happens inside the target column. In our example, you may notice that the copy’s target location is not specified together with the verifyEval command as well. This means that there are often three lines of commands in order to verify if a copy on a page is correct.
- verifyElementPresent. Sometimes we want to check whether a particular element is on a page or not. To do that, we use the verifyElementPresent command.
If the element is there, even if it is hidden or disabled, Selenium will tell us that the test is successful.
On the other hand, our test will fail if the element we are checking is not to be found anywhere in the page.
Note: There is also a verifyElementNotPresent command, which does the opposite of the verifyElementPresent command.
- verifyVisible. We can also test if an element is visibly shown in a page or not by using the verifyVisible command. It behaves similarly to the verifyElementPresent command except that tests will fail if the element we are checking is in the page but hidden, like how popups are invisible unless a particular action happens. See example screenshots for successful and failed tests below.