Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pause script with code
#1
Solved: 11 Years, 3 Months, 3 Weeks ago Exclamation 
I know this has been discussed in other posts but I haven't found what I am looking for.
I have a recovery scenario that calls a function on any run error. This function send out an email and displays a message box with error details. Problem is, when I click ok on the message box the test takes off again. I want the test to pause so I can see what caused the error.
I have tried using Stop, but that only works inside a test, it is ignored if in a function. I have also tried the below code, which works inside a test but errors when in a function.
Code:
Dim App 'As Application
Set App = CreateObject("QuickTest.Application")
App.Test.Pause

I would like to learn how to do 1 of the 2 options below.
Pause a test or insert a breakpoint with code.
Or
Call a recovery scenario and then once the function completes, still get the QTP Run Error message box which would then let me click Debug.

I have been working on this for a long time.
Thanks in Advance!
Reply
#2
Solved: 11 Years, 3 Months, 3 Weeks ago
Would something like this work?
Code:
Dim App
Set App = CreateObject("QuickTest.Application")
App.Test.pause
App.Test.Run
Reply
#3
Solved: 11 Years, 3 Months, 3 Weeks ago
App.Test.Pause will pause a test if it is used inside a test. App.Test.Pause will NOT work if used inside a function, which is where I need the test to pause. I can't use it inside the test because I woudln't know where to put it because the test could error anywhere. I need the test to pause in the function becasue the function is called on Any Run Error.
Thanks
Reply
#4
Solved: 11 Years, 3 Months, 3 Weeks ago
when you create a recovery scenario, one of the things it lets you define is the "Post-Recovery Test Run Options". The instructions on this page say, "select the test run operation you want to perform when the recovery operation is complete".

The choices are:
1) Repeat current step and continue
2) Proceed to next step
3) proceed to next action or component iteration
4) proceed to next test iteration
5) restart current test
6) stop the test run

I'm thinking you could select option #1 here - repeat the current test step.

In your recovery function, just before exiting the function, you could do this (this is taken from the QTP help on "Recovery Object", "Define a recovery Scenario" and modified a little bit):


'************************************************************************************************************************
'Description:
'
'This example uses the Recovery collection to specify a set of
'recovery scenarios to associate with a new test.
'
'Assumptions:
'There is no unsaved test currently open in QuickTest.
'For more information, see the example for the Test.SaveAs method.
'************************************************************************************************************************

Code:
Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtTestRecovery 'As QuickTest.Recovery ' Declare a Recovery object variable
Dim intIndex ' Declare an index variable

' Open QuickTest and prepare objects variables
Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object

Set qtTestRecovery = qtApp.Test.Settings.Recovery ' Return the Recovery object for the current test

' Disable all scenarios
For intIndex = 1 To qtTestRecovery.Count ' Iterate the scenarios
    qtTestRecovery.Item(intIndex).Disabled = True ' Disable each Recovery Scenario (Note: the 'Item' property is default and can be omitted)
Next

' Enable the recovery mechanism (with default, on errors, setting)
qtTestRecovery.Enabled = True

'Ensure that the recovery mechanism is set to be activated only after errors
qtTestRecovery.SetActivationMode "OnError"
'OnError is the default, the other option is "OnEveryStep".

Set qtApp = Nothing ' Release the Application object
Set qtTestRecovery = Nothing ' Release the Recovery


How this would work: you've defined your recovery scenario for the test already. Modify your existing recovery scenario definition and set "Post-Recovery Test Run Options" to "Repeat current step and continue". In the Run Settings for your test (from QTP select File->Settings and select "Run" from the "Test Settings" window. In the run Properties window, set "When error occurs during run session" to "pop up message box".

When the error occurs in your test, it calls your recovery function. The recover function does whatever you told it to do (sends an email, I guess), then (in this example) disables all recovery scenarios for this test only. When the recover function exits, it does the post-recover test run options and re-runs the step that failed. Your recovery function is disabled now, so when the QTP re-runs the current step it will throw an error but not call the recovery function. This error will cause it to display the usual error pop-up message box that lets you stop, retry, debug, or continue.

I haven't actually tried all this, but it seems like this should/might work. Let me know how it goes.
Reply
#5
Solved: 11 Years, 3 Months, 3 Weeks ago
tdevick
I like where you are going with this, the only question I have right now is what will happen if the test errors again? The recovery scenario was not turned back on so I will only get the pop-up and my function will not run, correct?
I have not put this into my test yet but will be shortly. Hopefully it will all come together when I am adding to my function.
I think this is getting me much closer (if not all the way there), thanks and I will let you know how it goes.
Reply
#6
Solved: 11 Years, 3 Months, 3 Weeks ago
Have you looked PopUp method of shell object...
Code:
Shell=CreateObject("Wscript.Shell")
iMessageType = 0
Select Case sStatus
            Case "Fail"
                iMessageType = 16
            Case "Warning"
                iMessageType = 48
            Case Else
                iMessageType = 64
End Select
iResult = Shell.PopUp(sMessage , 5 , "Your message ", iMessageType)
'press the OK button to pause the script.
If iResult = 1 Then
   'paused then vbscript message box
MsgBox sOriginalMessage & vbCrLf & vbCrLf & "Automation Paused - Press OK to continue", , "Script Paused By User"
end if

Hope you will be able to modify / add the logic according to your need..
I donot have qtp rightnow.. Recovery Scenario(if activated see Recovery.Activate ) is somewhat like a a polling mechansim waiting for a signal( for example: OnError, as highlighted in above post) , once it catches the signal it executes the chosen action by the user ( a function call in this case) , hope post revoery , Continue to Next Step should work in your case... , however I am not sure if you would be able to correct the error in your qtp resources during this pause.. but definitely you can find what the error was ... DescribeError statement will prob bring the last error in qtp.. or we can use for Err.Source, Err.Number and Err.Description and log these using the your logging function...Try Using these Error statements in Information bar/Debug View during this pause...

Note: As a best practice we use RecoveryScenario to handle unknown errors, however if you know that a statement is likely to cause an error then use On Error Resume Next and don not forget to put On Error goto 0 after catching the Err.Number and Err.Description

Best Regards,
Jiten
Reply
#7
Solved: 11 Years, 3 Months, 3 Weeks ago
From your original question, I thought maybe you wanted to see the error conditions (by breaking when the error occurs) but then you would stop/exit that particular script. If you want to run the rest of the test after you get a chance to examine the condition of the app under test when the error occurs, you could use the Command tab of the Debug window to manually re-enable your recovery scenario, then run your test from where it stopped. Put the code that disables the recovery scenario into a function named something like "DisableRecoveryScenario" (name doesn't matter) that you can call and give it one parameter named something like "status" (the name doesn't matter) and make it a boolean.

Change the code to use the parameter value instead of hard-coded "disable=true" :

Code:
TestRecovery.Item(intIndex).Disabled = Parameter("status")


When you're ready to re-enable your recovery scenario, call this function manually by going to the Debug window,click on the Command tab, and type: call DisableRecoveryScenario(false)

This should call your function and re-enable your recovery scenario.

If you want to automatically re-enable your recovery scenario without any manual intervention, I'm not sure how to do that. I'd have to think about it awhile, but I thought that you wanted the script to pause until you could look at the problem and the state of the universe, then pick up your script from where it stopped and continue on with the test once you understand the cause of the error.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  VB script Code. Tejas Tikhe 2 3,656 06-19-2012, 10:54 AM
Last Post: Tejas Tikhe
Rolleyes How to pause QTP script using DotNet Factory nistalaramesh 3 5,183 06-23-2011, 02:59 PM
Last Post: Saket
  Pause from QTP. logeshkumarvb 2 4,439 01-11-2011, 07:20 PM
Last Post: UFTEnthusiast
  need script to pause the test kumsweta 1 3,441 12-02-2008, 09:26 PM
Last Post: roxer

Forum Jump:


Users browsing this thread: 4 Guest(s)