Difference between "verifyAlert" and "assertAlert" command in selenium

There are too many commands starting with "verify" and "assert" text. Both these commands are same excluding one difference and that difference is after execution of "verify" command if condition is match or not match selenium will execute next commands but in case of execution of "assert" command if condition
returns false then selenium will stop remaining command's execution.

Let me show you that difference with "verifyAlert" and "assertAlert" commands with examples. You can view "assertAlertNotPresent" and "assertAlertPresent" commands example here. Both these commands are also very useful in software testing using selenium IDE.

"verifyAlert" command

"verifyAlert" command will retrieves and verify alert message text and also it will take action on alert box. it will return error message if expected alert not displayed. Let's we see it with example.



New Test
CommandTargetValue
openhttp://www.w3schools.com/js/tryit.asp?filename=tryjs_alert
selectFrameview
clickcss=input[type="button"]
verifyAlertHello! I am an alert box!1
selectWindownull
assertTitleTryit Editor v1.6

In this example, verifyAlert will verify alert message text with text "Hello! I am an alert box!1". Here it will show error message in log because real text of alert box is "Hello! I am an alert box!". but even after error selenium will execute remaining 2 commands. Here it will not show you error in log if given text "Hello! I am an alert box!" at place of "Hello! I am an alert box!1" with verifyAlert command.

"assertAlert" command

Same as verifyAlert command, "assertAlert" will also verify text and take action on alert box but if alert text not matches then it will stop execution. See bellow given example.

New Test
CommandTargetValue
openhttp://www.w3schools.com/js/tryit.asp?filename=tryjs_alert
selectFrameview
clickcss=input[type="button"]
assertAlertHello! I am an alert box!1
selectWindownull
assertTitleTryit Editor v1.6

In this example, assertAlert command will show error because alert text "Hello! I am an alert box!1" is not matching with real alert text "Hello! I am an alert box!" and it will not execute remaining 2 commands.

3 comments:

  1. Nice post with great details. Thanks for sharing. Like it.

    emergency alert software

    ReplyDelete
  2. Can any one let me know how to create user defined alert in selenium IDE and how to record vertical and horizontal scroll in selenium IDE....

    ReplyDelete
    Replies
    1. To generate alert In selenium IDE, you can see bellow given link
      http://software-testing-tutorials-automation.blogspot.in/2013/11/selenium-ide-runscript-command-example.html

      Not get your second question properly about vertical and horizontal scroll. Please describe your scenario

      Delete