• Selenium Video Tutorials

Selenium IDE - Assert/Verify Methods



Selenium IDE uses assert and verify methods to check if a certain text, element, page title, and so on matches with the requirements. These two methods basically help us to conclude if a test has passed or failed based on the verification points added (in the form of assert and verify commands).

What is an Assert Command?

In Selenium IDE, an assert command is used to verify if a certain situation is matching with the specification document. In case, they are not matching, the test execution stops at the point of a mismatch.

Example with Assert Command

Let us take an example of the below page, where we would capture the page title Selenium Practice Radio Button and check if the correct page title is displayed using the assert command.

Selenium Assert Verify 1

The steps to use an assert command are listed below −

Step 1 − Follow the Steps 1 to 4 as described in the link Selenium IDE Store Variables.

Step 2 − Enter open in the Command field, and Selenium Automation Practice Form in the Target field, to launch the application.

Step 3 − Enter store title in the Command field, and pageTitle in the Value field. Please note, pageTitle is variable to capture the title of the application launched.

Step 4 − Enter assert title in the Command field, ABC in the Target field. Please note, in this step we are verifying if the page tile is ABC.

Step 5 − Enter echo in the Command field, ${pageTitle} in the Target field. Please note, this would print the text we obtained in Step6 under the Log in Selenium IDE.

Step 6 − Enter close in the Command field to close the browser window.

Step 7 − Click on the three dots appearing at the left pane, then select the Rename option.

Step 8 − Enter a name, say Test6 under the Rename Test case field, then click on Rename. The entered name would appear on the left of Selenium IDE.

Step 9 − Click on the Run all tests from the top, and wait for the test execution to complete. In our example, we would see Runs: 1, Failures: 1, and a red bar denoting the test ran unsuccessfully with failures. Also, the message Test6 ended with 1 error(s) would appear under the Log.

Selenium Assert Verify 3

In the example above, we had obtained the page title which is Selenium Practice Radio Button. However, we had added the assert title command to check if the page title is equal to ABC. Hence the actual and the expected values did not match. Moreover, due to the assert command, the execution halted and the steps 4, and 5 did not execute.

What is a Verify Command?

In Selenium IDE, a verify command is also used to verify if a certain situation is matching with the specification document. In case, they are not matching, the test execution does not stop at the point of a mismatch. The error is captured at the Log in Selenium IDE and the steps after the error IS encountered also get executed.

Example with Verify Command

Let us take the same above example, where we would capture the page title Selenium Practice Radio Button and check if the correct page title is displayed using the verify command.

The steps to capture the browser title are listed below −

Step 1 − Follow the Steps 1 to 4 as described in the link Selenium IDE Store Variables.

Step 2 − Follow steps 2 and 3 from the previous example.

Step 3 − Enter verify title in the Command field, ABC in the Target field. Please note, in this step we are verifying if the page tile is ABC.

Step 4 − Follow steps 8,9, 10, 11, and 12 from the previous example.

Selenium Assert Verify 4

In the example above, we had obtained the page title which is Selenium Practice Radio Button. However, we had added the verify title command to check if the page title is equal to ABC. Hence the actual and the expected values did not match. Moreover, even after encountering failure in step3 the steps 4, and 5 executed and the execution did not stop in between, simultaneously, the error also got recorded under the Log.

Difference between Assert and Verify Commands

From the above examples, we can infer that both assert and verify commands can be used for verification purposes. But in case of errors encountered in a test, the execution stops at the failed step, and remaining steps do not get executed while assert command is used. However, the execution continued even after encountering a failed step, while we are using the verify command. The error encountered is also recorded under the Log in Selenium IDE for both the commands.

Conclusion

This concludes our comprehensive take on the tutorial on Selenium IDE Assert/Verify methods. We’ve started with describing what is an assert and a verify command in Selenium IDE, and walked through examples having an assert command and a verify command, illustrated how to use them, and the basic differences between the two commands along with Selenium. This equips you with in-depth knowledge of the assert and verify methods in Selenium IDE. It is wise to keep practicing what you’ve learned and exploring others relevant to Selenium to deepen your understanding and expand your horizons.

Advertisements