• 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.

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 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 − Click on the Selenium IDE extension visible on the browser after its installation.

Step 2 − Selenium IDE should be launched along with it, a welcome message should be displayed with the version of the tool. In the below image, the version installed is 3.17.2.

Along with this, it gives us the option to select what we would like to do with the tool, like Record a new test in a new project, Open an existing project, Create a new project, and Close Selenium IDE.

Also, a link with the text - the Selenium IDE project page is provided, which on clicking would land us to the Selenium Integrated Development Environment documentation page.

https://www.selenium.dev/selenium-ide/.

Selenium Assert Verify 2

Step 3 − Click on the Create a new project link, then enter a project name, say, Test6 under the Please provide a name for your new project. Finally, we would click on the OK button.

Step 4 − We would have the workspace ready in the Selenium IDE now.

Step 5 − Enter open in the Command field, and https://www.tutorialspoint.com/selenium/ in the Target field, to launch the application.

Step 6 − 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 7 − 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 8 − 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 9 − Enter close in the Command field to close the browser window.

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

Step 11 − 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 12 − 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.

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 steps 1 to 6 from the previous example.

Step 2 − 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 3 − 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.

What is the 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.

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