Facebook

Course Name Start Date Time Duration Registration Link
No Training Programs Scheduled ClickHere to Contact
Please mail To sudhakar@qtpsudhakar.com to Register for any training

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