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?
Does an object have to be in Repository to use Info?
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Does an object have to be in Repository to use Info?
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
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?
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.
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Does an object have to be in Repository to use Info?
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:
Alex
Ranorex Team
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 foundRegards,
Alex
Ranorex Team