Wednesday, April 17, 2013

QTP code to search data from Excel sheet

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 Methods

QTP Methods


       QTP methods are used to extract the properties of a selected object in an application, There are some list of properties that comes under QTP methods,
  1. Capture Bitmap
  2. Child Objects
  3. GetRoProperty
  4. GetToProperty
  5. GetToProperties
  6. SetToProperty
  7. GetVisibleText
  8. GetItem
  9. GetContent
  10. GetItemsCount       
Note: The properties under 8, 9, 10 indicates the (List & Combobox) so using the above properties we can enhance the qtp scripts more effective as per the business requirements with respect to the project

Steps to follow before starting Automation

Steps to follow before starting Automation

Analyze the Manual Test Cases
           
          a) Requirement Test suite creation
          b) Application Stability
          c) Implement the frame work

                     i) Linear Framework
                     ii) Data driven Framework
                     iii) Modular Framework
                     iv) Key-Word driven Framework
                      v) Hybrid Framework

Child Objects Method in QTP

Child Objects Method in QTP


 Child Objects

              This method will display the count of the needed objects that we needed specifically from the application.

For Example:

           1. We might be need the no. of Links (Links)
           2. We might be need the no. of Buttons (WinButton, WebButton)
           3. We might be need the no. of Editbox (WinEdit, WebEdit)  

To display the count of the objects present in the same name we can declare the below syntax.

Example: 1

'Display the count of the links present in the google page:

Set lnk=Description.Create
lnk("micclass").value="Link"
Set brw=Description.Create
brw("name").value="Google"
Set olinks=Browser("name:=Google").Page("title:=Google").ChildObjects(lnk)
msgbox olinks.count

Example: 2

'Display the count of the buttons present in the qtp default flight application landing page:

Set btns=Description.Create
btns("micclass").value="WinButton"
Set dlg=Description.Create
dlg("name").value="Login"
Set ocollection=Dialog("text:=Login").ChildObjects(btns)
msgbox ocollection.count

Example: 3

'Display the count of the Edit Boxes present in the qtp default flight application landing page:

Set btns=Description.Create
btns("micclass").value="WinEdit"
Set dlg=Description.Create
dlg("name").value="Login"
Set ocollection=Dialog("text:=Login").ChildObjects(btns)
msgbox ocollection.count