Page 1 of 1

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

Posted: Thu Nov 03, 2011 10:33 pm
by winnicki
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?

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

Posted: Fri Nov 04, 2011 12:07 pm
by Support Team
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

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

Posted: Fri Nov 04, 2011 9:17 pm
by winnicki
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.

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

Posted: Mon Nov 07, 2011 6:43 pm
by Support Team
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