Define a repository item in Code

Best practices, code snippets for common functionality, examples, and guidelines.
theraviz
Posts: 111
Joined: Sun Apr 14, 2019 9:46 am

Define a repository item in Code

Post by theraviz » Mon Aug 19, 2019 1:58 pm

Hello,

I am writing a reusable function in class file. I have converted some action to code where I have a function parameter - RepoItemInfo type. (divtagInfo)

I dont want this parameter in the reusable function as I will be just calling the function without passing parameter.

So I want to define the RepoItemInfo control inside the function itself. Please provide me the code on how to remove divtaginfo function parameter from the below code and define the same inside the code itself.
10.JPG
You do not have the required permissions to view the files attached to this post.

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

Re: Define a repository item in Code

Post by odklizec » Mon Aug 19, 2019 2:17 pm

Hi,

In my opinion, referencing elements via method parameter is the best approach! Defining repo element directly in method is wrong in long-term perspective. This could lead to messy and hard to maintain code.

If you still want to call repo element directly in mehtod, i.e. without using method parameters, you must instantiate the repository in class file with your custom method. You should add something like this:

Code: Select all

private static SolutionName.RepositoryNameRepository repo = SolutionName.RepositoryNameRepository.Instance;
Then simply call the repo element like this:

Code: Select all

repo.All.Folders.Leading.To.Element.elementinfo
But again, passing element to method via method's parameter is the best and most recommended approach!
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

theraviz
Posts: 111
Joined: Sun Apr 14, 2019 9:46 am

Re: Define a repository item in Code

Post by theraviz » Mon Aug 19, 2019 2:39 pm

Hi,

Sorry I couldn't get the below work around especially the element info part. I am new to this. Could you please provide more detailed code?

I tried the below but it has some errors. Kindly help.
11.JPG
12.JPG
You do not have the required permissions to view the files attached to this post.

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

Re: Define a repository item in Code

Post by odklizec » Mon Aug 19, 2019 2:46 pm

Hi,

From the code it looks as if StatusText is already an adapter? In case of Info element, it would be StatusTextInfo. So there should be no need to use FindAdapter.
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

theraviz
Posts: 111
Joined: Sun Apr 14, 2019 9:46 am

Re: Define a repository item in Code

Post by theraviz » Mon Aug 19, 2019 2:58 pm

Thanks again. It worked :)