TA的每日心情 | 开心 2016-2-27 08:48 |
---|
签到天数: 2 天 连续签到: 1 天 [LV.1]测试小兵
|
一点帮助
这也是我一直在关心的问题。先给你一点帮助,但愿对你有帮助:
Problem ID: 34418
--------------------------------------------------------------------------------
Product: QTP Version N/A QTP 6.5 QTP 8.0
Ext(s): Java
Topics:
Java Specific Questions or Problems
Recognition and Interaction with Lists, Trees, and Comboboxes
OS: Any Windows Platform
Creation Date: 22 Sep 2004
Last Modified Date: 15 Dec 2004
--------------------------------------------------------------------------------
Problem Description: How to retrieve the index of a given element in a JavaTree
Does QuickTest Professional have a method to retrieve the index of a given element in a JavaTree? The JavaTree method has a built-in method to retrieve the string from an index, but it does not appear to have a method to perform the reverse.
--------------------------------------------------------------------------------
Solution: Use the custom GetIndex function
Note:
This function is not part of QuickTest Professional. It is not guaranteed to work and is not supported by Mercury Customer Support. You are responsible for any and all modifications that may be required.
This function was written against the JTree object in the SwingSet2 demo application that comes with the Sun JDK.
GetIndex(obj, str1)
obj The JTree object
str1 The path to the element the generated index is for
The index of an element in the JTree is dependent on how the tree is displayed. For example, if a branch containing three elements is expanded, the index for the desired element will be three greater than if that branch was collapsed. The GetIndex function collapses the tree to make sure the index returned is the same each time the function is executed.
Public Function GetIndex(obj, str1)
' Collapse the tree
rows = obj.GetROProperty("items count")
For i = rows -1 to 0 step -1
obj.object.collapseRow i
Next
' Expand the specified row
obj.Expand str1
' Get the number of items. Note: this value changes depending on how many branches in the tree are expanded.
' This is why the specified row must be expanded.
rows = obj.GetROProperty("items count")
' Loop through the rows in the expanded tree to find specified item
For i = 0 to rows -1
item1 = obj.GetItem (CStr(i))
match1 = StrComp(str1, item1)
If match1=0 Then
GetIndex = i
Exit Function
End If
Next
GetIndex = -1
End Function
RegisterUserFunc "JavaTree", "GetIndex", "GetIndex"
msgbox JavaWindow("SwingSet").JavaTree("TreeDemo$1").GetIndex("Music;Jazz;Miles Davis;Voodoo Down")
The RegisterUserFunc method registers the function for use with a QuickTest test object. For more information, please refer to Problem ID 25943 - How to register a user-defined function for use with objects. |
|