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..
'"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
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.
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.
Gr8 example..It helps me a lot. Thanks
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteGreat Example.
ReplyDeleteWhen 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
what will happen if i put on error resume next in above the option explicite and below the option explicite
ReplyDeletewhen 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
ReplyDeletevarious ways to insert a Action in a test in QTP?
ReplyDeletetypes of Parameters are there in QTP?
http://www.bestqtptraining.com/
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
ReplyDeleteJava 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.
ReplyDeletenice bLog! its interesting. thank you for sharing.... executive resume writing service
ReplyDeleteAs applicant tracking technologies have come into common use among headhunter firms, large corporations, and even mid-size and small businesses, recommended resume formats and methods of transmission have rapidly evolved with the advancing technologies.Resume Creator
ReplyDeleteStudents who are looking for online tuition in kolkata for CBSE, IB and State Board? Register at Ziyyara and get tutored online from the best home tutors in CBSE.
ReplyDeleteVisit Us:- https://ziyyara.in/home-tuition
Call Our Expert:- +91-9654271931