Code module in recording module

Ranorex Studio, Spy, Recorder, and Driver.
swmatisa
Posts: 123
Joined: Fri Aug 05, 2011 7:52 am

Code module in recording module

Post by swmatisa » Wed Sep 21, 2011 3:07 pm

WinXP SP3 (WindowsUpdate done)
Ranorex 3.1.0
*********************************
Hello,
Could you please give me information to solve my problem :
I need often to do the some job between 2 actions of a record module. The job is always the same except a parameter that I can put in a variable.

I try:
  • 1) To create a code module, but I cannot call it (or find to call it) in an action of a recording module, only between recording modules.
    2) I can create a user code to do the job, but I must redo the same in each recording module.
Any other idea ?

Thanks for your help
SW

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Code module in recording module

Post by Support Team » Wed Sep 21, 2011 4:28 pm

Hi,

Since 3.1 you are able to call methods from your C# classes or UserCode modules in your Recording window.
At first you have to create a "normal" C# class or a UserCode module. There you can add public methods.
Your Recording.UserCode class has to derive from the new C# class or from your UserCode Module.
Now you can add an UserCode Action in your Recording file and as method you can select your public methods from the C# class or from your UserCode Module.

Regards,
Markus
Ranorex Support Team

swmatisa
Posts: 123
Joined: Fri Aug 05, 2011 7:52 am

Re: Code module in recording module

Post by swmatisa » Fri Sep 23, 2011 2:52 pm

Support Team wrote: Your Recording.UserCode class has to derive from the new C# class or from your UserCode Module.
It is working, but I see some strange behaviour (bug?) on rename.

To reproduce:
  • 1) Write the code of function "toto" in the Parent of Recording.UserCode
    2) Build
    3) Add UserCode "toto"
    4) Build (all is OK)
    5) Rename "toto" to "titi"
    6) Build or Rebuild (No error)!!!
Regards
SW

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Code module in recording module

Post by Support Team » Tue Sep 27, 2011 8:48 am

swmatisa wrote:Parent of Recording.UserCode
What do you mean with the Parent of the User Code? Are you writing your code in the Recording1.cs?

Regards,
Peter
Ranorex Team

swmatisa
Posts: 123
Joined: Fri Aug 05, 2011 7:52 am

Re: Code module in recording module

Post by swmatisa » Wed Sep 28, 2011 7:50 am

Support Team wrote:At first you have to create a "normal" C# class or a UserCode module. There you can add public methods.
Your Recording.UserCode class has to derive from the new C# class or from your UserCode Module.
Now you can add an UserCode Action in your Recording file and as method you can select your public methods from the C# class or from your UserCode Module.
I follow your explanations. So I create a common class for all my "Recording.UserCode":
public class TestModuleCommon
	{
		public TestModuleCommon()
		{
		}
		public void Toto()
		{
			// Job
		}
And I derive my Recording.UserCode from TestModuleCommon
public partial class CheckGui0 : TestModuleCommon
    {
...
And I add "User Code" with method name Toto in CheckGui0.rxrec

Regards
SW

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Code module in recording module

Post by Support Team » Wed Sep 28, 2011 11:26 am

Hi,

you meant that you have renamed the Method Name from the User Code action in the Recording view to titi?
If so this is not a bug, this will create a new empty method with the specific name in the Recording.UserCode class.

Regards,
Markus
Ranorex Support Team

swmatisa
Posts: 123
Joined: Fri Aug 05, 2011 7:52 am

Re: Code module in recording module

Post by swmatisa » Wed Sep 28, 2011 4:16 pm

Support Team wrote:you meant that you have renamed the Method Name from the User Code action in the Recording view to titi?
No I rename in the TestModuleCommon:
public class TestModuleCommon  
    {  
        public TestModuleCommon()  
        {  
        }  
        public void Titi()  // Old Toto
        {  
            // Job  
        }
Regards
SW

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Code module in recording module

Post by Support Team » Thu Sep 29, 2011 10:56 am

Hi,

Okay that's the same as I have written, the only difference is that Ranorex now creates a Method named "Toto" in the Recording.UserCode.cs file.

Regards,
Markus
Ranorex Support Team

swmatisa
Posts: 123
Joined: Fri Aug 05, 2011 7:52 am

Re: Code module in recording module

Post by swmatisa » Fri Sep 30, 2011 6:50 am

Support Team wrote:Okay that's the same as I have written, the only difference is that Ranorex now creates a Method named "Toto" in the Recording.UserCode.cs file.
OK, but it is a non intuitive behavior. In code, when I rename a function (with an IDE) , all references to this function are also renamed. Another possibility is to generate a warning for empty UserCode.

I understand your point of view, but from mine, it is really near from a bug.

Regards
SW

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Code module in recording module

Post by Support Team » Fri Sep 30, 2011 9:34 am

Hi,

Okay I also understand your point of view, so we will discuss it with the relevant developers.

Regards,
Markus
Ranorex Support Team