Selenium for testing alert on page using "verifyAlertPresent" and "verifyAlertNotPresent" command

"verifyAlertPresent" Command

Alert testing with selenium is not much hard. In Selenium IDE plug in, there are many commands available related to verify. One of them is "verifyAlertPresent" for verification of alert on the page. Some times, when you taking some action on page, it is showing alert message in popup. If you want to verify that alert message
is appear on page or not, you need to use "verifyAlertPresent" and "verifyAlertNotPresent" command.

"verifyAlertPresent" will becomes pass if there is an alert message on page and will return error if there is not present alert on page.

Here is an example of "verifyAlertPresent" command where, when user click on "Try it now" button, it is showing one alert message. Let we see how to verify that alert using selenium IDE. In bellow given example, first "verifyAlertPresent" command will becomes pass because there is an alert message on page (selenium has clicked on "Try it now" button in previous command "click"). But second "verifyAlertPresent" command will return "[error] false" in selenium log because selenium has closed alert message in previous command "assertAlert" so there is not any alert message on page.

New Test
assertAlertHello from JavaScript!

"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