shortcuts

Ask general questions here.
User avatar
giuseppe.lacagnina
Posts: 113
Joined: Fri Sep 18, 2015 10:25 am
Location: Brunn am Gebirge, Vienna, Austria

shortcuts

Post by giuseppe.lacagnina » Fri May 12, 2017 8:01 am

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!!!

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3945
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: shortcuts

Post by odklizec » Fri May 12, 2017 8:06 am

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.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

User avatar
giuseppe.lacagnina
Posts: 113
Joined: Fri Sep 18, 2015 10:25 am
Location: Brunn am Gebirge, Vienna, Austria

Re: shortcuts

Post by giuseppe.lacagnina » Fri May 12, 2017 8:37 am

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!

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3945
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: shortcuts

Post by odklizec » Fri May 12, 2017 9:17 am

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.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

User avatar
giuseppe.lacagnina
Posts: 113
Joined: Fri Sep 18, 2015 10:25 am
Location: Brunn am Gebirge, Vienna, Austria

Re: shortcuts

Post by giuseppe.lacagnina » Fri May 12, 2017 9:21 am

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.

ahoisl
Certified Professional
Certified Professional
Posts: 125
Joined: Fri Sep 07, 2007 8:16 am

Re: shortcuts

Post by ahoisl » Fri May 12, 2017 7:57 pm

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

User avatar
giuseppe.lacagnina
Posts: 113
Joined: Fri Sep 18, 2015 10:25 am
Location: Brunn am Gebirge, Vienna, Austria

Re: shortcuts

Post by giuseppe.lacagnina » Mon May 15, 2017 2:01 pm

Well, thanks a lot for the excellent ideas! I will try them out immediately and come back here in case of questions.

Cheers,

Giuseppe

User avatar
giuseppe.lacagnina
Posts: 113
Joined: Fri Sep 18, 2015 10:25 am
Location: Brunn am Gebirge, Vienna, Austria

Re: shortcuts

Post by giuseppe.lacagnina » Tue May 16, 2017 8:07 am

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) -

ahoisl
Certified Professional
Certified Professional
Posts: 125
Joined: Fri Sep 07, 2007 8:16 am

Re: shortcuts

Post by ahoisl » Tue May 16, 2017 8:16 am

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

User avatar
giuseppe.lacagnina
Posts: 113
Joined: Fri Sep 18, 2015 10:25 am
Location: Brunn am Gebirge, Vienna, Austria

Re: shortcuts

Post by giuseppe.lacagnina » Tue May 16, 2017 8:21 am

Done, it works. Thanks a million!!!

Giuseppe