Quick Test Pro Tutorial

Learn Java Programming in just 5 Weeks
Test Script Title Example



'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Author              : David MacCain
'Version             : 1.0                     
'Test case document  : SCREEN3
'Test Script Name    : Create an Initializer - Private     
'Test steps covered  :   
'Description         : 
'Assumptions         :           
'Dependencies        :                       
'Inputs              :                                                                                   
'Outputs             :                                                                                               
'Return value        :
'Preconditions       :                                                                                                                           
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
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

4. How to insert "Wait" command in scripts?

   Browser("Welcome to the Iconfig").Page("Edit Initializer Name_2").WebList("templateFamilyList").Select "ISE 1.0" 
   Wait 6
   Browser("Welcome to the Iconfig").Page("Edit Initializer Name_2").WebList("moduleSelect").Exist

5. ReportEvent: Simple "If-Then-Else" logics

       If Browser("Welcome to the Iconfig").Page("Welcome to the Iconfig").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 Iconfig").Page("Welcome to the Iconfig").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.

6. 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

7. GetRoProperty: i.e. creating a message box to report object is available

       autofilltext=Browser("Iconfig + Template Editor").Page("Iconfig + 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

8. 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.

9. 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("Iconfig + Template Editor").Page("Welcome to the Iconfig").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("Iconfig + Template Editor").Page("Welcome to the Iconfig").WebButton("ABCD").FireEvent"ondblclick"

10. Use of the Data Table
Example script: Browser("Browser").Page("Verizon Business Corporate").WebEdit("USER").Set "dmaccain"
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 (dmaccain), you can change value 'dmaccain' to 'tpentam'

11. GetItem(1)

  If Browser("Welcome to the Iconfig").Page("Welcome to the Iconfig").WebList("templateFamilyList").Exist Then
         Browser("Welcome to the Iconfig").Page("Welcome to the Iconfig").WebList("templateFamilyList").GetItem(1)
        Browser("Welcome to the Iconfig").Page("Welcome to the Iconfig").WebList("templateFamilyList").Select DataTable("templateFamilyList", dtGlobalSheet)
   End if

12. 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 IConfig+\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")    

No comments:

OTN Discussion Forums: Message List - Database - General

Ask Tom HOT ARTICLES

 
© Copyright 2008 - 2011. All rights reserved to dba-sansar.blogspot.com.
All other blogs, posts and entries are the property of their respective authors.
Please email us for your comments and suggessions Click Here