Repository item existence check in run time

Ask general questions here.
elis
Posts: 15
Joined: Sun Nov 10, 2013 10:27 am

Repository item existence check in run time

Post by elis » Wed Nov 20, 2013 7:11 pm

Hi all,

I am trying to check (in code level) if a form (from the repository) exists.
I tried to use : Validate.Exists(Xpath to form)

Since this function is void, I tried to catch the ValidationException but it's half solution since the Report shows a failure if this kind of exception is thrown.

I am sure there is a cleaner way to check if an item from the repository exists in run time.

Please help :)

Thanks,
Eli

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

Re: Repository item existence check in run time

Post by krstcs » Wed Nov 20, 2013 7:27 pm

If you just want to check if it exists (and not VALIDATE it exists...) then try this:

Code: Select all

if (repo.MyObjectParent.MyObject.SelfInfo.Exists()) {
    //do whatever you need to do here...
}
or, if it is a repo folder...

Code: Select all

if (repo.MyObjectParent.MyObjectInfo.Exists()) {
    //do whatever you need to do here...
}

The key is checking the SelfInfo object instead of the Self object.
Shortcuts usually aren't...

elis
Posts: 15
Joined: Sun Nov 10, 2013 10:27 am

Re: Repository item existence check in run time

Post by elis » Wed Nov 20, 2013 9:54 pm

Thanks!

I tried it but when the item does not exist the module is stuck.
Here is the code:

var repo = TestRepository.Instance;
var microTorrent331 = repo.MicroTorrent331;

if(microTorrent331.SelfInfo.Exists())
{
Report.Info(microTorrent331.SelfInfo.Exists().ToString());
}

When "microTorrent331.SelfInfo.Exists()" is false the execution is stuck.

Any ideas? :?

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

Re: Repository item existence check in run time

Post by krstcs » Wed Nov 20, 2013 10:19 pm

How long did you wait?

It should only be stuck for the timeout length, which is typically 30s.

You could add a little more too it to manipulate the timeout, like:

Code: Select all

var repo = TestRepository.Instance;
var microTorrent331 = repo.MicroTorrent331;

//Save the old duration...
Duration oldDur = microTorrent331.SearchTimeout;
//Set the new, temp duration...
microTorrent331.SearchTimeout = new Duration(500);  //500 ms, 1/2 sec.

if(microTorrent331.SelfInfo.Exists())
{
    Report.Info(microTorrent331.SelfInfo.Exists().ToString());
}

//Reset the original duration
microTorrent331.SearchTimeout = oldDur;
That would set a temporary 1/2 second timeout, and then set it back.

EDIT: You may need to use the INFO object again to get and set the search timeout, it depends on your repo structure.
Shortcuts usually aren't...

elis
Posts: 15
Joined: Sun Nov 10, 2013 10:27 am

Re: Repository item existence check in run time

Post by elis » Wed Nov 20, 2013 10:28 pm

Cool :)

Thank you!