Posts: 18
Threads: 13
Joined: Oct 2012
Reputation:
0
04-11-2013, 04:23 AM
Hi
I currently have as my last step in qtp
Browser("aALIWeb").close
this will close the browser in qtp ... IF the test ends normally.
But, I have the setting that upon error, QTP should stop the run.
The run gets stopped in the middle of the test so the close is never
executed.
How can I have the browser be closed whether the test ends normally or by error? I need it closed so for the next test I can open a fresh copy and not have the state of the web page be wherever it left off before.
Posts: 1,003
Threads: 1
Joined: Jul 2009
Reputation:
5
04-11-2013, 06:54 AM
Well, thats the caveat when you have the tool take over the control. Ideally, when you stop an execution it should be controlled via the code, but nevertheless, QTP has the option so why not use it. However, it ends up like you can either have the egg or the chicken
Now since it is controlled by QTP and you cannot insert a code after the error occurs, the easiest would be to,
"Look for any open browsers and if they exist close them before a test execution Starts".
However, this would be a very primitive and not a best practice suggestion. The best way to do this is to handle errors in the code using the On Error Resume Next and then capturing those errors using Err.Number and logging them. This way you will have un-interrupted execution as well you know specifically the ones which failed.
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.
Posts: 18
Threads: 13
Joined: Oct 2012
Reputation:
0
04-11-2013, 08:03 PM
Thanks Basanth, I thought of closing open windows at the beginning of the test, but wouldn't that close itself too? I want the browser that gets open when the test starts to stay open.
Posts: 1,003
Threads: 1
Joined: Jul 2009
Reputation:
5
04-12-2013, 07:21 AM
(This post was last modified: 04-12-2013, 07:43 AM by basanth27.)
No it wouldnt. Here is what i meant,
First Line of code, before you do any action - Close all Open Browsers.
Second Line - Open your test browser.
This way, you will not close the current browser you have and it will ensure that the system is set to base state where everything starts clean.
No, It wouldnt. Here is what i meant,
1. Before you do anything, Close All the open browsers. This should be the first line of code.
2. Your subsequent lines should contain the test browser you intend to open.
Yes, This will after each test execution, will close the browser in action and open the new test browser.
In case if you know what is the possible error, then you could probably try the recovery scenario. But, It isint my good friend as it will slow down the test execution.
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.