Page 1 of 1

Validate.Exists to initialize

Posted: Thu Sep 11, 2014 8:32 am
by rotciv
Hello
I have a general question and wonder if you could help

in order to play safe and at the same time not to waste time I am doing very similar thing twice always in the code:

Code: Select all

 
if (Validate.Exists(repo.LoginWindow.SelfInfo.AbsolutePath, new Duration(20000),
                        "Check Object '{0}'", new Validate.Options(false, ReportLevel.Info)))
{
     var loginWindow = repo.LoginWindow.Self;
...
the purpose is to
1) control the process and to act only if Login exists
2) not to waste some default search time as it would be in case if I replaced it with only one line
loginWindow = repo.LoginWindow.Self. So if it didnt exist it would have waited much longer than 20s - I dont want to replace default wait time as in other case I want to wait longer


I dont like what I am doing as it seems that
1) the same thing is done twice - ie Ranorex is searching for teh same object first time when I am checking whether it exists and second time when I am initializing loginWindow - so twice amount of search time
2) the code is longer


is it possible to achieve the same result in a better way (for example initializing loginWindow at the time when I am doing Exists)?

thanks for your help,
rotciv

Re: Validate.Exists to initialize

Posted: Thu Sep 25, 2014 4:53 pm
by krstcs
There are many answers to that question, most depending on how your application under test (AUT) is coded. If you posted a snapshot of your AUT (or a demo that is similar) it would help us understand the problem better.


For example, if the login container is a child of another element that you know will be there, you can search for that parent first. There may be some attribute of the direct parent that gives a hint as to the state of the inner objects. Say you have the following structure in a web page:

Code: Select all

<div @id='UserDialog_Container' @dialog_state='login_dialog'>
    <div @id='login_dialog'> ... </div>     <--- This might change and the @dialog_state ^ above would change to match
    <div @id='newPassword_dialog'> ... </div>
</div>
In this case you could search for the UserDialog_Container div and check if it's @dialog_state attribute is set to 'login'.


So, TLDR; look at the parent and see if you can use its state to figure out what it contains.

Re: Validate.Exists to initialize

Posted: Thu Sep 25, 2014 10:30 pm
by Support Team
Let me summarize: you want to wait for a repo item to appear, but use a different timeout value then specified in the repo item, and not throw an exception if the item is not found in time. And if the item is found, you want to work with the adapter right away. Right?

Sadly, the RepoItemInfo object does not provide such a method right now. It has an "Exists(out Adapter)" method returning an adapter instance, but currently you cannot provide a different timeout.

However, we already have that feature request in our list and I will see if we can add such a method (i.e. RepoItemInfo.Exist with a timeout argument and an out argument returning the adapter instance) in one of our next releases.

Currently, I would use a Host.Local.FindSingle call with the path from the repo item and wrap it into a Try/Catch block. That would at least avoid the duplicate search for the element.

Regards,
Alex
Ranorex Team