"verifyAlertPresent" Command
Alert testing with selenium is not very hard. In the Selenium IDE plug-in, there are many commands available related to verification. One of them is "verifyAlertPresent" for verification of alerts on the page. Sometimes, when you take some action on the page, it shows an alert message in a popup. If you want to verify that alert message
is appear on the page or not, you need to use the "verifyAlertPresent" and "verifyAlertNotPresent" commands.Read here what is the command associated with testing an alert
"verifyAlertPresent" will become pass if there is an alert message on the page and will return an error if there is no present alert on the page.
Here is an example of the "verifyAlertPresent" command where, when the user clicks on the "Try it now" button, it shows one alert message. Let us see how to verify that alert using Selenium IDE. In the below-given example, the first "verifyAlertPresent" command will pass because there is an alert message on the page (selenium has clicked on the "Try it now" button in the previous command "click"). But the second "verifyAlertPresent" command will return "[error] false" in the selenium log because selenium has closed the alert message in the previous command "assertAlert" so there is not any alert message on the page.
New Test | ||
Command | Target | Value |
open | http://www.javascripter.net/faq/alert.htm | |
click | css=input[type="button"] | |
verifyAlertPresent | ||
verifyAlertNotPresent | ||
assertAlert | Hello from JavaScript! | |
verifyAlertPresent | ||
verifyAlertNotPresent |
"verifyAlertNotPresent" Command
"verifyAlertNotPresent" Command has the same function as "verifyAlertPresent" Command. Only one difference is it will return "[error] true" in selenium log if there is alert present on page when selenium executing this command.
In above example, first "verifyAlertNotPresent" Command will return "[error] true" which describes that there is an alert on the page. Second "verifyAlertNotPresent" Command will becomes pass because on that stage there is not any alert present on page.
No comments:
Post a Comment