Does an object have to be in Repository to use Info?

Ranorex Spy, Recorder, and Studio.
winnicki
Posts: 5
Joined: Wed Sep 14, 2011 5:54 pm

Does an object have to be in Repository to use Info?

Post by winnicki » Thu Nov 03, 2011 10:33 pm

I'm doing web testing and I need to check if an object exists or not. Sometimes it does and other times it does not. I can use try / catch and then it just throws an exception when the path isn't found, but I read on your site that you can do something like this which I think is a better approach:

// Use the 'Info' object to check existence of the
// 'TextOnline' item which uses the following RxPath:
// statusbar/text[@accessiblename='Online']
// This way you can wait with the timeout specified for
// the item within the repository for the text 'Online'
bool statusTextConnected = repo.MyApp.TextOnlineInfo.Exists();

The thing is, I don't actually use the repository that Ranorex. I have my own repository class that contains getter methods for objects. The reason for this is that the Ranorex repository gets too disorganized.
So my question is.. can I still use the Info object on elements if they are not from the ranorex repository?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Does an object have to be in Repository to use Info?

Post by Support Team » Fri Nov 04, 2011 12:07 pm

Hi,

You can use the Exists(...) methods of the Validation class, for additional information about the methods please take a look at our online API: Namespaces ► Ranorex ► Validate ► Exists()


Regards,
Markus
Ranorex Support Team
.
Image

winnicki
Posts: 5
Joined: Wed Sep 14, 2011 5:54 pm

Re: Does an object have to be in Repository to use Info?

Post by winnicki » Fri Nov 04, 2011 9:17 pm

Perfect, thanks. I did see the Validate.Exists method but most of them are void however I found the one that does return bool and this is what I need.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Does an object have to be in Repository to use Info?

Post by Support Team » Mon Nov 07, 2011 6:43 pm

There's more than one way to check for the existence of an object using its RanoreXPath, see this section in the Ranorex User Guide. You can also use the TryFindSingle method:
Element elem;
if (Host.Local.TryFindSingle("/yourPath", out elem))
    ; // element found

Form myApp = ...; // insert code to find the app form
Button button;
if (myApp.TryFindSingle<Button>("pathToButton", out button))
    ; // button found
Regards,
Alex
Ranorex Team
.
Image