Pages

Wednesday, March 2

How "On Error Resume Next" can be a problem in QTP?

In this post, we will look into the use of Error Handling in QTP.

'"On Error Resume Next" is used to handle errors in vbscript/QTP and usually very helpful. But many times, it might give you  unexpected outcomes. Let's see how..

Example 1:

Function Example(var1 , var2)
On Error Resume Next
Example = var1/var2
On Error GOTO 0
End Function
msgbox Example(2, 0)

Run this code and see the result.

Result - Blank value is returned because of  'On Error Resume Next', which is incorrect! If  'On Error Resume Next' was not there, it would have return an error code - 11, as division by zero.

Consider the situation where you are passing the above output as an input is some other function as input! What'll happen? Whole your test will be doing something unexpected and you will end up with nothing other then confusions and looking in the code for What went wrong..... :)



Example 2:

Assume either because of some issue or unexpected behavior of the application, 'Login' button is not displayed.

Now, if you run below code--

On Error Resume Next
Browser("mybrowser").Page("mypage").WebEdit("loginname").Set "abhikansh"
Browser("mybrowser").Page("mypage").WebEdit("password").SetSecure "mypass"
Browser("mybrowser").Page("mypage").WebButton("login").click
wait 2
Browser("mybrowser").Page("NEWPAGE").WebLink("NEXT").click

Expected Result: When you click on Login button, it should navigate to next page, where it will click on NEXT link.


Actual Result : Even though the Login button is not displayed on the page, there will be no runtime error and because steps inside the 'On error resume next'. It will try to click on NEXT link, which is not appeared.

It will keep executing all the following steps of the script without any error. But actually it will not achieve anything because application is still stuck on first page.

So what's the lesson? Shall I avoid to use 'On error resume next'?

No. Not at all! But be very careful while using.


Remember.. "On Error Resume Next" is useful when you intentionally don't want to let errors occur i.e. any temporary browser specific error or printer error which is not about AUT (application under test), but as explained in above examples, it may work in wrong direction if not used properly.

In case of any queries, please leave your comments.

10 comments:

  1. Gr8 example..It helps me a lot. Thanks

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Great Example.

    When I run my script, there is excel file opens up from the web. How can I close that Excel sheet generated while executing. The recorded script doesn't click on the excel file to close it. Please give me some idea. Thanks!

    RB

    ReplyDelete
  4. what will happen if i put on error resume next in above the option explicite and below the option explicite

    ReplyDelete
  5. when you have simply just graduated through school it is likely you will not have the desired practical knowledge. The following you need to generate the skill-sets you garnered in your internship, volunteer practical knowledge as well as other extracurricular routines best functional resume template

    ReplyDelete
  6. various ways to insert a Action in a test in QTP?
    types of Parameters are there in QTP?

    http://www.bestqtptraining.com/

    ReplyDelete
  7. Recently there has been a dramatic surge in the number of people requesting Federal Resume Writing and KSA document preparation. My own personal theory is that given the current state of the economy people are seeking a more stable form of employment and one that pretty much ensures no layoffs. federal resume service

    ReplyDelete
  8. Good information to know and right to the point on career. Thanks for this well written post related to search jobs , i’ll follow up for more updates if you keep posting them.

    ReplyDelete
  9. Java is the major vernacular of the coding which help us with doing various kind of creators. Moreover, may be this whole is useful for us and may be it is astoundingly troublesome for our piece forming. However, we are endeavoring to do http://www.resumeexamples2017.com/resume-examples-accounting-2017/ for our work and tihis moreover bravo.

    ReplyDelete