Page 1 of 1

Usercode from library

Posted: Thu Nov 15, 2012 1:40 pm
by topcatalpha
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

Re: Usercode from library

Posted: Thu Nov 15, 2012 3:53 pm
by odklizec
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 ;)

Re: Usercode from library

Posted: Thu Nov 15, 2012 4:31 pm
by Support Team
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)

Re: Usercode from library

Posted: Thu Nov 15, 2012 5:31 pm
by topcatalpha
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

Re: Usercode from library

Posted: Fri Nov 16, 2012 1:44 pm
by Support Team
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)

Re: Usercode from library

Posted: Thu Dec 06, 2012 10:59 am
by orbistest
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

Re: Usercode from library

Posted: Thu Dec 06, 2012 12:02 pm
by Support Team
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)