Accessing advanced, dynamic data in user code

Class library usage, coding and language questions.
lawrence
Posts: 10
Joined: Tue May 09, 2017 4:15 pm

Accessing advanced, dynamic data in user code

Post by lawrence » Mon Jul 03, 2017 3:16 pm

Hi all

In Ranorex spy (version 7.1. AUT: Java, SWT) I can see the advanced, dynamic properties of a TreeItem:
Spy.PNG
spy view
Spy.PNG (50.26 KiB) Viewed 767 times
What I would like to do is to access the property "DisplayName" in "Data" of the "Dynamic" section in an user code method. I've managed to get the "Data" attribute from the element associated with the Tree Item, but I don't know how to get the "DisplayName" property from the data object. Here's the code I'm working on:
IList<TreeItem> treeItems = repo.AJApp.OverviewAreas.Bookmarks.Self.Find<TreeItem>(".//treeitem", 1000); 
IEnumerator<TreeItem> treeIterator = treeItems.GetEnumerator();
bool itemFound = false;
while (treeIterator.MoveNext() && !itemFound){
    TreeItem item = treeIterator.Current;
//I've managed to get the data object and can see in the debugger that it has a property called "Display Name"
    Object data = item.Element.GetAttributeValue("Data");
    //String displayNameText = <how can I get DisplayName from data>
    if(bookmarkText.Equals(displayNameText)){
         itemFound = true;
         item.DoubleClick();
       	 Report.Success("Bookmark for" + bookmarkText + " found and clicked");
    }
}
if(!itemFound){
    Validate.Fail("No bookmark with text  " + bookmarkText + " found");
}
In the debugger I can see that the "DisplayName" property exists:
debug.PNG
debugger view
debug.PNG (15.56 KiB) Viewed 767 times
Many thanks for your help!

Cheers,
Lawrence

Vaughan.Douglas
Posts: 250
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

Re: Accessing advanced, dynamic data in user code

Post by Vaughan.Douglas » Mon Jul 03, 2017 3:42 pm

Have you tried something like this?
IList<TreeItem> treeItems = repo.AJApp.OverviewAreas.Bookmarks.Self.Find<TreeItem>(".//treeitem", 1000); 
IEnumerator<TreeItem> treeIterator = treeItems.GetEnumerator();
bool itemFound = false;
while (treeIterator.MoveNext() && !itemFound){
    TreeItem item = treeIterator.Current;
//I've managed to get the data object and can see in the debugger that it has a property called "Display Name"
    List data = item.Element.GetAttributeValue("Data");
    String displayNameText = data("displayName");
    if(bookmarkText.Equals(displayNameText)){
         itemFound = true;
         item.DoubleClick();
       	 Report.Success("Bookmark for" + bookmarkText + " found and clicked");
    }
}
if(!itemFound){
    Validate.Fail("No bookmark with text  " + bookmarkText + " found");
}
  • Changed the data var from Object to List
  • Use the "displayname" key to return the item
Although now that I think about it, it may be something more like this:
String displayNameText = data.item("displayName");
Doug Vaughan

lawrence
Posts: 10
Joined: Tue May 09, 2017 4:15 pm

Re: Accessing advanced, dynamic data in user code

Post by lawrence » Mon Jul 03, 2017 4:08 pm

Vaughan.Douglas wrote: Changed the data var from Object to List
This doesn't compile,

Code: Select all

item.Element.GetAttributeValue("Data")
returns an object and not a list.
More specifically, as I can see in the debugger, it actually returns an object of type "JavaObjectWrapper", but not sure how to handle this type...

lawrence
Posts: 10
Joined: Tue May 09, 2017 4:15 pm

Re: Accessing advanced, dynamic data in user code

Post by lawrence » Mon Jul 03, 2017 4:39 pm

Managed to find a solution by using Ranorex.Plugin library (containing JavaObjectWrapper). In case anybody is interested here's the code:

Code: Select all

[UserCodeMethod]
       public  static void SelectBookmark(String bookmarkText){
       	if(!repo.AJApp.LesezeichenTabInfo.Exists(1000)){
	 	 	repo.AJApp.Navigation.GlobalActions.Lesezeichen.Click();       	
	    }
       	IList<TreeItem> treeItems = repo.AJApp.OverviewAreas.Lesezeichen.Self.Find<TreeItem>(".//treeitem", 1000); 
       	IEnumerator<TreeItem> treeIterator = treeItems.GetEnumerator();
       	bool itemFound = false;
       	
       	while (treeIterator.MoveNext() && !itemFound){
       		TreeItem item = treeIterator.Current;
       		JavaObjectWrapper dataWrapper = (JavaObjectWrapper)item.Element.GetAttributeValue("Data");
       		Object displayNameText = dataWrapper.GetProperty("DisplayName");
       		
       		if(displayNameText != null && bookmarkText.Equals(displayNameText.ToString())){
       			itemFound = true;
       			item.DoubleClick();
       			Report.Success("Bookmark for" + bookmarkText + " found and clicked");
       		}
       	}
       	if(!itemFound){
         		Validate.Fail("No bookmark with text  " + bookmarkText + " found");
         }  
       }


Thanks anyway for the help!

Lawrence

Vaughan.Douglas
Posts: 250
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

Re: Accessing advanced, dynamic data in user code

Post by Vaughan.Douglas » Mon Jul 03, 2017 4:51 pm

I missed a step when looking at the image, sorry. Also this is just sudo code, I don't know if it will actually compile as is.
Object data = item.Element.GetAttributeValue("Data");  
    String displayNameText = data.PropertyNames("displayName");
you should be able to add your Data object to a watch and from there drill in.
Doug Vaughan