Total Pageviews

Monday, 30 January 2012

RK QTP Classes6 - Scripts to all

Qtp Scripts

Sorting of Elements in an Array

'#####################################################
'Program to illustrate sorting of elements of an array
'This program takes the array boundary from the user
'Validate if it is a valid number <=10  
'Get the list of elements from the user  
' Validate if it is a number  
' Finally Sorts and displays the contents of the array
'#####################################################  
 
'Variable Declarations 
Dim nArray(),nArrayBound 
Dim nCounter, nCtr1,nCtr2 
Dim nTempVar,sTempStr 
Dim bFlag 
 
'Get the number of elements as input from the user nArrayBound=inputbox("Enter a number between 5 and 10" 
 
'Validate the input (if it is a valid number) 
bFlag=False  
 
Do While bFlag=False  
 
   If isNumeric(nArrayBound) Then 'Valid number   
 
      If nArrayBound<=10 Then 'Lesser than 10    
 
         If nArrayBound>=5 Then  'Greater than 5
 
            bFlag=True
 
         Else
 
            bFlag=False
            nArrayBound=inputbox("Enter a number greater than 5")
 
         End If
 
       Else
 
         bFlag=False
         nArrayBound=inputbox("Enter a number Less than or equal to 10")
 
       End If
 
   Else
 
       bFlag=False
       nArrayBound=inputbox("Enter a valid number")
 
   End If
 
Loop
 
'Redim the array decalred with the number of elements
ReDim nArray(nArrayBound-1) ' -1 because the array index starts with 0
nArrayBound=cint(ubound(nArray)) 'moving the upper boundary of the array to a variable
 
For nCounter=0 to nArrayBound
 
   'Get the elements of the array from the user
   nArray(nCounter)=inputbox("Enter the Array Element #"&nCounter)
   'Validate the input (if it is a valid number)
   bFlag=False
 
   Do While bFlag=False
 
      If isNumeric(nArray(nCounter)) Then ' Checking if the input is a number
 
         bFlag=True
 
      Else
 
         bFlag=False
         nArray(nCounter)=inputbox("Enter a valid number")
 
      End If
 
   Loop
 
Next
 
For nCtr1=0 to cint(ubound(nArray)) 'To track the current elemtent
 
   For nCtr2 = nCtr1+1 to cint(ubound(nArray))  ' The other elements in the Array
 
      If cint(nArray(nCtr2))< cint(nArray(nCtr1)) Then ' Check which one is smaller
 
            'Swap the elements
            nTempVar = nArray(nCtr1)
            nArray(nCtr1)=nArray(nCtr2)
            nArray(nCtr2)=nTempVar
 
      End If
 
   Next
 
Next
 
sTempStr="Sorted list : "
 
For nCounter=0 to ubound(nArray)
 
   'Putting the sorted elements in a string
   sTempStr=sTempStr&nArray(nCounter)&", "
 
Next
 
Msgbox(sTempStr)
 
'#######################
'#### Sample Result  #####
'#######################
' Sorted list: -8, -2,0,1,4,4,7,
'##### End of Script######

VBScript Program to reverse a string without using strreverse

'Program to reverse a string without using strreverse

MyStr = inputbox("Enter the String:")
nCnt = Len(MyStr)

For i = 1 to nCnt

   RevStr = Mid(MyStr,i,1)&RevStr

Next

Msgbox RevStr

VBScript code to check if a string is Palindrome or not

'Program to check if the given string is a Palindrome or not

MyStr=Ucase(inputbox("Enter the String:"))
RevStr=strreverse(MyStr)

if strcomp(MyStr,RevStr)=0 then
   msgbox "It is a Palindrome"
else
   msgbox "It is not a Palindrome"
end if

VBScript: Listing the prime numbers

'VBScript program to display the prime numbers
PrimeNumberLimit = inputbox("Enter the range till (ex: 50):")
'Getting the limit as an input from the user

PrimeNumberList="Prime number list is:"
'Initialising the list of prime numbers

For Ctr1=1 to PrimeNumberLimit

   PrimeFlag=True
   ' Initialising a Flag variable

   If  Ctr1>=4 Then

      For Ctr2=2 to Ctr1/2
 
         If Ctr1 mod Ctr2 = 0 Then 'Checking the reminder
 
            PrimeFlag=False
            'Not a prime number

         End If
 
      Next

   End If

   If PrimeFlag=True Then

      PrimeNumberList=PrimeNumberList&" "&Ctr1
      'Collecting the prime numbers

   End If

Next

Msgbox PrimeNumberList
'Displaying the result

Program Explained Line 2: Getting the input from the user and storing it in a variable. Sample output:
Line 5: Initializing the list of prime numbers in a string. Line 8: Checking for all the numbers starting from 1 till user's input Line 10: Initializing a flag variable. Line 13: Excluding 1,2,3 the first three prime numbers. Lines 15-22: Checking for the reminder, and if it is zero we conclude it is not a prime number. Lines 28-33: Collecting all the prime numbers in a string. Line 37: Displaying the list of prime numbers. Result:

Validating an input from the user

'The following code illustrates how an input can be validated in VBScript. This example program demonstrates how to validate for a numeric value between 5 and 10

nInputNumber=inputbox("Enter a number between 5 and 10")

'Validate the input (if it is a valid number)

bFlag=False

Do While bFlag=False

   If isNumeric(nInputNumber) Then 'Valid number

      If nInputNumber<=10 Then 'Lesser than 10

         If nInputNumber>=5 Then  'Greater than 5
            bFlag=True
         Else
            bFlag=False
            nArrayBound=inputbox("Enter a number greater than or equal to 5")
         End If

      Else

         bFlag=False
         nArrayBound=inputbox("Enter a number Less than or equal to 10")

      End If
   Else

      bFlag=False
      nArrayBound=inputbox("Enter a valid number")

   End If
Loop

Msgbox "All Conditions Satisfied"

Program Explained: The above code illustrates how an input can be validated in VBScript. This example program demonstrates how to validate for a numeric value between 5 and 10. I have explained the executable lines below: Line 3: We use an Input box to get a value from the user and store it in a variable nInputNumber Line 7: We set the bFlag variable as false, this variable is a falgging boolean varible which will be set as true when our conditions are satisfied. Line 9: (Do Loop) Looping the statements until our conditions are satisfied (Numeric Value & greater than or equal to 5 & less than or equal to 10) Line 11: (If isNumeric(nInputNumber)) Checking for condition 1 - Is it a number? Line 13: (If nInputNumber<=10) Checking for condition 2 - Is it Less than or equal to 10? Line 11: (If nInputNumber<=10) Checking for condition 1 - Is it Greater than or equal to 5? Lines 16,18,24,30: Setting the bFlag (Flag) variable as True/False according to whether or not the condition is satisfied. Lines 19,25,31: Throwing of appropriate error message back to the user and getting a new input from the user Line 36: Message box confirming that it is out of loop and all the conditions are satisfied.

QTP Script to update variables value from ini file

'Subprocedure to update value of ini variables value
Public Sub WriteToEnvironment(sParam ,sValue)
'Declare the required variables
Dim oFSO, oFile, oTxtStream, sLine, sNewTextStream, vpath

'Create the application object for FileSystemObject
Set oFSO = CreateObject("Scripting.FileSystemObject")

'Declare the file input/output constants
Const ForReading = 1, ForWriting = 2, ForAppending = 8

'Declare Tristate values constant used to indicate the format of the opened file
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

'Get the file from the file specified in environment variable  
Set oFile = oFSO.GetFile(Environment("iniPath"))

'Open the ini file for reading purpose
Set oTxtStream = oFile.OpenAsTextStream(ForReading, TristateUseDefault)

'Read the file till the end
While Not oTxtStream.AtEndOfStream

'Read the file line by line
sLine = oTxtStream.ReadLine
sParameter = Array()

'Spilt the ini variable by delimiter 
sParameter = Split(sLine, "=")

'If the ini variable name matches to required then modify the value with new value
If sParameter(0) = sParam Then
sLine = sParam & "=" & sValue
End If

sNewTextStream = sNewTextStream & sLine & vbCrLf
Wend

'close the stream object
oTxtStream.Close

'Create the application object for FileSystemObject
Set oFSO = CreateObject("Scripting.FileSystemObject")

'Get the file from the file specified in environment variable  
Set oFile = oFSO.GetFile(Environment("iniPath"))

'Open the ini file for writhing purpose
Set oTxtStream = oFile.OpenAsTextStream(ForWriting, TristateUseDefault)

'Write the new stream data to file
oTxtStream.Write sNewTextStream

'Close the stream object
oTxtStream.Close
End Sub

QTP code to search data from Excel sheet

Dim appExcel, objWorkBook, objSheet, columncount, rowcount,

'Create the application object for excel
Set appExcel = CreateObject("Excel.Application")

'Set the workbook object by opening 
Set objWorkBook = appExcel.Workbooks.open("c:\Smoke_Test\SmokeTest.xls")

'Set the Worksheet object
Set objSheet = appExcel.Sheets("Global")

'Get the count for total used columns
columncount = objSheet.usedrange.columns.count

'Get the count for total used rows
rowcount = objSheet.usedrange.rows.count

'Assign the data to search for
Find_Details="Report"

'Iterate the loop through each cell to find out required data 
For a= 1 to rowcount
For b = 1 to columncount
fieldvalue =objSheet.cells(a,b)
If  cstr(fieldvalue)= Cstr(Find_Details) Then
msgbox cstr(fieldvalue)
Exit For
End If
Next
Next

QTP code to terminate all instances of Internet explorer using collections

'Code to close all Internet explorer browser process using QTP

Dim oWMIService, allIExplorer,iEItem
Dim strComputer

strcomputer="."

'Get the WMI object
Set oWMIService=GetObject("Winmgmts:\\"& strcomputer & "\root\cimv2")

'Get collection of processes for with name iexplore.exe
set allIExplorer=obj.execquery("Select * from win32_process where name='iexplore.exe'")
name
'Loop through each process and terminate it
For each iEItem in allIExplorer
iEItem.terminate
Next

Set allIExplorer= Nothing
Set oWMIService= Nothing

QTP script to send an email from outlook

'Call to the function for sending the mail on mail id 'abc@abc.com'
Call SendMail("abc@abc.com","Hi","Hi","")

' THis function will create an email and send it using outlook

Function SendMail(SendTo, Subject, Body, Attachment)

'CreateObject method to create an Outlook Application object
Set ol=CreateObject("Outlook.Application")

'Create a new outlook mail object
Set Mail=ol.CreateItem(0)

'Add the email address to the recipient list of the message
Mail.to=SendTo

'Add the subject of the message
Mail.Subject=Subject

'Add the body of the mail message
Mail.Body=Body

'Add the attachment to the mail message
If (Attachment <> "") Then
Mail.Attachments.Add(Attachment)
End If

'Send the mail message
Mail.Send

'Free up the memory
ol.Quit
Set Mail = Nothing
Set ol = Nothing

End Function

Code to download attachment from outlook emails

'Below code goes through all the unread mails from inbox folder and download the attachment

'CreateObject method to create an Outlook Application object
Set ObjO=createobject("Outlook.Application")

'GetNameSpece returns a NameSpace object of the specified type
Set olns=ObjO.GetNameSpace("MAPI")

'Get the reference of inbox folder
Set ObjFolder=olns.GetDefaultFolder(6)

'Iterate for all the unread mails and download the attchment from those mails
For each item1 in ObjFolder.Items
If item1.Unread  Then
For each att in item1.attachments
FileName="C:\EmailData\" &att.FileName
att.saveasfile FileName
Next
End If
Next

QTP script to login to Gmail using different sets of logins from datatable

In the following example there is no need of recording any scripts. Just copy paste the below script and it should work provided you meet the prerequisites. Prerequisites:  1) Ensure that you set the run settings to "Run one iteration only" 2) Create the datatable (Global sheet) parameters => Rename Columns A & B as UserName and PassWord respectively (as shown below) 3) Update the test data (Different sets of user name password combinations on the global sheet (as shown below).
QTP Data Table Global Sheet
QTP Data table (global sheet), click on the image to enlarge
' Program to login to Gmail using different set of logins from a datatable
' Table Structure (parameters): UserName, PassWord

'Retrieve the number of rows in the table
nRowCount=DataTable.GlobalSheet.GetRowCount

'Close any existing IE browser windows
systemutil.CloseProcessByName "iexplore.exe"

'For every User name Password combination
For i = 1 to nRowCount

   'Open a new IE browser and navigate to gmail.com
   Systemutil.Run "iexplore", "http://gmail.com"

   'Wait for the page to load
   Browser("title:=.*").Page("title:=.*").Sync

   'Get the current row User name and password and store it in variables
   DataTable.GlobalSheet.SetCurrentRow(i)
   sEmailid=DataTable("UserName",Global)
   sPassWord=Datatable("PassWord",dtGlobalSheet)

   'Update the user name and password on the page and sign in
   Browser("title:=.*").Page("title:=.*").WebEdit("name:=Email").Set sEmailid
   Browser("title:=.*").Page("title:=.*").WebEdit("name:=Passwd").Set sPassWord
   Browser("title:=.*").Page("title:=.*").WebButton("name:=Sign in").Click
   Browser("title:=.*").Page("title:=.*").Sync

   wait(10)

   'Check if the left 13 charecters of the browser title is "Gmail - Inbox"
   If left(browser("title:=.*").Page("title:=.*").getROProperty("title"),13) ="Gmail - Inbox"Then
      msgbox("Signed in Successfully")
   Else
      msgbox("Login Unsuccessful")
   End If

   'Close the IE browser
   systemutil.CloseProcessByName "iexplore.exe"

Next

'Result
'## Message box prompting whether the login was successful or not for all the login id and password combination

How to retrieve all the link names and URLs using QTP?

We need to use the ChildObjects method to get the collection of links. Using the collection object we can then retrieve the name and URL properties of every link. Step by Step illustration: 1) Using the ChildObjects method, get all the links on the webpage.  2) We now have the collection object ready. 3) Use the GetROProperty method to retrieve the required property values. (In our case Innertext & href) Example :
' This can be used on any page
Set oLinkDesc = Description.Create()

' Retrieve HTML tag "A"
oLinkDesc("html tag").Value = "A"

' Create the collection object
Set nLinksCollection = Browser("title:=.*"”).Page("title:=.*").ChildObjects(oLinkDesc)
nLinksCount = nLinksCollection.Count()

' Retrieve all the requied properties
For i=0 to nLinksCount-1

   sName = nLinksCollection(i).GetROProperty("innertext")
   sHref = nLinksCollection(i).GetROProperty("href"”)

   ' Saving the results in the reporter
   Reporter.ReportEvent 0, "Links name: " & sName & "; URL: " & sHref

Next

QTP Script to Connect to a Database

public void ConnectToDatabase()
{

Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3

Set objConn=CreateObject("ADODB.Connection")
Set objRecordset=CreateObject("ADODB.Recordset")

objConn.Open "DRIVER={Oracle in OraHome92};SERVER={Servername};UID={Username};PWD={Password};DBQ={Dbnmae}"
objRecordset.CursorLocation = adUseClient
objRecordset.Open "Select {Col name} from tablename",objConn,adOpenStatic,adLockOptimistic

While not (objRecordset.EOF)

   objRecordset.MoveNext
   Msgbox "Result" & objRecordset.Fields.Item("{Col name}")& vbCrLf 

Wend

objRecordset.Close
objConn.Close

Set objRecordset=Nothing
Set objConn=Nothing

}

QTP Script to get the title of all open browsers

'QTP Script to Get the title of all open browsers

Set BrowserDesc = Description.Create()

BrowserDesc("application version").Value = "internet explorer 7"

Set BrowserCollection = DeskTop.ChildObjects(BrowserDesc)

nCnt = BrowserCollection.Count
MsgBox "There are totally "&nCnt&" browsers opened"

For Ctr = 0 To (nCnt -1)

   MsgBox "Browser : #"&Ctr&" has the title:"& BrowserCollection(Ctr).GetROProperty("title")

Next  

Set bColl = Nothing
Set bDesc = Nothing

How to deal with Dynamically changing Objects in QTP?

We come across this situaltion quite frequently. How do we deal with a dynamic object/continuously changing object at the runtime. May be the object's properties are set dynamically at runtime through input parameters. We are now at a point where we cannot add this object to the OR (Object Repository). So what's the solution?  It is simple, create a dynamic/runtime object. How do I define/create a dynamic object?
  • First Method:(method is explained inline)
Set newObject = Description.Create
'The above line declares a new object

newObject("micclass").Value = "WebElement"
'The above line sets the type of object (Browser/Page/WebElement/Link etc), in this case it is a Web Element

'The below 3 lines set the Dynamic/Runtime properties of the object

newObject("html tag").Value = "SPAN"
newObject("class").Value = "radio-classic-ITEM-OFF"
newObject("text").Value = Parameter("Text")

'Usage of the new Object
Browser("Google").Window("Google").WebElement(newObject).Click
  • Second Method
The following syntax can be handy for one time usage of a Dynamic Object. In this method we set the properties of the dynamic object in the same line. This is another way of implementing the above example.
Browser("Google").Window("Google").WebElement("html tag:=SPAN", "class:=radio-classic-ITEM-OFF", "text:=" & Parameter("Text")).Click

Datatable - Import/Export

There are 4 methods that QTP provided to Import/Export a datatable to/from an .xls file.
1) Import method : This method is used to import an entire workbook into QTP datatable.
datatable.Import "D:\QTPScripts\Test_Folder\Testing.xls"'Imports the entire workbook
2) ImportSheet method : This method is used to import only a specific sheet into QTP datatable.
datatable.ImportSheet "D:\QTPScripts\Test_Folder\Testing.xls",1,2'Imports the source sheet (1) to destination sheet (2)
3) ExportSheet method : This method is used to export only a specific datatable sheet from QTP to an .xls file.
datatable.ExportSheet "D:\QTPScripts\Test_Folder\Testing.xls",1'Exports the specified sheet to a file; Overwrites by default, only one copy is exported.
4) Export method : This method is used to export the entire datatables from QTP to an .xls file.
datatable.Export "D:\QTPScripts\Test_Folder\Testing.xls"'Entire workbook is exported

GetTOproperties, SetTOproperty, GetTOproperty & GetROproperty - methods explained with sample scripts.

Before we get started, I would like to take some time explaining about the TO, RO, Get and Set part of the methods.
TO : Stands for Test Object (The object that we have recorded in our object repository)
RO : Stands for Runt-time Object (The application object we are testing against the object in the Object repository)
Get : Is used to get (return) the current property/ies of a Run-time or a test object.
Set : Is used to set (return) the property of a test object.
GetTOproperties:
This method is used to return get the properties and their corresponding values from the recorded object in our object repository.
The following example explains the usage of GetTOproperties method:
'################################
'### Get TO Properties Script ###
'################################

systemutil.Run "iexplore.exe", "http://www.google.com"

Set oWebEdit=Browser("Google").Page("Google").WebEdit("q") 'Create webedit object

Set TOProperties=oWebEdit.GetTOProperties 'Get TO Properties

For i = 0 to TOProperties.count - 1 'Looping through all the properties
    sName=TOProperties(i).Name ' Name of the property
    sValue=TOProperties(i).Value 'Value of the property
    isRegularExpression=TOProperties(i).RegularExpression 'Is it a Regular expression
    Msgbox sName & " -> " & sValue & "->" & isRegularExpression 
Next

'##############
'### Result:###
'##############
' type -> ext -> true
' name -> q -> true
'### End of Script ####

SetTOproperty :
This method is used to set the value of a particular property of an object in the object repository.
GetTOproperty:
This method is used to get the current value of a property of an object in the object repository. If we had used the SetTOproperty method to change the existing property of an object in the OR, GetTOproperty method would only retrieve the current value of the property (ie, what ever value was set using SetTOproperty).
Note : Whatever value we set during the script execution is not retained after the execution is complete. The values in the OR automatically gets back to what it was at the beginning of the execution just like the run-time data tables.
'#############################################
'### Set TO Property & Get TO property ###
'#############################################

oldName = oWebEdit.GetTOProperty("name")
msgbox "Old Name ->" & oldName
oWebEdit.SetTOProperty "name","New Value"
NewName = oWebEdit.GetTOProperty("name")
msgbox "New Name ->" & NewName

'##############
'### Result:###
'##############
' Old Name ->q
' New Name ->New Value
'### End of Script ###

GetROProperty:
This method is used to get the runtime value of a property in an application object.
Note : SetROproperty method is not supported by QTP, hence it is unavailable.
'#######################
'### Get RO Property ###
'#######################

oWebEdit=Browser("Google").Page("Google").WebEdit("q").GetROProperty("value") 
msgbox oWebEdit

'###############
'### Result: ###
'###############

'### The text in the webedit control is displayed
'### End of Script ###

Rk classes -7

qtp software free download 10.0 trial version

www8.hp.com/us/en/software/software-solution.html?compURI=tcm:245-937061#tab=3



Debugging anAction or a Function in QTP

Suppose you create an action or a function that defines variables that will be used in other parts of your test or function library. You can add breakpoints to the action or function to see how the value of the variables changes as the test or function library runs. To see how the test or function library handles the new value, you can also change the value of one of the variables during a breakpoint.

This can be done by following below simple steps:


Step 1: Create a New Action or Function: Open a test and insert a new action, or open a new function library and create a new function called SetVariables.

If you are working in the Expert View, then follow Step 4 directly. If you are working in a function library, continue with Step 2 and Step 3.

Step 2: (For Function Libraries Only) Associate the Function Library with a Test: Make sure the function library is in focus. Select File > Associate Library ‘<Function Library Name>’ with ‘<Test Name>’. QuickTest associates the function library with your test.

Step 3: (For Function Libraries Only) Add a Call to the Function in Your Test: Add a call to the function by inserting a new step and typing the following in the Expert View: SetVariables.

Step 4: Add Breakpoints: Add breakpoints at the appropriate lines.

Step 5: Begin Running the Test: Run the test. The test or function library stops at the first breakpoint, before executing that step (line of script).

Step 6: Check the Value of the Variables in the Debug Viewer Pane:
Step 7: Check the Value of the Variables at the Next Breakpoint: Click the Run button to continue running the test. The test stops at the next breakpoint.

Step 8: Modify the Value of a Variable Using the Variables Tab
Step 9: Modify the Value of a Variable Using the Command Tab
Step 10: Repeat a Command from the Command History
Using Breakpoints :
We can use breakpoints to instruct QuickTest to pause a run session at a predetermined place in a component or function library. QuickTest pauses the run when it reaches the breakpoint, before executing the step. we can then examine the effects of the run up to the breakpoint, make any necessary changes, and continue running the component or function library from the breakpoint.
You can use breakpoints to:
* suspend a run session and inspect the state of your site or application.
* Mark a point from which to begin stepping through a component or function library using the step commands
* We can set breakpoints, and we can temporarily enable and disable them. After we finish using them, we can remove them from your component or function library.
Note: Breakpoints are applicable only to the current QuickTest session and are not saved with your component or function library.

Operations we can perform on Breakpoints:
* Setting Breakpoints
* Enabling and Disabling Breakpoints
* Removing Breakpoints

* Setting Breakpoints:
By setting a breakpoint, we can pause a run session at a predetermined place in a component or function library. A breakpoint is indicated by a filled red circle icon in the left margin adjacent to the selected step.
To set a breakpoint:
Perform one of the following:
*Click in the left margin of a step in script/function library where you want the run to stop
*Click a step and then:
Click the Insert/Remove Breakpoint button
Choose Debug > Insert/Remove Breakpoint
The breakpoint symbol is displayed in the left margin of the script or function library.
Note: Breakpoints are applicable only to the current QuickTest session and are not saved with your component or function library.

* Enabling and Disabling Breakpoints :
We can instruct QuickTest to ignore an existing breakpoint during a debug session by temporarily disabling the breakpoint. Then, when you run our component or function library, QuickTest runs the step containing the breakpoint, instead of stopping at it. When we enable the breakpoint again, QuickTest pauses there during the next run. This is particularly useful if your component or function library contains many steps, and you want to debug a specific part of it.
We can enable or disable breakpoints individually or all at once. For example, suppose we add breakpoints to various steps throughout your component or function library, but for now you want to debug only a specific part of your document. We could disable all breakpoints in your script or function library, and then enable breakpoints only for specific steps. After you finish debugging that section of your document, you could disable the enabled breakpoints, and then enable the next set of breakpoints (in the section you want to debug). Because the breakpoints are disabled and not removed, we can find and enable any breakpoint, as needed.
An enabled breakpoint is indicated by a filled red circle icon in the left margin adjacent to the selected step.
A disabled breakpoint is indicated by an empty circle icon in the left margin adjacent to the selected step.
Note: Breakpoints are applicable only to the current QuickTest session and are not saved with your component or function library.

We can:
Enable/disable a specific breakpoint
Enable/disable all breakpoints
To enable/disable a specific breakpoint:
Click in the line containing the breakpoint you want to disable/enable.
Choose Debug > Enable/Disable Breakpoint or press Ctrl+F9. The breakpoint is either disabled or enabled (depending on its previous state).
To enable/disable all breakpoints:
Choose Debug > Enable/Disable All Breakpoints or click the Enable/Disable All Breakpoints button. If at least one breakpoint is enabled, QuickTest disables all breakpoints in the component or function library. Alternatively, if all breakpoints are disabled, QuickTest enables them.

* Removing Breakpoints:
You can remove a single breakpoint or all breakpoints defined for the current component or function library.
To remove a single breakpoint:
Perform one of the following:
Click the breakpoint.
Click the line in your component or function library with the breakpoint symbol and:
Click the Insert/Remove Breakpoint button.
Choose Debug > Insert/Remove Breakpoint.
The breakpoint symbol is removed from the left margin of the QuickTest window.
To remove all breakpoints:
Click the Clear All Breakpoints button, or choose Debug > Clear All Breakpoints. All breakpoint symbols are removed from the left margin of the QuickTest window

* Setting Breakpoints:
By setting a breakpoint, we can pause a run session at a predetermined place in a component or function library. A breakpoint is indicated by a filled red circle icon in the left margin adjacent to the selected step.
To set a breakpoint:
Perform one of the following:
*Click in the left margin of a step in script/function library where you want the run to stop
*Click a step and then:
Click the Insert/Remove Breakpoint button
Choose Debug > Insert/Remove Breakpoint
The breakpoint symbol is displayed in the left margin of the script or function library.
Note: Breakpoints are applicable only to the current QuickTest session and are not saved with your component or function library.

* Enabling and Disabling Breakpoints :
We can instruct QuickTest to ignore an existing breakpoint during a debug session by temporarily disabling the breakpoint. Then, when you run our component or function library, QuickTest runs the step containing the breakpoint, instead of stopping at it. When we enable the breakpoint again, QuickTest pauses there during the next run. This is particularly useful if your component or function library contains many steps, and you want to debug a specific part of it.
We can enable or disable breakpoints individually or all at once. For example, suppose we add breakpoints to various steps throughout your component or function library, but for now you want to debug only a specific part of your document. We could disable all breakpoints in your script or function 


Step Into, Step Out, and Step Over commands
Step Into:- Choose Debug > Step Into, click the Step Into button, or press F11 to run only the current line of the active test or function library. If the current line of the active test or function library calls another action or a function, the called action/function is displayed in the QuickTest window, and the test or function library pauses at the first line of the called action/function.

Step Out :- Choose Debug > Step Out, click the Step Out button, or press SHIFT+F11 only after using Step Into to enter an action or a user-defined function. Step Out runs to the end of the called action or user-defined function, then returns to the calling test or function library and pauses the run session.

Step Over:- Choose Debug > Step Over, click the Step Over button, or press F10 to run only the current step in the active test or function library. When the current step calls another action or a user-defined function, the called action or function is executed in its entirety, but the called action or function script is not displayed in the QuickTest window.

Interview Question:- What is difference b/w Step Into, Step Out, and Step Over commands ?

What are Recover Scenarios?
While executing your scripts you may get some UNEXPECTED/UNPREDICTABLE errors. (like printer out of paper). To "recover" the test (and continue running) from these unexpected errors you use Recovery Scenarios.
Next question arises,
When to use "on error resume next" or programmatic handling of errors VS Recovery Scenarios ?
If you can predict that a certain event may happen at a specific point in your test or component, it is recommended to handle that event directly within your test or component by adding steps such as If statements or optional steps or "on error resume next", rather than depending on a recovery scenario. Using Recovery Scenarios may result in unusually slow performance of your tests.They are designed to handle a more generic set of unpredictable events which CANNOT be handled programmatically.
For Example:
A recovery scenario can handle a printer error by clicking the default button in the Printer Error message box.
You cannot handle this error directly in your test or component, since you cannot know at what point the network will return the printer error. You could try to handle this event in your test or component by adding an If statement immediately after the step that sent a file to the printer, but if the network takes time to return the printer error, your test or component may have progressed several steps before the error is displayed. Therefore, for this type of event, only a recovery scenario can handle it.
I would not go into details of how to create files and how to define them since they are fully covered in QTP Documentation. Mercury QuickTest Professional User's Guide > Working with Advanced Testing Features > Defining and Using Recovery Scenarios >
What constitute Recovery Scenarios?
A recovery scenario consists of the following: 
  • Trigger Event. The event that interrupts your run session. For example, a window that may pop up on screen, or a QTP run error.
  • Recovery Operations. The operations to perform to enable QTP to continue running the test after the trigger event interrupts the run session. For example, clicking an OK button in a pop-up window, or restarting Microsoft Windows.
  • Post-Recovery Test Run Option. The instructions on how QTP should proceed after the recovery operations have been performed, and from which point in the test QTP should continue, if at all. For example, you may want to restart a test from the beginning, or skip a step entirely and continue with the next step in the test.

Recovery scenarios are saved in recovery scenario files having the extension .rs. A recovery scenario file is a logical collection of recovery scenarios, grouped according to your own specific requirements. 
Is there a method to programmatically call them?
By default, QTP checks for recovery triggers when an error is returned during the run session. You can use the Recovery object's method to force QTP to check for triggers after a specific step in the run session. 
For a complete list go to QTP Documentation > Quick Test Advanced References > Quick Test Automation > Recovery Object

In this example, we will define a Function Call and use that Function Call to handle the error. The default syntax for the Recovery Scenario Function is:
Function fnRecovery(Object, Method, Arguments, retVal)
        'Error Handling Code
End Function
Explanation of each argument to fnRecovery is given below:
Object as Object: The object of the current step.
Method as String: The method of the current step.
Arguments as Array: The actual method's arguments.
Result as Integer: The actual method's result.
To handle this scenario, we will use the function below:
Function Recovery_ListItemIsNotFound(Object, Method, Arguments, retVal)
     Dim sAllItems, arrAllItems, intItem
 
     With Object
          'Retrieve all items from the Listbox
          sAllItems = .GetROProperty("all items")
          'Split 'all items' using a delimiter ";" into an array
          arrAllItems = Split(sAllItems, ";")
 
          'Select a random number
          intItem = RandomNumber.Value(LBound(arrAllItems), UBound(arrAllItems))
          .Select "#" & intItem
 
          Reporter.ReportEvent micInfo, "ListItemIsNotFound", "Item: " & .GetROProperty("value")
     End With
End Function
Recovery_ListItemIsNotFound, as the same suggests, executes the Recovery Operation if the list item that we supplied to our target WebList does not exist. This is quite common in Web applications, and Items in a WebList can change depending upon the input(s) provided.
To start, Click Resources -> Recovery Scenario Manager. You should see a window like this:


To recover from unexpected events and errors that are occurred in the test environment during run session, we can use Recovery Scenario Manager. For good recovery, error must be known the occurrence is unknown.

There are (4) Types of events such as:

(i) Application Crash

An open application fails during Test Run.

Navigation:

Resources Menu -> Recovery Scenario Manager-> Click New-> Click Next ->
Select Application Crash as Trigger event->Next ->Select selected executable
application->Next ->Select Recovery Operation [Keyboard, Mouse Operation,
Close Application Process, function Call, Restart, Microsoft Windows] ->Next ->If
you want to check Add another operation else uncheck->Next ->Next ->Enter
Scenario Name ->Next->Select Option ->Finish ->Close ->Save the scenario in
specified location with ".qrs"
(qrs stands for QuickTest Recovery Scenario.)

(ii) Popup Window.

To handle unwanted popups.

Navigation:

Resources Menu ->Recovery Scenario Manager ->New ->Next ->Select "Popup
Window" as Trigger event ->Next ->Click on Hand Icon ->Show unwanted
window with Hand icon ->Next ->Next ->Select function call as Recovery
Operation ->Next [Open Notepad ->Save empty file with .vbs extension] ->Browse
the .vbs fie path ->Next ->Uncheck Add another Recovery Operation ->Next ->
Select Post-Recovery Test Run Option [Repeat current step and continue, Proceed to
Next step, Proceed to Next Action, Proceed to next test iteration, Restart current test
run, Stop the Test Run] ->Next ->Enter Scenario Name ->Next ->Select Option ->
Finish ->Save the scenario with ".qrs" ->Record required Recovery Operation [Click
ok, Click Cancel] take the script into function ->Save the library file ->Click Run

(iii) Test Run Error.

A step in your test does not run successfully then Test Run Error
can be raised.

Navigation :

Resources Menu ->Recovery Scenario Manager ->New ->Next ->Select "Testrunerror
Window" as Trigger event ->Next ->select any error o ->Next ->Next ->Select function call as Recovery
Operation ->Next [Open Notepad ->Save empty file with .vbs extension] ->Browse
the .vbs fie path ->Next ->Uncheck Add another Recovery Operation ->Next ->
Select Post-Recovery Test Run Option [Repeat current step and continue, Proceed to
Next step, Proceed to Next Action, Proceed to next test iteration, Restart current test
run, Stop the Test Run] ��Next ��Enter Scenario Name ��Next ��Select Option ��
Finish ��Save the scenario with ".qrs" ��Record required Recovery Operation [Click
ok, Click Cancel] take the script into function ��Save the library file ��Click Run


The property values of an object in your application match
specified values. You can specify property values for each object in the
hierarchy.

Navigation:

Resources Menu -> Recovery Scenario Manager -> New -> Next -> Select "Object state
Window" as Trigger event -> Next -> Click on Hand Icon -> Show object with hand icon
-> Next -> Next->select object property with value (enabled ,false)->click next -> Select function call as Recovery
Operation -> Next [Open Notepad -> Save empty file with .vbs extension] -> Browse
the .vbs fie path -> Next -> Uncheck Add another Recovery Operation -> Next ->
Select Post-Recovery Test Run Option [Repeat current step and continue, Proceed to
Next step, Proceed to Next Action, Proceed to next test iteration, Restart current test
run, Stop the Test Run] -> Next-> Enter Scenario Name -> Next -> Select Option ->
Finish -> Save the scenario with ".qrs" -> Record required Recovery Operation [Click
ok, Click Cancel] take the script into function -> Save the library file -> Click Run