Treeview item operating

Class library usage, coding and language questions.
AndrewK
Posts: 4
Joined: Mon Feb 22, 2016 3:44 pm
Location: Germany, Ampfing
Contact:

Treeview item operating

Post by AndrewK » Wed Feb 24, 2016 1:42 pm

Dear all,
I need operate with simply win32 Treeview. Using Ranorex it's seems not too easy task.
I need to have possibility to click ItemA, which locates in treeview:

Root
|_ItemB
...... |_ItemA

...but just using string path: "Root|ItemB|ItemA" as argument

for example ranorex's competitor, the TestComplete can do this since 2001 and uses following code:

w = Form1.Window('ATL:*','Tree*'); - here we build w variable equal to TreeView object
w.Click('Root|ItemB|ItemA'); - here we simply cliked interesting us treeview item.

Ranorex by recording always maps each concrete treeview item-obect in repository wich can be accessed personally and derectly.

Is exists some way to access treeview items using basically string-path argument?

thank you

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Treeview item operating

Post by krstcs » Wed Feb 24, 2016 3:33 pm

First, please post a Ranorex Snapshot of the item, it will help us help you. http://www.ranorex.com/support/user-gui ... files.html

Second, you probably need to look into using Regular Expressions in your RanoreXPath statements. This will allow you to have one repo item that maps to many tree elements, based on data passed in at runtime.

If you get us the snapshot, as well as a detailed description of exactly what you are trying to accomplish in this situation, we can help you figure out the best XPath to use.
Shortcuts usually aren't...

AndrewK
Posts: 4
Joined: Mon Feb 22, 2016 3:44 pm
Location: Germany, Ampfing
Contact:

Re: Treeview item operating

Post by AndrewK » Wed Feb 24, 2016 4:01 pm

Thank you for rapid responce.
Unfortunatelly i'm not allowed post any url at posts. My snapshot of the item is more then 1 Mb allowed by forum rules. Is some1 way I can provide for you and for public my data?
Andrew.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3945
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Treeview item operating

Post by odklizec » Wed Feb 24, 2016 6:52 pm

Hi,

Just post the link enclosed in quote/code tags. This should help. Eventually, post the link without www/com strings :)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

AndrewK
Posts: 4
Joined: Mon Feb 22, 2016 3:44 pm
Location: Germany, Ampfing
Contact:

Re: Treeview item operating

Post by AndrewK » Thu Feb 25, 2016 12:49 pm

Hi again :)

This is snappy:

Code: Select all

dropbox.com/s/rd0z40a7rofys1a/TreeView-item.rxsnp?dl=0

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3945
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Treeview item operating

Post by odklizec » Thu Feb 25, 2016 1:25 pm

Hi,

Thanks for the snapshot.

Is there any particular reason, why you need to identify the element (ItemA) you want to click by its ItemB and Root parents? It's of course possible. However, with Ranorex xpaths, it's possible to identify the ItemA element just by its AccessibleName. You can, of course, to add also ItemB and Root references to the xpath, so the identification of element could be faster and more precise.

Recorder by default records/maps each clicked treeitem (or any other element) but if you want to make you repository cleaner and more automation friendly, you should reduce the number of recorded elements by using variables and/or regular expressions in the xpath. So then you can use just one treeitem repo element instead of every single recorded element with hardcoded names.

For example, let's say you have this xpath recorded in repository:
/form[@title~'^Cinegy\ Desktop\ \(Build:\ 10']//element[@controlid='955507960']//tree//treeitem[@accessiblename='TestFarm Portfolio']//treeitem[@accessiblename='LoadTesting']/treeitem[@accessiblename='Roll4JoinSplit']/treeitem[@accessiblename='Roll_1_PC-QA-08']
This xpath identifies "Roll_1_PC-QA-08" treeitem by by its parent elements Roll4JoinSplit (ItemB) and LoadTesting (Root). However, Ranorex would find the same element also by using this simplified xpath:
/form[@title~'^Cinegy\ Desktop\ \(Build:\ 10']//element[@controlid='955507960']//tree//treeitem[@accessiblename='Roll_1_PC-QA-08']
And best of all, you can make the path parametrized, by using variable:
/form[@title~'^Cinegy\ Desktop\ \(Build:\ 10']//element[@controlid='955507960']//tree//treeitem[@accessiblename=$varItemName]
So now you can have just one tree element saved in repository and then you have to fill the $varItemName variable with exact name of treeitem you want to find. The best is to use data connector to load the reference data (using excel, csv or sql db) containing the name of treeitem and connect it with repo/module variable.

To understand the Ranorex xpaths and repository workflow, I would strongly recommend you to check the Ranorex screencasts available here:
http://www.ranorex.com/support/screencasts.html

Additionally, read (and understand) also the Ranorex xpath chapter in User Guide:
http://www.ranorex.com/support/user-gui ... xpath.html

It's critical to understand the Ranorex xpaths, repository administration and usage of data connectors before you start with serious automation in Ranorex. Using recorder is fine to speed things up, but then you must cleanup recorded actions/repo and where required/suitable, make the repository elements parametrized with variables, regular expressions and relative paths.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

AndrewK
Posts: 4
Joined: Mon Feb 22, 2016 3:44 pm
Location: Germany, Ampfing
Contact:

Re: Treeview item operating

Post by AndrewK » Wed Mar 02, 2016 12:25 pm

hi odklizec,

Sorry for long responce.

Yes xPath is one powerfull feature of Ranorex, which does possible seek any GUI object.

I've stoped in situation with using variable, which contains path to my treevew item.

As you may be remember, I'v mapped several most important GUI elements of the tested app.

Image

RanorexSpy shows the path for treevew item:

Code: Select all

/form[@title~'^Cinegy\ Desktop\ \(Build:\ 11']//tree[@accessiblerole='Outline']/treeitem[@accessiblename='Cinegy Archive : master']/treeitem[@accessiblename='TestFarm Portfolio']/treeitem[@accessiblename='AutoTest']/?/?/treeitem[@accessiblename='Roll4JoinSplit']/treeitem[@accessiblename='Roll_1_PC-QA-08']
that means that I have to use in my variable TvItem some code like this:

Code: Select all

/treeitem[@accessiblename='Cinegy Archive : master']/treeitem[@accessiblename='TestFarm Portfolio']/treeitem[@accessiblename='AutoTest']/?/?/treeitem[@accessiblename='Roll4JoinSplit']/treeitem[@accessiblename='Roll_1_PC-QA-08']
I using following code for this:

Code: Select all

       public void Explorer_walking()
        {
        	var explorer_TreeView = repo.CMD_root.Explorer.Explorer_TreeView; // this is my mapped treeview
        	Report.Screenshot(explorer_TreeView);

        	var myItem = CMD.Recording1.Instance.TvItem; // this is path string
        	Report.Info(myItem);
        	var TestClick = explorer_TreeView.FindSingle<Ranorex.TreeItem>(myItem,2000);
        	
        	Report.Info(TestClick.ToString());
        	Report.Screenshot(TestClick);
        	TestClick.Click();        	
        	 
        }
My variable CMD.Recording1.Instance.TvItem contains following string:

Code: Select all

/treeitem[@accessiblename='TestFarm Portfolio']/treeitem[@accessiblename='AutoTest']/?/?/treeitem[@accessiblename='Roll4JoinSplit']/treeitem[@accessiblename='Roll_1_PC-QA-08'
The problm is that my code unable found the interested item.

What i do wrong?

Andrew

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3945
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Treeview item operating

Post by odklizec » Wed Mar 02, 2016 12:53 pm

Hi Andrew,

It's hard to say what's wrong without debugging your solution with a real-world example. But there is one thing I noticed.

If this is the xpath to Explorer_TreeView repo element:
/form[@title~'^Cinegy\ Desktop\ \(Build:\ ']/?/?/element[@class>'ATL:' and @windowtext='Explorer']/?/?/?/tree[@accessiblerole='Outline']

Then if you add this path (in Ranorex Spy) at the end of Explorer_TreeView xpath, it will fail to find the element:

Code: Select all

/treeitem[@accessiblename='TestFarm Portfolio']/treeitem[@accessiblename='AutoTest']/?/?/treeitem[@accessiblename='Roll4JoinSplit']/treeitem[@accessiblename='Roll_1_PC-QA-08']
And this is exactly what you are trying to do in your code.

I would suggest to change the CMD.Recording1.Instance.TvItem xpath to this (just add dot and additional slash at start):

Code: Select all

.//treeitem[@accessiblename='TestFarm Portfolio']/treeitem[@accessiblename='AutoTest']/?/?/treeitem[@accessiblename='Roll4JoinSplit']/treeitem[@accessiblename='Roll_1_PC-QA-08']
Hope this helps?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration