HOW TO pass a Repo element as an argument into a method?

Ask general questions here.
dugovic.milan
Posts: 41
Joined: Wed Jun 29, 2016 1:19 pm
Location: Frankfurt, Germany
Contact:

HOW TO pass a Repo element as an argument into a method?

Post by dugovic.milan » Fri Jan 27, 2017 9:14 am

Hey guys, is it actually possible to pass a Ranorex element into a custom C# method? What kind of type should the argument/parameter be? Any thoughts on this? Thank you
Ranorex 8.3.0

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

Re: HOW TO pass a Repo element as an argument into a method?

Post by odklizec » Fri Jan 27, 2017 9:25 am

Hi,

Yes, it's possible to pass the repo element to method. You can pass it either as an Adapter or RepoItemInfo...

Code: Select all

TestMethod(Adapter argument1, RepoItemInfo argument2)
I would suggest using RepoItemInfo instead of Adapter and then if needed, convert the RepoItemInfo to Adapter inside the given method. If you pass the repo item as an Adapter, Ranorex will always search (whole effective timeout) for the element during the method execution. This does not happen in case of passing RepoItemInfo.
Last edited by odklizec on Fri Jan 27, 2017 9:33 am, edited 1 time in total.
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

dugovic.milan
Posts: 41
Joined: Wed Jun 29, 2016 1:19 pm
Location: Frankfurt, Germany
Contact:

Re: HOW TO pass a Repo element as an argument into a method?

Post by dugovic.milan » Fri Jan 27, 2017 9:31 am

Thanks odklizec. I knew I can rely on you every time :D

EDIT: How can I convert RepoItemInfo to adapter?
Ranorex 8.3.0

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

Re: HOW TO pass a Repo element as an argument into a method?

Post by odklizec » Fri Jan 27, 2017 9:56 am

You can do it like this...

Code: Select all

TestMethod(RepoItemInfo repoInfoElement)
{
    Ranorex.Unknown itemAdapter = repoInfoElement.CreateAdapters<Ranorex.Unknown>();
}
Using 'Unknown' is handy if you want to create a generalized adapter, but it provides only basic properties for given repo element. To access the element specific attributes, you need to replace 'Unknown' adapter with more specific adapter.
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

dugovic.milan
Posts: 41
Joined: Wed Jun 29, 2016 1:19 pm
Location: Frankfurt, Germany
Contact:

Re: HOW TO pass a Repo element as an argument into a method?

Post by dugovic.milan » Fri Jan 27, 2017 10:23 am

odklizec wrote:You can do it like this...

Code: Select all

TestMethod(RepoItemInfo repoInfoElement)
{
    Ranorex.Unknown itemAdapter = repoInfoElement.CreateAdapters<Ranorex.Unknown>();
}
Using 'Unknown' is handy if you want to create a generalized adapter, but it provides only basic properties for given repo element. To access the element specific attributes, you need to replace 'Unknown' adapter with more specific adapter.
Can you give me some examples how to specify an adapter?
Ranorex 8.3.0

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

Re: HOW TO pass a Repo element as an argument into a method?

Post by odklizec » Fri Jan 27, 2017 12:20 pm

Simply replace 'Unknown' with any other available adapter for given element (e.g. Text, Form,...). If you type Ranorex. Ranorex intellisense should provide you with a list of available adapters. You just have to select the appropriate one, based of the Preferred Capability for given repo element (check it via Spy).
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