Page 1 of 1

How to call function from Recording Module?

Posted: Tue Aug 02, 2011 10:56 pm
by EugeneF
Hi,

I have test cases with recording modules. I also have usercode files with functions that I need to call from recording modules.
How I can call them please?

Re: How to call function from Recording Module?

Posted: Wed Aug 03, 2011 1:32 pm
by Support Team
Hi,
The UserCodeModules and the Recording files are normal C# classes, so you can call their methods like
you would call them if you have “normal” C# classes.
You can create static methods in your UserCodeModule, then you won’t need an instance of it in the Recording or you can create "normal" public methods then you would need at first an instance of the UserCodeModule.

In your Recording file you can call the specific methods like these:

Code: Select all

TestCodeModule.testMethod();
            TestCodeModule testModule = new TestCodeModule();
            testModule.testMethod2();

The two methods in the TestCodeModule class:
     public static void testMethod(){
             System.Console.WriteLine("!!!!! UserCode !!!!");

        }
          public void testMethod2(){
             System.Console.WriteLine("!!!!! UserCode !!!!");

        }
I would suggest you to use static methods.

Regards,
Markus
Ranorex Support Team

Re: How to call function from Recording Module?

Posted: Wed Aug 03, 2011 5:06 pm
by EugeneF
Hi Marcus,

Thank you for your help. However, I cannot save any code in recording module - it disapears right after I move to another file - even if I saved it before.

Re: How to call function from Recording Module?

Posted: Wed Aug 03, 2011 5:18 pm
by Support Team
You cannot change the code in the "Recording.cs" file, only in the "Recording.UserCode.cs" file. The code for the "Recording.cs" file is regenerated every time the recording changes. Please, read following section in the Ranorex User Guide:
http://www.ranorex.com/support/user-gui ... tions.html

Regards,
Alex
Ranorex Team

Re: How to call function from Recording Module?

Posted: Wed Aug 03, 2011 6:25 pm
by EugeneF
So, again... If I cannot save recoding.cs how I can call it from recording file? Should I move recording.cs to usercode.cs and disabled recording module?

Re: How to call function from Recording Module?

Posted: Wed Aug 03, 2011 9:37 pm
by Support Team
Just add a User Code Action to the recording (using the recorder UI) and then you can use the code Markus posted in that User Code Action. It is documented quite detailed in the User Guide section I already posted before:
http://www.ranorex.com/support/user-gui ... tions.html

Regards,
Alex
Ranorex Team