Facebook

For any corporate training requirements Please mail To sudhakar@qtpsudhakar.com
New Schedule in MindQ Systems, Madhapur By SUDHAKAR
Course Name Date Time Duration Type Branch
UFT + UFTPro 20th September 2017 7.30 AM - 9.00 AM IST 25Days Classroom + Online Hitech City
Selenium+Appium 4th October 2017 4.30 PM - 6.00 PM IST 40Days Online -

A book "Cracking the QTP interview" authored by Sudhakar.Read More. Buy From FlipKart

Tuesday, September 15, 2009

Object Hierarchies in QTP


Is it Mandatory to Follow Object Hierarchies Specified by QTP?

We all know that the basic object hierarchy specified by QTP is from parent to child. If is there multiple parent hierarchies then we have to start from higher level parent.

Ex:

1. Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click 
2. Browser("Browser").Dialog("Internet Security Alert").WinButton("Yes").Click 

But we don't need to follow the basic hierarchy in this case. We can ignore the top level parent object to work with Dialogs.

Using the below code you can directly work with Objects in Dialog.

'Using the Function
Set oObjDescription=CreateObjectDescription("text:=OK")
set oObject=GetDialogObject("Open Order",oObjDescription)
oObject.Highlight

'***********************************************************

Function GetDialogObject(oDialogTitle,oObjProperties)

Dim oDialog
Dim iIndex
Dim oDialogName
Dim oDialogObjects

Set oDialogDescription=Description.Create
oDialogDescription("micclass").value="Dialog"

Set oDialogObjects=Desktop.ChildObjects(oDialogDescription)

If  oDialogObjects.count=1 Then

For iIndex=0 to oDialogObjects.count-1
oDialogName=oDialogObjects(iIndex).GetROProperty("text")
If  trim(lcase(oDialogName))=trim(lcase(oDialogTitle)) Then
Set oDialogChildCollection=oDialogObjects(iIndex).ChildObjects(oObjProperties)
If  oDialogChildCollection.count=1 Then
Set GetDialogObject=oDialogChildCollection(0)
elseIf  oDialogChildCollection.count>1 Then
msgbox "More Objects Found With Provided Properties"
ExitAction
ElseIf  oDialogChildCollection.count=0 Then
msgbox "No Object Found With Provided Properties"
ExitAction
End If
Exit For
End If
Next
ElseIf  oDialogObjects.count>1 Then
msgbox "More Objects Found With Provided Properties"
ExitAction
ElseIf  oDialogObjects.count=0 Then
msgbox "No Object Found With Provided Properties"
ExitAction
End If

Set oDialog = Nothing
Set oDialogObjects = Nothing
Set oDialogChildCollection = Nothing

End Function

Function CreateObjectDescription(StrProperties)

Dim objDescription
Dim ObjArr
Dim PropCount
Dim ObjProperty

Set objDescription=Description.Create

ObjArr=split(StrProperties,",")

For PropCount=0 to ubound(ObjArr)
ObjProperty=split(ObjArr(P
ropCount),":=")
objDescription(ObjProperty(0)).value=ObjProperty(1)
Next

Set CreateObjectDescription=objDescription

End Function

'***********************************************************

For Web Applications we follow the hierarchy like this

Browser("browser").Page("page").WebEdit("edit").Set "Sudhakar Kakunuri"

The same statement will work without page object.

Ex:

Browser("browser").WebEdit("edit").Set "Sudhakar Kakunuri"

____________________________________________________________________________
Please send your Suggestions, Doubts about my blog and posts to my yahoo group http://in.groups.yahoo.com/group/qtpsudhakar

No comments :

Post a Comment