How to call function from Recording Module?

Class library usage, coding and language questions.
EugeneF
Posts: 63
Joined: Fri Jul 29, 2011 12:26 am

How to call function from Recording Module?

Post by EugeneF » Tue Aug 02, 2011 10:56 pm

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?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to call function from Recording Module?

Post by Support Team » Wed Aug 03, 2011 1:32 pm

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
.
Image

EugeneF
Posts: 63
Joined: Fri Jul 29, 2011 12:26 am

Re: How to call function from Recording Module?

Post by EugeneF » Wed Aug 03, 2011 5:06 pm

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.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to call function from Recording Module?

Post by Support Team » Wed Aug 03, 2011 5:18 pm

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
.
Image

EugeneF
Posts: 63
Joined: Fri Jul 29, 2011 12:26 am

Re: How to call function from Recording Module?

Post by EugeneF » Wed Aug 03, 2011 6:25 pm

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?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to call function from Recording Module?

Post by Support Team » Wed Aug 03, 2011 9:37 pm

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
.
Image