Usercode from library

Ask general questions here.
topcatalpha
Posts: 47
Joined: Tue Sep 06, 2011 7:48 am

Usercode from library

Post by topcatalpha » Thu Nov 15, 2012 1:40 pm

Hi,

Is there a way to use functions from a library as "usercode" action in a recordmodule, without implementing the functions in the usercode.cs file ?

We like to create librarys with common functions which should be used in several recordmodules. This could be interesting for people who do not develop.

regards,

Kurt

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

Re: Usercode from library

Post by odklizec » Thu Nov 15, 2012 3:53 pm

Good question! I was thinking about the same on yesterday, while implementing the same function in multiple usercodes, which I think is a prospective nightmare from the maintenance point of view. I'm not a programmer and my C# skills are currently pretty limited. So please don't laugh if it's an easy one ;)
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
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Usercode from library

Post by Support Team » Thu Nov 15, 2012 4:31 pm

Hello,

Yes. You can create your own DLL with your custom functions in Visual Studio.
Just create a new 'Class Library' in Visual Studio, add a few functions and reference it in your test solution.

Regards,
Markus (T)

topcatalpha
Posts: 47
Joined: Tue Sep 06, 2011 7:48 am

Re: Usercode from library

Post by topcatalpha » Thu Nov 15, 2012 5:31 pm

OK,

How can i use the functions of the library directly in the recording module by selection [Add new action] -> [user code] -> [Methode name]. Without writing the same functions from the library in the usercode.cs again.
To avoid duplicate work for every new recordingmodule.

Our goal is to provide a test automation library (dll) which can be used directly in a recording module. This way also non programmers can create new testcases with functions developers provide.

regards,

Kurt

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Usercode from library

Post by Support Team » Fri Nov 16, 2012 1:44 pm

Hello,

If you extend the recording class you could use methods of your modules of your library within a test suite as shown below:
public partial class Recording1 : ReportDLL.UserCodeModule1
ReportDLL is the name of the DLL and UserCodeModule1 is the class to be used.

Regards,
Markus (T)

orbistest
Posts: 23
Joined: Mon Oct 17, 2011 5:31 pm

Re: Usercode from library

Post by orbistest » Thu Dec 06, 2012 10:59 am

HElP - I am going mad ...??? :?

This is what I have done. VB.NET not C# .
I made a new solution and then added a project (RT-click/add new project/advanced/Ranorex Class Library) called MyLibrary.

Then in the MyNewClass.vb I added a public sub within the class -
Public Class MyNewClass
Public Sub MySub(arg1 as string)
... some code ...
End Sub
End Class

I build this and then close the project/solution.

Open a new solution - MyLibraryTest
add new existing project to add in the project with MyNewClass
add a reference in MyLibraryTest to this project

Now within a recording (e.g. Recording1.usercode.vb ) I add the following -
Public Partial Class recording1 : MyLibrary.MyNewClass

When I try to compile I get invalid End of statement.
I have noticed that if I use Intellisense and type ": MyLibrary." then I get offered a class My which is NOT the full class name.

Please - step by step - tell me what I am doing wrong ... :(
I want to have functions such as SetVariableTo( variable, value) in a shareable library which I can simply add to recordings using the Add/Usercode and selecting the function from the drop-down.

Many thanks.

orbistest

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Usercode from library

Post by Support Team » Thu Dec 06, 2012 12:02 pm

Hello,

The posted code snippet works only in C# (not in VB.NET).
Please use the following code to inherit your library:
Public Partial Class Recording1
	Inherits MyLibrary.MyLibrary.MyNewClass
Regards,
Markus (T)