Showing posts with label qtp. Show all posts
Showing posts with label qtp. Show all posts

Friday, September 9, 2011

Recovery Scenario Manager in QTP

Recovery scenario manager is used to handle unexpected events/errors during the execution of QTP script.
This is the general definition which we are seeing for a long time. But the question that arises is when should we use Recovery scenario manager and when not? And why is recovery scenario manager not used for all the events that gets raised while QTP execution?
Recovery scenarios are used only when the event occurrence is not predictable. That is if we are not sure at what place the event may get raised, then we go for recovery scenarios. If the event occurrence is predictable, then it is always recommended to use programmatic handling by using statements such as IF conditions or On error resume next. Because using Recovery scenario manager will slower down the performance of QTP. 

For example, assume that Ads are getting raised when Application is opened in a browser or while accessing the application. Assume that sometimes they get raised immediately as soon as you open a browser and sometimes they get raised only after you are accessing something on the page. And also assume that you are not able to predict how many ads get displayed. In such situations we go for Recovery Scenarios. 

One of the other best example and common example is Printer out of Paper example. It is not possible to predict at what time Network would return the printer error. Hence Recovery scenario is used in this example because by the time the printer error message gets raised QTP might have progressed several steps before the error is displayed.
Some of the examples where we don’t go for Recovery scenarios:

The dialog box that gets prompted for remembering the password. This can be handled using If statements.

The dialog box that gets raised to overwrite the existing file during the process of saving a file.
How to create a Recovery Scenario:
Select Recovery Scenario Manager from Resources>>Recovery Scenario Manager.
Click on New to create a new Recovery Scenario and it takes the user to ‘Recovery Scenario Wizard’.
Recovery Scenario involves following steps: 

1. Define the trigger event that interrupts the test run 

Define the trigger event that interrupts the test run such as Popup window, QTP error or Application error.
2. Specify the recovery operation(s) required to continue
Specify the recovery operations that need to be performed on the trigger event such as closing the Popup through keyboard operation/mouse operation, closing the application, Calling a function or restarting windows.





3. Choose a post-recovery test run operation
Instructing QTP what should be done after performing the recovery operations on Triggered event. For example like re-executing the same step in the test or moving to next step in the test or moving to the next test or close the execution of qtp script etc.,



4. Specify a name and description for the recovery scenario
Specify the name and description for the recover scenario.






5.Specify whether to associate the recovery scenario to the current test and/or to all new tests
Specify whether to add the recovery scenario to current test or make it a default to all the new tests that are created here after.



Reference: Quick Test User guide - Defining Recovery Scenarios

Saturday, August 20, 2011

QTP AOM - Open QTP and run a script in QTP using AOM

Dim qtp, ts, tres, op, oprun

set qtp = createobject("Quicktest.Application")

set tres = createobject("QuickTest.RunResultsOptions")

qtp.Launch 'for launching QTP

qtp.Visible= true 'to make QTP visible

set op = qtp.Options

set oprun = op.Run

oprun.ViewResults = true 'to view the results once script is executed

if qtp.GetStatus = "Ready" then

qtp.Open "D:\QTP\sampletest",true 'open the test from the location mentioned

set ts = qtp.Test

tres.ResultsLocation = "D:\QTP\sampletest\Res" 'results location

ts.Run tres 'run the test

if ts.LastRunResults.Status = "Passed" then

msgbox "Test run is successful"

else

msgbox "Test run failed, analyze and post the defect"

end if

ts.close

else

msgbox "QTP is not ready"

end if

qtp.Quit

set qtp = nothing

How to load comma separated values(CSV) from notepad into QTP datatable?

Following is the script to load comma separated values(CSV) from notepad into QTP datatable:

Dim fso, ts, ReadLines, Values, Rowcount

Rowcount=1 'set Rowcount variable value as 1

Set fso = CreateObject("Scripting.FileSystemObject")

Const ForReading = 1 'Set ForReading as 1

Set ts = fso.OpenTextFile("C:\testdata.txt", ForReading) 'Open the file for reading

datatable.SetCurrentRow(1)'Set cuurent row of QTP datatable as first row
 
Do while ts.AtEndOfStream <> True 'Looping untill the end of the file

ReadLines = ts.ReadLine() 'Read the first line in notepad

Values=Split(Readlines,",",-1,1) 'Split the line based on , (comma) delimiter

For i=0 to ubound(Values)

Datatable(Rowcount, dtlocalsheet)=Values(i) 'inserting the data in qtp local sheet

Rowcount=Rowcount+1 'shifting to next row in qtp data table

Next

Loop

Wednesday, July 20, 2011

How to execute double click operation in Firefox using QTP?

To make my question even more clear, consider the following scenario:

Login into Yahoo mail and click on Inbox. Mail list gets opened in the right side. Now when a single click is performed on any mail list item, Mail gets opened under the Mail list in the same tab. Please see following attachment.



When double clicked on the same mail item, mail gets opened completely in a new tab.



In the example shown above, how can double click operation be performed in Firefox using QTP?

Please make a note that using firevent "ondbclick" method will solve the problem only in IE but not in Firefox. So how can this be achieved in Firefox?

Here is the answer for this.....
.
.
.
.
.
You will see an Unspecified error when you use ondblclick directly. This happens because QTP is set to be in Event Replay mode by default.

To make this work, we need switch QTP into Mouse replay Mode before the ondblclick operation and then switch it back to Event mode after it. Here is how you can do that Programatically:

Setting.Webpackage("ReplayType")=2
Browser("Yahoo").Page("Yahoo").WebElement("Element1").FireEvent "ondblclick",40,10
Setting.WebPackage("ReplayType")=1