• Selenium Video Tutorials

Selenium IDE - Assertions Commands



Every command used in Selenium IDE is known as the Selenese commands. Using the Selenese commands we perform all the testing activities on a web application. Selenese commands are of three types −

  • Actions − The action commands are used to manipulate the state of the application under test. For example, click, type, open, close, and so on.

  • Accessors − The accessor commands are used to assess the state of the application under test and store it in variables. For example, store title, store text, and store value.

  • Assertions − The assertion commands are used to check the state of the application under test. It has three sub-types namely, assert, verify, and waitfor.

Basic Assertions Commands

The various types of assertions commands are listed below −

  • assert(variable, expected value) − This command is used to verify if the variable is matching the expected value. The variable is converted to string for comparison. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert alert(alert text) − This command is used to verify if an alert has the text matching the alert text. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert checked(locator) − This command is used to verify if the target element with the locator value is checked. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert confirmation(text) − This command is used to verify if a confirmation has been rendered. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert editable(locator) − This command is used to verify if the target element with the locator value is editable. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert element present(locator) − This command is used to verify if the target element with the locator value is available on the web page. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert element not present(locator) − This command is used to verify if the target element with the locator value is not available on the web page. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert not checked(locator) − This command is used to verify if the target element with the locator value is not checked. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert not editable(locator) − This command is used to verify if the target element with the locator value is not editable. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert not selected value(locator, text) − This command is used to verify if the value attribute of the selected option of the target dropdown element does not have the given text. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert not text(locator, text) − This command is used to verify if the target element with the locator value does not have the given text.

  • assert prompt(text) − This command is used to verify if a prompt has been rendered. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert selected value(locator, text) − This command is used to verify if the value attribute of the selected option of the target dropdown element has the given text. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert selected label(locator, text) − This command is used to verify if the label of the selected option of the target dropdown element has the given text. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert text(locator, text) − This command is used to verify if the target element with the locator value has the given text. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert title(text) − This command is used to verify if the web page has the given text. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert value(locator, text) − This command is used to verify the value of an edit box. For a radio button/checkbox, the value will be set to on/off provided it is selected or not. If assert did not pass, then the execution will stop at the point of mismatch.

  • verify(variable, expected value) − This command is used to verify if the variable is matching the expected value. The variable is converted to string for comparison. It is a soft assert and execution will not stop in case of a mismatch.

  • verify checked(locator) − This command is used to verify if the target element with the locator value is checked. It is a soft assert and execution will not stop in case of a mismatch.

  • verify editable(locator) − This command is used to verify if the target element with the locator value is editable. It is a soft assert and execution will not stop in case of a mismatch.

  • verify element present(locator) − This command is used to verify if the target element with the locator value is available on the web page. It is a soft assert and execution will not stop in case of a mismatch.

  • verify element not present(locator) − This command is used to verify if the target element with the locator value is not available on the web page. It is a soft assert and execution will not stop in case of a mismatch.

  • verify not editable(locator) − This command is used to verify if the target element with the locator value is not editable. It is a soft assert and execution will not stop in case of a mismatch.

  • verify not selected value(locator, text) − This command is used to verify if the value attribute of the selected option of the target dropdown element does not have the given text. It is a soft assert and execution will not stop in case of a mismatch.

  • verify not text(locator, text) − This command is used to verify if the target element with the locator value does not have the given text. It is a soft assert and execution will not stop in case of a mismatch.

  • verify selected label(locator, text) − This command is used to verify if the label of the selected option of the target dropdown element has the given text. It is a soft assert and execution will not stop in case of a mismatch.

  • verify selected value(locator, text) − This command is used to verify if the value attribute of the selected option of the target dropdown element has the given text. It is a soft assert and execution will not stop in case of a mismatch.

  • verify text(locator, text) − This command is used to verify if the target element with the locator value has the given text. It is a soft assert and execution will not stop in case of a mismatch.

  • assert title(text) − This command is used to verify if the web page has the given text. It is a soft assert and execution will not stop in case of a mismatch.

  • verify value(locator, text) − This command is used to verify the value of an edit box. For a radio button/checkbox, the value will be set to on/off provided it is selected or not. It is a soft assert and execution will not stop in case of a mismatch.

  • wait for element editable(locator, wait time) − This command is used to wait for the given wait time(in milliseconds) for the target element with the locator value to be editable.

  • wait for element not editable(locator, wait time) − This command is used to wait for the given wait time(in milliseconds) for the target element with the locator value not to be editable.

  • wait for element not present(locator, wait time) − This command is used to wait for the given wait time(in milliseconds) for the target element with the locator value to be unavailable on the web page.

  • wait for element not visible(locator, wait time) − This command is used to wait for the given wait time(in milliseconds) for the target element with the locator value to be invisible on the web page.

  • wait for element present(locator, wait time) − This command is used to wait for the given wait time(in milliseconds) for the target element with the locator value to be available on the web page.

  • wait for element visible(locator, wait time) − This command is used to wait for the given wait time(in milliseconds) for the target element with the locator value to be visible on the web page.

Example

Let us take an example of the below page, where we would click on the Created link.

Selenium Assertions Commands 1

We would verify its page title which is Selenium Practice - Links. After clicking the Created link, we would also verify the text - Link has responded with status 201 and status text Created.

Selenium Assertions Commands 2

The steps to be followed 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 Assertions Commands 3

Step 3 − Click on the Create a new project link, then enter a project name, say, Test8 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.

Selenium Assertions Commands 4

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 verify title in the Command field and Selenium Practice - Links in the Target field.

Step 7 − Enter click in the Command field, xpath=//*[@id="created"] in the Target field. Please note, xpath=//*[@id="created"] is the locator value of the link.

Step 8 − Enter wait for element visible in the Command field, xpath=/html/body/main/div/div/div[2]/div[1] in the Target field and 30000 in the Value field. Please note, xpath=/html/body/main/div/div/div[2]/div[1] is the locator value of the text to be visible.

Step 9 − Enter assert text in the Command field, xpath=/html/body/main/div/div/div[2]/div[1] in the Target field and Link has responded with status 201 and status text Created in the Value field. Please note, xpath=/html/body/main/div/div/div[2]/div[1] is the locator value of the text.

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

Selenium Assertions Commands 5

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

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

Step 13 − 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: 0, and a green bar denoting the test ran successfully without any failures. Also, the message that the completed successfully appeared under the Log.

Selenium Assertions Commands 6

In the example above, we had launched the application and verified its page title - Selenium Practice - Links using the assertions command verify title. Then clicked on the Created link, and waited for text Link has responded with status 201 and status text Created to be visible with the assertion command wait for element visible and verified the text with another assertion command assert text.

Apart from that, all the test steps, along with the test case name turned green, reflecting a PASS for all the steps. All the steps which reflected under the Log tab, showed an OK in green.

This concludes our comprehensive take on the tutorial on Selenium IDE - Assertion Commands. We’ve started with describing various assertions commands and an example to walk through how to use the assertions commands along with Selenium. This equips you with in-depth knowledge of the assertions commands 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