How to call function from Recording Module? : Automation API

How to call function from Recording Module?

Class library usage, coding and language questions.

How to call function from Recording Module?

Postby EugeneF » Tue Aug 02, 2011 11: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?
EugeneF
 
Posts: 55
Joined: Fri Jul 29, 2011 1:26 am

Re: How to call function from Recording Module?

Postby Support Team » Wed Aug 03, 2011 2: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
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: How to call function from Recording Module?

Postby EugeneF » Wed Aug 03, 2011 6: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.
EugeneF
 
Posts: 55
Joined: Fri Jul 29, 2011 1:26 am

Re: How to call function from Recording Module?

Postby Support Team » Wed Aug 03, 2011 6: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
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: How to call function from Recording Module?

Postby EugeneF » Wed Aug 03, 2011 7: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?
EugeneF
 
Posts: 55
Joined: Fri Jul 29, 2011 1:26 am

Re: How to call function from Recording Module?

Postby Support Team » Wed Aug 03, 2011 10: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
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria


Return to Automation API

Who is online

Users browsing this forum: No registered users and 0 guests