Welcome, Guest. Please login or register.
Login with username, password and session length

 
Advanced search

18120 Posts in 4741 Topics- by 31743 Members - Latest Member: suuraj
 

Pages: [1]   Go Down
Print
0 Members and 1 Guest are viewing this topic.
Author Topic: How to get particular Java Tree Node Image    (Read 2538 times)
Anil Kumar
User
*
Offline Offline

Posts: 5


« on: October 06, 2008, 01:58:12 PM »

Hi,

Can anyone please help me getting the Image of an Java tree Node?
I tried the following code:

Code
GeSHi (qtp):
JavaWindow("window").JavaTree("JTree").object.getCellRenderer().getLeafIcon()

 
Created by GeSHI 1.0.7.20

but no luck.

help in this regard would be greatly appreciated.

Thanks,
Anil RK
« Last Edit: October 07, 2008, 10:10:00 AM by Meir Bar-Tal » Logged
Meir Bar-Tal
Administrator
Advanced User
*****
Offline Offline

Posts: 1283



WWW
« Reply #1 on: October 16, 2008, 10:21:11 AM »

What's your requirement: to get the image or the filename of the image?
Logged

Best Regards,

Meir Bar-Tal
AdvancedQTP Chief Editor & Forums Administrator
Anil Kumar
User
*
Offline Offline

Posts: 5


« Reply #2 on: October 27, 2008, 02:35:01 PM »

Hi,

My requirement is to get the file name of the image. So that i can compare with existing file names and decide upon which node i am clicking.

Thanks in advance.

Anil RK
Logged
Meir Bar-Tal
Administrator
Advanced User
*****
Offline Offline

Posts: 1283



WWW
« Reply #3 on: November 02, 2008, 11:57:40 PM »

I'm not absolutely sure about this (I'll recheck it later), but if you're able to get the leaf node, then you can try either the getImage() or getLocation() methods.
Logged

Best Regards,

Meir Bar-Tal
AdvancedQTP Chief Editor & Forums Administrator
Anil Kumar
User
*
Offline Offline

Posts: 5


« Reply #4 on: November 04, 2008, 01:00:37 PM »

Hi,

I tried getIcon & getLocation, error "Object doesn't support this property or method:'getLeafIcon().getLocation" is shown.

When i am using '.getLeafIcon().toString', the following text is shown.

com.xxx.framework.ui.component.gsi.StatusSupport$NavNodeRenderer$NavNodeIcon@81998f

Please suggest.

Thanks,
AniL RK
Logged
Meir Bar-Tal
Administrator
Advanced User
*****
Offline Offline

Posts: 1283



WWW
« Reply #5 on: November 05, 2008, 10:57:37 AM »

Maybe you need to iterate through the Nodes and for each call getNode().getImage().getFilename() and compare with your expected filename.

Could you attach the description properties of the object?
Could you attach a screenshot?
Logged

Best Regards,

Meir Bar-Tal
AdvancedQTP Chief Editor & Forums Administrator
Steve Schaefer
User
*
Offline Offline

Posts: 2


« Reply #6 on: May 20, 2009, 12:50:50 PM »

I write most of my QTP script using descriptive programming, so this function may look a little different than the ones you write using the object repository. Also, a few of the lines wrapped when I pasted the code here.

The function is called with vTree, which equals the JaveTree index. In my case, there was only 1 JavaTree on the page so it was indes = 0. The function returns a pipe-delimited string containing each item displayed in the fully opened tree.
  vItems = fSplitJavaTree(0)

The nested For-loops determine how deep you need to go to get each leaf, but can be shortened or expanded as needed.

Since I didn't want the full path returned (just the last part, which equals the displayed text) I included the last For-Loop to grap the text after the last ";"

Hope this helps  Wink

Code
GeSHi (qtp):


Function fSplitJavaTree(vTree)'Returns String Separated w/ "|"

   Dim oDesc

   vCollection = "|"



   Set oDesc = Description.Create()

   Set objLink = Browser("Index:=0").Page("Index:=0").JavaApplet("Index:=0").JavaTree("Index:="&vTree)

   objLink.Highlight



   'Expand Level 0

   vLevel_0 = 0

   objLink.Expand "#"&vLevel_0

   'Expand Level 1

   On Error Resume Next

   For vLevel_1 = 1 to 3

      objLink.Expand "#"&vLevel_0 & ";#" & vLevel_1

      'Expand Level 2

      For vLevel_2 = 0 to 3

         objLink.Expand "#"&vLevel_0 & ";#" & vLevel_1 & ";#" & vLevel_2

         'Expand Level 3

         For vLevel_3 = 0 to 3

            objLink.Expand "#"&vLevel_0 & ";#" & vLevel_1 & ";#" & vLevel_2 & ";#" & vLevel_3

            'Expand Level 4

            For vLevel_4 = 0 to 3

               objLink.Expand "#"&vLevel_0 & ";#" & vLevel_1 & ";#" & vLevel_2 & ";#" & vLevel_3 & ";#" & vLevel_4

            Next

         Next

      Next

   Next



   vCount = objLink.GetROProperty("items count")



   For i = 1 To vCount - 1

      vStage1 = objLink.GetItem(""&i&"")

      vStage1_array = split(vStage1,";")

      vLastPart = UBound(vStage1_array)

      vCollection = vCollection & vStage1_array(vLastPart) + "|"

   Next

   fSplitJavaTree = vCollection

End Function

 
Created by GeSHI 1.0.7.20
« Last Edit: May 20, 2009, 08:05:25 PM by Meir Bar-Tal » Logged
Meir Bar-Tal
Administrator
Advanced User
*****
Offline Offline

Posts: 1283



WWW
« Reply #7 on: May 20, 2009, 09:17:15 PM »

I think a recursive function would provide a better, generic solution, as you cannot know in advance how many levels there might be in the tree.

I'll make an attempt to publish such a function here or in my blog.
If someone would like to take the challenge instead, that would be great.
The resulting working function will be published with full credit to the author.
Logged

Best Regards,

Meir Bar-Tal
AdvancedQTP Chief Editor & Forums Administrator
Meir Bar-Tal
Administrator
Advanced User
*****
Offline Offline

Posts: 1283



WWW
« Reply #8 on: May 20, 2009, 09:25:10 PM »

BTW Steve, the original requirement by Anil was to get the filename of the image.
Thanks for sharing your code with the community!

Smiley
Logged

Best Regards,

Meir Bar-Tal
AdvancedQTP Chief Editor & Forums Administrator
Pages: [1]   Go Up
Print
Jump to: