Page 1 of 1

Use seperate class as user code

Posted: Thu Jul 25, 2013 3:36 pm
by Patrick Kunst
Hi there,
Currently I am testing Ranorex and now I have a question.
Is it possible to use methods like you can do it with the user code but from separated classes?
I only found "Using Code Modules within Test Cases" but this is not exactly what I am looking for.

I want to write a class called GeneralActions.cs and write some methods for example for unexpected window handling. So this code is used in more than one Record. My question is this possible or have i call the methods of this class in the user coder?

Re: Use seperate class as user code

Posted: Thu Jul 25, 2013 5:42 pm
by sergii
You can just create in your GeneralActions.cs "shared" methods and fields and call them from other user codes files.


GeneralActions.cs:
...
namespace Patrick
...
public static void MakeActive (string xpath)
{
///some cool stuff
}
...
public static class Shared
{
public static string StringClipBoard { get; set; }
/// Some shared variables.
}
...



Then is your other files you can just call "shared" things.
Test.cs:
...
namespace Patrick
...
Shared.StringClipBoard = localVariable;
MakeActive(localVariable);




OtherTest.cs:
var newLocalVariable = Shared.StringClipBoard;

Re: Use seperate class as user code

Posted: Thu Jul 25, 2013 5:55 pm
by krstcs
You can also derive your generic class from ITestModule and then derive your test classes from your generic class. Put your generic functions in the generic class and they will be available to all derived classes.

You will have to go into UserCode to be able to use any of this though. Ranorex is not as extensible as it would have to be to include custom code in the rxrec module view.

Maybe they will get there eventually. They make improvements all the time around here.

Re: Use seperate class as user code

Posted: Fri Jul 26, 2013 8:15 am
by Patrick Kunst
Thnak you for your fast replys.
I will try it.