Ranorex Class Library and repositories

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

Ranorex Class Library and repositories

Post by giuseppe.lacagnina » Thu Sep 15, 2016 2:11 pm

Dear All,

I have added to my solution a Class Library, which has methods shared by many test cases in a project from the same solution.

I would like to know whether it is possible to make the repository of the solution visible by the class library.

The application has an error dialog which keeps popping up, and I would like to define a method to deal with it inside my class library. This would let me define the method in one place and just call it inside the modules.

The problem is that I need the class library to access the repo items. Is that possible? Can anyone help?
Thanks!!!

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

Re: Ranorex Class Library and repositories

Post by odklizec » Fri Sep 16, 2016 9:21 am

Hi Giuseppe,

If I understand your problem right, you want to access the solution's repo from the class library? In this case, all you need to do is to instantiate repository in the class library of your choice, like this:
private static YourSolutionName.RepositoryName repo = SolutionName.RepositoryName.Instance;
Just modify this line of code according to your solution and put it after the code module constructor. Hope this helps?
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: Ranorex Class Library and repositories

Post by giuseppe.lacagnina » Fri Sep 16, 2016 9:26 am

Well, sounds very good! I just had no idea how to achieve this properly.
Thanks a lot! :D :D :D

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

Re: Ranorex Class Library and repositories

Post by giuseppe.lacagnina » Fri Sep 16, 2016 9:52 am

I have a problem.

In order to instantiate the repo in the class library, I have to add a reference of the project containing the repo to the class library.

This project, however, contains a reference to the class library and therefore there is a circularity issue.

Any way out of this?

Thanks!

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Ranorex Class Library and repositories

Post by krstcs » Fri Sep 16, 2016 1:35 pm

No, there's no way around it. You can't (and shouldn't) reference the test project in your library. The point of a library is that it can be used by many different projects. Referencing the test project in your library means your library is no longer independent.

If you want to use items from your project in methods in your library, your best bet is to define the library modules so that they take either a RepoItemInfo or Adapter object as parameters.

Code: Select all

public void MyLibraryMethod(RepoItemInfo myItemInfo) {
}
public void MyLibraryMethod(Ranorex.Adapter myAdapter) {
}


Then, in your test project, pass the element from your repo directly into the library method call.

Code: Select all

RepoItemInfo myButtonInfo = repo.MyApp.MyButtonInfo;
MyLibrary.MyLibraryMethod(myButtonInfo);
Also, when you create the library methods, make sure that they are very generic internally. You want to make them so that any test in the future that needs that functionality can use them.

In addition, if you find that you have to have references to a specific test project in a library method, then that method probably shouldn't be in the library, but in the test project.
Shortcuts usually aren't...

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

Re: Ranorex Class Library and repositories

Post by giuseppe.lacagnina » Fri Sep 16, 2016 1:52 pm

Ok, I will try this approach!
Thanks a lot for the excellent explanation.
Giuseppe