Quick Test Professional(QTP)- Useful Tricks

1. How to create a new action?
-Open QTP
-Insert>call to new action>start recording to create an action
-make sure to check “Reusable action”
-Save it in the QC folder where you can remember

2. How to call an existing action for the existing scripts?
-Open QTP
-Insert>Call to existing Action
-save the called action

3. How to insert “Wait” command in scripts?
Browser("Welcome to the Config").Page("Edit Name_2").WebList("FamilyList").Select "ISE 1.0"
Wait (6)
Browser("Welcome to the Config ").Page("Edit Name_2").WebList("moduleSelect").Exist

4. ReportEvent: With “If-Then-Else” logics
If Browser("Welcome to the Config ").Page("Welcome to the Config ").Link("General").Exist then
Reporter.ReportEvent micPass,"web element","general present"
else
Reporter.ReportEvent micFail,"webelement","General not present"
End if
Browser("Welcome to the Config ").Page("Welcome to the Config ").Link("General").Click

Note: make a copy of your original one line script and replace “Click” with “Exist then” in the copied one.
Click return key and type reporter. And you will see bunch of report events. Select ReportEvent and hit space bar to provide space. You will see bunch of other pop up list. Select “micPass” and provide a comma to it. Afterward put comments and status results inside the double quotes i.e. reporter.ReportEvent micFail,"webelement","general not present". You can see this report in test results.

5. Insert Standard Check Points while recording
If your test case is asking to “delete template”, then when you hit “delete” you will see some kind of confirmation message to make sure the template has been deleted. Put the check point when you see the confirmation message. To insert checkpoints while recording, for instance you want to insert checkpoint for “Confirmation message” and you’ve have not stopped recording yet after clicking “delete”, then in QTP, select insert>checkpoint>standard checkpoint>select the delete confirmation message. Done

6. GetRoProperty:
i.e. if you would like to get properties/value of an object
autofilltext=Browser("Config + Template Editor").Page("Config + Template Editor").WebElement("source_field_name").GetROProperty ("innertext")
msgbox autofilltext
If autofilltext="Velocity Template" Then
Reporter.ReportEvent 0,"Verify the 'Velocity template' box.","successfully identified Velocity template"
Else
Reporter.ReportEvent 1,"Verify the 'Velocity template' box.","Unable to identify Velocity template"
End If

You can give meaningful word to variable autofilltext for message box. Remove any operation i.e. Click right after dot at the end and replace it with GetRoProperty. To get the property of the object whether or not it is innertext or outertext, follow these steps. From QTP select ‘Object Spy’ and point it to the object you want to find its property and click the object. Once the object is clicked, property & values are saved in the Object Spy. Scroll down in the object spy window. You will see whether or not it is innertext or outertext. You can copy and paste it inside the parenthesis right after GetRoProperty.
And type msgbox
In if statement, value after assignment sign is the name of the object. Others are ReportEvent that we talked in Question 5

Note: usually you do not need to show message pop up if you’re running multiple test cases at night as when it pops up, it will stop other test cases to run until you click the pop up. So always comment it out for msgbox i.e. ‘msgbox autofilltext

7. Inserting Breakpoints
Usually break point are good when you don’t want to run whole script but upto some linke of the script.
If you point your mouse to the left side of the screen right next to your script and click to a particular line of the script, you will see big red dot. This is what called break point. Test run will stop to the point where you’ve placed your break point. This is easy tool specially when you’re are creating/testing/debugging scripts.
You can remove break point by clicking at the red dot.

8.How to FireEvent: Script for ‘Double-click’ ?
If you can not record for double clicking some object, you can generate a script for it. Here you got following script
Browser("Config + Template Editor").Page("Welcome to the Config ").WebButton("ABCD").Click
Now make it a double click action. Remove Click and type FireEvent, you will see popup with FireEvent and select it and inside double quotes, type “ondblclick” like the following
Browser("Config + Template Editor").Page("Welcome to the Config ").WebButton("ABCD").FireEvent"ondblclick"

9. How to use of the Data Table ?
Example script: Browser("Browser").Page("abc").WebEdit("USER").Set "ssharma"
a) Parameterization
simply provide multiple data in the same column. If these test data are valid, they qtp will run as many time as you have data
From QTP, Keyword Veiw>Select a value from the value column>click a parameter sign>Parameter>Give the object name in the name field such as USER from above example script. Now it will generate a column in the Global data table.

b) Tracking object values which can be replaced in the latter releases if data is deleted for some reason: from above example if you record a column in the
data table for USER (columnname) and data (ssharma), you can change value ‘ssharma to skhanal 

 10. how to use code/script to call an Excel Sheet?
Create a reusable action and type the following code:
Datatable.addsheet("login")
DataTable.Importsheet ( pathfinder.Locate( "[QualityCenter] Subject\Auto STD Regression Config+\login_info.xls")),"login","login"
For i = 0 to DataTable.GetSheet("login").GetRowCount -1
call Login(DataTable.Value("username", "login"), DataTable.Value("password","login"), DataTable.Value("url","login"))
datatable.Value("Result")="pass"
Next
DataTable.DeleteSheet("login")

11.How to make local object to globally available?
For Local Object Repository:
-Open the test on the QTP editor (Expert View)
-Resource>Object Repository
For Global Object Repository:
-Open the test on the QTP editor (Expert View)
-Resource>Object Repository Manager
You need to have both windows opened and simply drag and drop from local to global.
Once you move to global make sure to save it in the global repository.

12. How to export /import excel sheet?
User can make an Excel sheet with the required parameters and can import it to QTP when necessary. Ater creating excel sheet,open QTP, right click on any of the cells in the Data Table
File>Import.
a window pop-up box appears whether you will want to replace the contents of the current data table with the ones in the excel sheet.
Click OK .



Same way you can export data table into an external excel file. It is useful to use the required parameters in some different test run within QTP.
Or use script - Datatable.Export("path of file")

13. GetItem(1)
getItem(1) function will pick first values in the picklist If Browser("Welcome to the Config").Page("Welcome to the Config ").WebList("FamilyList").Exist Then Browser("Welcome to the Config ").Page("Welcome to the Config ").WebList("FamilyList").GetItem(1) Browser("Welcome to the Config ").Page("Welcome to the Config ").WebList("FamilyList").Select DataTable("FamilyList", dtGlobalSheet) End if

No comments: