How does the RepoItemInfo.Exists() function work inside?

Ask general questions here.
semate
Posts: 3
Joined: Tue Jul 03, 2018 7:42 am

How does the RepoItemInfo.Exists() function work inside?

Post by semate » Thu Nov 08, 2018 10:13 am

Hello!

The Exists() functions works well on a RepoItemInfo Item.
But what if you only have a RxPath? Well, sure you can create an Adapter. Is TryFindSingle() of the Adapter the equivalent of the Exists() function of the RepoItemInfo? Or is there more to it?

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

Re: How does the RepoItemInfo.Exists() function work inside?

Post by odklizec » Thu Nov 08, 2018 10:23 am

Hi,

Exists() method accepts both repoiteminfo and rxpath. I would suggest to check the Exists() method overloads (just type "Validate.Exists(" and scroll through the available overloads, using up/down keys), eventually, check the Ranorex API documentation, available here:
https://www.ranorex.com/Documentation/Ranorex/
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

semate
Posts: 3
Joined: Tue Jul 03, 2018 7:42 am

Re: How does the RepoItemInfo.Exists() function work inside?

Post by semate » Thu Nov 08, 2018 10:41 am

Hi!

Good point from odklizec using the global Validate.Exists() function. But the TryFindSingle or FindSingle would already provide me with the Adapter. Otherwise I would have to search the path twice, once for the exists check and once for the adapter creation, wouldn't I? So I'm still wondering if all these functions are actually end up doing the same or if they differ inside?

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

Re: How does the RepoItemInfo.Exists() function work inside?

Post by odklizec » Thu Nov 08, 2018 11:00 am

Hi,

How I see it, while both methods may look similar, Exists method is a simple validation action? The purpose of TryFindSingle is to check, if the element (for given xpath) exists and if does exists, create an adapter. If it does not exists, it returns "false", without throwing an exception. FindSingle, in contrary, throws an exception.
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

semate
Posts: 3
Joined: Tue Jul 03, 2018 7:42 am

Re: How does the RepoItemInfo.Exists() function work inside?

Post by semate » Thu Nov 08, 2018 2:09 pm

Hi!

Right! TryFindSingle and FindSingle seem to be two sides of the same coin. Ranorex just allows you to do the error handling you prefer (return value vs exception).

So I did some tests using the following code:

Code: Select all

Stopwatch sw = new Stopwatch();
RepoItemInfo mainFormInfo = repo.MyMainForm.SelfInfo;         	
RxPath rxpath=mainFormInfo.Path;
Debug.WriteLine("RepoItemPath:"+rxpath.ToString());         	
sw.Start();
bool ex1 = Validate.Exists(rxpath,Duration.FromMilliseconds(10000),"Exists RxPath",false);
sw.Stop();
Debug.WriteLine("Exists RxPath: "+ex1.ToString()+" in "+sw.ElapsedMilliseconds.ToString()+"ms");
sw.Reset();         	
sw.Start();
bool ex2 = Validate.Exists(mainFormInfo,"Exists RepoItemInfo",false);
sw.Stop();
Debug.WriteLine("Exists RepoItemInfo: "+ex2.ToString()+" in "+sw.ElapsedMilliseconds.ToString()+"ms");
sw.Reset();
sw.Start();
Element el=Element.FromPath(rxpath.ToString());
sw.Stop();
Debug.WriteLine("Create Element From Path in "+sw.ElapsedMilliseconds.ToString()+"ms");
sw.Reset();
sw.Start();
Unknown ad=Adapter.Create<Unknown>(el);
sw.Stop();
Debug.WriteLine("Create Element From Adapter in "+sw.ElapsedMilliseconds.ToString()+"ms");
sw.Reset();
sw.Start();
bool ex3 = Validate.Exists(mainFormInfo,"Exists Element",false);
sw.Stop();
Debug.WriteLine("Exists Element: "+ex3.ToString()+" in "+sw.ElapsedMilliseconds.ToString()+"ms");
sw.Reset();
sw.Start();
bool ex4 = Validate.Exists(mainFormInfo,"Exists Adapter",false);
sw.Stop();
Debug.WriteLine("Exists Adapter: "+ex4.ToString()+" in "+sw.ElapsedMilliseconds.ToString()+"ms");
... with the result:
Exists RxPath: True in 5844ms
Exists RepoItemInfo: True in 121ms
Create Element From Path in 19ms
Create Element From Adapter in 0ms
Exists Element: True in 87ms
Exists Adapter: True in 114ms

Next I flipped the first two calling methodes and restarted the test.

Code: Select all

...
sw.Start();
bool ex2 = Validate.Exists(mainFormInfo,"Exists RepoItemInfo",false);
sw.Stop();
Debug.WriteLine("Exists RepoItemInfo: "+ex2.ToString()+" in "+sw.ElapsedMilliseconds.ToString()+"ms");
sw.Reset();         	
sw.Start();
bool ex1 = Validate.Exists(rxpath,Duration.FromMilliseconds(10000),"Exists RxPath",false);
sw.Stop();
Debug.WriteLine("Exists RxPath: "+ex1.ToString()+" in "+sw.ElapsedMilliseconds.ToString()+"ms");
...
.. and the result was:
Exists RepoItemInfo: True in 6015ms
Exists RxPath: True in 155ms
Create Element From Path in 25ms
Create Element From Adapter in 0ms
Exists Element: True in 114ms
Exists Adapter: True in 114ms

It puzzles me that the first call seems to be by far the longest. That indicates that Ranorex is buffering something internally. The first method accessing this item than has to do most of the work. Could that be this is somewhere in the ElementEngine Singleton? BTW the Form I check for existance was always up. And the Spy was able to find the element in 17ms, which would approx. line up with the Create Element From Path value.

Interresting was also when I set the timer of the RxPath Validation from 10000 to 100:
Exists RxPath: False in 3212ms
Exists RepoItemInfo: True in 2870ms
Create Element From Path in 28ms
Create Element From Adapter in 0ms
Exists Element: True in 109ms
Exists Adapter: True in 96ms

I would have expected a lower value in the first one. Somewhere closer to 100ms.
Anyone any good explanation for this?

User avatar
RobinHood42
Posts: 239
Joined: Fri Jan 09, 2015 3:24 pm

Re: How does the RepoItemInfo.Exists() function work inside?

Post by RobinHood42 » Mon Nov 12, 2018 11:46 am

Hi,

Can't confirm that behavior. My results are around the following values:

Exists RxPath: False in 717ms
Exists RepoItemInfo: True in 2114ms

and (flipped)

Exists RepoItemInfo: True in 2326ms
Exists RxPath: False in 340ms

Tested with Ranorex 8.3.0

Cheers,
Robin