Page 1 of 1
shortcuts
Posted: Fri May 12, 2017 8:01 am
by giuseppe.lacagnina
Dear All,
I am using C# quite a lot in my tests and I have a question. I often have expressions like
repo.A.B.C.D.x
repo.A.B.C.D.y
is there a way to define some object ob that will represent repo.A.B.C.D such that I can have the definition and then
ob.x
ob.y
? That would be cool!
Thanks!!!
Re: shortcuts
Posted: Fri May 12, 2017 8:06 am
by odklizec
Hi,
No, there is no such a thing (as far as I know). But are you aware that you can actually pass a repo item to your methods as a parameter? This way you can either reduce the amount of hardcoded repo items in code and also the name of repo item in code will be much shorter
It's definitely not a very good idea to address the repo items directly in code. You should always pass them as a parameter.
Re: shortcuts
Posted: Fri May 12, 2017 8:37 am
by giuseppe.lacagnina
Hi.
Thanks! Do you have a good reference on passing repo items as parameters?
What I find confusing is that for a repo obj ob, sometimes I need to use ob itself and sometimes
obInfo. I could not find a way to handle this without having to pass two objects.
Thanks again for your help!
Re: shortcuts
Posted: Fri May 12, 2017 9:17 am
by odklizec
In my opinion, it's always best to pass the element as RepoItemInfo. The difference between Info and Adapter object is, that with Info object, Ranorex access element attributes (some of them) without actually accessing the element's UI. So it does not wait for the element appearance and does not throw an exception in case the element is not found. So this is why it's better to use Info object to pass the repo element to method. However, the info object does not have access to all element's attributes. So you may need to convert the Info object to Adapter (using CreateAdapter or CreateAdapters) later in your code.
Re: shortcuts
Posted: Fri May 12, 2017 9:21 am
by giuseppe.lacagnina
Thanks!
I had a problem. I used CreateAdapter to get the adapter, to call Click() on the item, but the click simply did not happen. I suppose I will have to try some more.
Re: shortcuts
Posted: Fri May 12, 2017 7:57 pm
by ahoisl
giuseppe.lacagnina wrote:is there a way to define some object ob that will represent repo.A.B.C.D such that I can have the definition and then
Sure, this is possible. The repository generates distinct types (inheriting from RepoGenBaseFolder) for every folder/appfolder. So, why not just give it a try?
var appFolder = repo.A;
var parentFolder = appFolder.B;
var someFolder = repo.A.B.C;
giuseppe.lacagnina wrote:What I find confusing is that for a repo obj ob, sometimes I need to use ob itself and sometimes
obInfo.
The "RepoItemInfo" object is just a description of the repository item, i.e. it knows the RxPath to search, the search timeout, the repository folder structure, and so on. It's just a repository object, not a real UI element.
To get an element you can interact with, i.e. an object that represents a UI element, you need to search for the corresponding RxPath the RepoItemInfo object stores, which will then give you the corresponding Adapter if (and only if) the element is found within the search timeout. The CreateAdapter method will just do that: it searches for the RxPath associated with the info object and returns the adapter if it finds the element.
Regards,
Alex
Ranorex Team
Re: shortcuts
Posted: Mon May 15, 2017 2:01 pm
by giuseppe.lacagnina
Well, thanks a lot for the excellent ideas! I will try them out immediately and come back here in case of questions.
Cheers,
Giuseppe
Re: shortcuts
Posted: Tue May 16, 2017 8:07 am
by giuseppe.lacagnina
ahoisl wrote:
To get an element you can interact with, i.e. an object that represents a UI element, you need to search for the corresponding RxPath the RepoItemInfo object stores, which will then give you the corresponding Adapter if (and only if) the element is found within the search timeout. The CreateAdapter method will just do that: it searches for the RxPath associated with the info object and returns the adapter if it finds the element.
I tried, in a method (item is of RepoItemInfo)
Adapter adapter = item.CreateAdapter(true);
but I get the following compilation error
The type arguments for method 'Ranorex.Core.Repository.RepoItemInfo.CreateAdapter<T>(bool)' cannot be inferred from the usage. Try specifying the type arguments explicitly. (CS0411) -
Re: shortcuts
Posted: Tue May 16, 2017 8:16 am
by ahoisl
You have to specify an adapter type, e.g. Button or Form, but you have to make sure that the element supports that adapter. You can always use
Unknown, which does not have any required capabilities:
var adapter = item.CreateAdapter<Ranorex.Unknown>(true);
Regards,
Alex
Ranorex Team
Re: shortcuts
Posted: Tue May 16, 2017 8:21 am
by giuseppe.lacagnina
Done, it works. Thanks a million!!!
Giuseppe