Help on how to reuse code for a button clik

Class library usage, coding and language questions.
puntapret
Posts: 34
Joined: Fri Sep 14, 2012 11:05 am

Help on how to reuse code for a button clik

Post by puntapret » Thu Apr 24, 2014 11:07 am

Hi,

In my Repository, i have a button with a variable "actionName", that will be called with Add,Save, Cancel, Edit,Delete, etc ...

Code: Select all

.//button/text[@Name=$btnactioname]
What i want to do is on my recording, i can create a ClickButton that will just click the button above.

What i did so far, i created a code module :

Code: Select all

public class ClickActionBar : ITestModule
    {
        public static CommonGUIRepository repo = CommonGUIRepository.Instance;
        
        /// <summary>
        /// Constructs a new instance.
        /// </summary>
        public ClickActionBar()
        {
            // Do not delete - a parameterless constructor is required!
        }

        /// <summary>
        /// Performs the playback of actions in this module.
        /// </summary>
        /// <remarks>You should not call this method directly, instead pass the module
        /// instance to the <see cref="TestModuleRunner.Run(ITestModule)"/> method
        /// that will in turn invoke this method.</remarks>
        void ITestModule.Run()
        {
            Mouse.DefaultMoveTime = 300;
            Keyboard.DefaultKeyPressTime = 100;
            Delay.SpeedFactor = 1.0;
        }
        
        public void ClickActionName(string name)
        {
            repo.btnactionname = name;
            repo.Portal.FormControl.ActionBar.btnAction.Click();
        }
    }
But then, i realized that i don't know which Action should i add in my recording to call my User Code above. I know that i can add an User Code in my recording, but must i create a new method to call my ClickActionBar above ? And there will be multiple use of this ClickActionBar in the same recording, for example, click add, and then click save at the end, etc ...

I think what i want to do is quite commun, but i can't find an easy way.

Thanks in advance

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

Re: Help on how to reuse code for a button clik

Post by Support Team » Mon Apr 28, 2014 9:39 am

Hi,

When you want to use the method of the UserCodeModule in the Recording's action table you just need to follow the steps below:
  • Open the Recording.UserCode.cs file and add ... partial class Recording1 : UserCodeModule1 to inherit from your UserCodeModule
  • Open your Recording's action table again and select your UserCode method:
    UserCodeMethod.png
    UserCodeMethod.png (5.98 KiB) Viewed 987 times
Regards,
Markus
.
Image

puntapret
Posts: 34
Joined: Fri Sep 14, 2012 11:05 am

Re: Help on how to reuse code for a button clik

Post by puntapret » Wed May 07, 2014 3:35 pm

Support Team wrote:Hi,

When you want to use the method of the UserCodeModule in the Recording's action table you just need to follow the steps below:
  • Open the Recording.UserCode.cs file and add ... partial class Recording1 : UserCodeModule1 to inherit from your UserCodeModule
  • Open your Recording's action table again and select your UserCode method:
    UserCodeMethod.png
Regards,
Markus
Yes, i know how to do that, but what i want to know is how to pass parameters and bind it, and repeatedly using it.

For example, button with Action Name "Save", will be called 5 times in my recording.

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

Re: Help on how to reuse code for a button clik

Post by Support Team » Fri May 09, 2014 11:58 am

Hi,

When you want to use your code in the recording you can add it as described in my previous post. You just need to pass the value of the repository as string argument, you can of course also use a module variable as argument.

There is also another way to change the value of the specific repository variable by using a data connector.
You just need to follow these steps:
1. Open the recording where you want to execute the adapted UserCode method.
2. Open the VARIABLES.. window and select Copy Variable from Repository as shown below:
CopyVariable.png
CopyVariable.png (44.56 KiB) Viewed 961 times
3. Now you can bind the module variable btnactionname_ to a data source.
4. After you bound it you just need to add a click action to your action table using the specific repository item.

I hope this proves helpful!

Regards,
Markus
.
Image