Use seperate class as user code

Ask general questions here.
Patrick Kunst
Posts: 9
Joined: Thu Jul 25, 2013 3:29 pm

Use seperate class as user code

Post by Patrick Kunst » Thu Jul 25, 2013 3:36 pm

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?

sergii
Posts: 30
Joined: Fri Jun 07, 2013 11:07 pm

Re: Use seperate class as user code

Post by sergii » Thu Jul 25, 2013 5:42 pm

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;

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

Re: Use seperate class as user code

Post by krstcs » Thu Jul 25, 2013 5:55 pm

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.
Shortcuts usually aren't...

Patrick Kunst
Posts: 9
Joined: Thu Jul 25, 2013 3:29 pm

Re: Use seperate class as user code

Post by Patrick Kunst » Fri Jul 26, 2013 8:15 am

Thnak you for your fast replys.
I will try it.