If there is not disabled creation of complete ancestor subtree (in Ranorex settings), Ranorex should save a complete GUI tree, not just the one element you started from.
Anyway, I don't understand why do you want to recreate the GUI tree similar to the one in Spy? I think you just trying to reinvent the wheel
If you want to create a reference GUI tree (for comparing with actual GUI state), I would suggest to create a Ranorex snapshot from code and then use this snapshot as a reference or whatever do you want to do with it. In my opinion, it's way better option than to create your own (custom) GUI tree. Ranorex folks already put a lot of time and effort into creating and optimizing Spy tree, so why not to use it instead of creating a custom solution? Ranorex snapshot is just a GUI tree stored in file.
Check for example this sample, which compares a snapshot with actual web table...
http://www.ranorex.com/support/user-gui ... html#c8203
And here is a method I'm using for saving Ranorex snapshots from code (to create or re-create reference snapshots whenever needed):
Code: Select all
public void SaveSnasphot(Ranorex.Adapter repoElementToSave, string filename_ReferenceTableSnapshot)
ElementSnapshot elementSnapshot = ElementSnapshot.Capture(repoElementToSave, true);
var xmlDoc = elementSnapshot.SerializeXmlDoc();
FileStream fs = new FileStream(@filename_ReferenceTableSnapshot, FileMode.Create, FileAccess.ReadWrite, FileShare.Read);
Ranorex.Report.Log (ReportLevel.Info, "New reference table saved.");
You see, it's pointless to recreate something that already exists