Binding variables to recorded modules called via user code

Ask general questions here.
Pixi6s
Posts: 92
Joined: Tue Jun 28, 2011 8:57 pm

Binding variables to recorded modules called via user code

Post by Pixi6s » Tue Jul 05, 2011 8:15 pm

I created a User Code module that calls recording Modules

Code: Select all

        void ITestModule.Run()
        {
            int x = TestCase.Current.DataContext.CurrentRowIndex;
            if (x == 1)
            {
            	SetupShipping.Start();
            }else{
          	SetExistingShipping.Start();
            }
        }
Within SetupShipping I have several variables that I need to bind to a data source. Start doesn't take parameters and they no longer just appear in the data binding menu. How would I accomplish this?

Thanks

Pixi6s
Posts: 92
Joined: Tue Jun 28, 2011 8:57 pm

Re: Binding variables to recorded modules called via user code

Post by Pixi6s » Wed Jul 06, 2011 4:54 pm

Hello support team,

Is this possible? I have to finish this test soon and I need to know if I am going down the wrong path using record modules asap.

Thanks

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

Re: Binding variables to recorded modules called via user code

Post by Support Team » Wed Jul 06, 2011 7:56 pm

Hello,

Sometimes, for branches and special loops, it's necessary to start other modules from user code modules. Just be a aware that this way you are hiding things from the Test Suite view. And there is the problem to forward variables. A solution to the latter could be to manually create variables via Insert Module Variable in the editor's context menu and instead of using the string in the property you forward to the according variables in the called modules.
[TestVariable("A83ECAE2-3EB7-48B3-88BA-15AEC5AF4766")]
public string MyTestVariable
{
    get { return CalledRecording.Instance.MyTestVariable; }
    set { CalledRecording.Instance.MyTestVariable = value; }
}
We are currently working on an extension to the Test Suite to make this less necessary to manually call other modules.

Regards,
Roland
Ranorex Support Team

Pixi6s
Posts: 92
Joined: Tue Jun 28, 2011 8:57 pm

Re: Binding variables to recorded modules called via user code

Post by Pixi6s » Fri Jul 08, 2011 3:32 pm

This works great! Thanks

KAB
Posts: 10
Joined: Mon Jan 09, 2012 1:30 pm

Re: Binding variables to recorded modules called via user code

Post by KAB » Wed Jul 04, 2012 1:51 pm

Okay I've now tried to do somelike this, but somehow I can't get the variable from one code module to the other.

I have one solution handling all my instrument functions, which I've compiled to a .dll (Instruments.dll), which I've then included/added referrenced to in another solution.

Using the functions from Instruments.dll in the current solution, is working fine, when using the modules directly in the test suite, building test cases (drag-n-drop functions from Module browser to test cases). In which case I can assign values through data binding, and validate results this way.
But these test cases are somewhat confusing to look at, since the Instrument.dll is made with namings that referrence to a specific instruments, e.g RelayBoardRelay1On, DaqValidateAiCh101 and so on, so they can be used in any applications.
What I then do (or want to do) is wrap these modules in in a user code module containing e.g.:

Code: Select all

    [TestModule("20ECC8A8-36BB-4FBD-9743-2B7467489A1A", ModuleType.UserCode, 1)]
    public class DutExternalPowerOff : ITestModule
    {
        /// <summary>
        /// Constructs a new instance.
        /// </summary>
        public DutExternalPowerOff()
        {
            // 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()
        {
            ITestModule ExtPow = new Instruments.DaqU2351a.Ch501Bit3OffA();
            ExtPow.Run();

// Alternate way is:
// TestModuleRunner.Run(ExtPow);
        }

To make the test cases easier to read (in the rxtst file), as I now have a step in my test case called "DutExternalPowerOff" instead of "Ch501Bit3OffA (Instuments)".

My problem is now when I have an instrument function that takes variables as input for e.g. validating voltages. I have no problems if I just accept the "DaqValidateAiCh101 (Instruments)" step in my test case, because it will then say I have 2 unbound variables (upper and lower limit), which I can then just bind to values as appropiate. But when I wrap up this "DaqValidateAiCh101" in user code so I can get a "ValidateOutput1On" step, I can't seem to forward the desired limits to my public variables (upper and lower limit) in DaqValidateAiCh101 (which are created by "Insert Module Variable" function) and in the code module for the function in Instruments looks like:

Code: Select all

string _lowerLimit = "-10";
[TestVariable("483A5439-629F-4E1B-BE38-E4605ABD1B67")]
public string lowerLimit
{
    get { return _lowerLimit; }
    set { _lowerLimit = value; }
}

Trying to doing as described, I would think that I in my current solution I would have to do something like:

Code: Select all

string _outOnLow = "";
[TestVariable("773A5039-629F-4E1B-BE38-E4605ABD1B67")]
public string outOnLow
{
    get { return Instruments.DaqValidateAiCh101.lowerLimit; }
    set { Instruments.DaqValidateAiCh101.lowerLimit = value; }
}
But this isn't working, so I'm clearly missing something. I've also tried:

Code: Select all

ITestModule OutputOn = new Instruments.DaqValidateAiCh101();

[TestVariable("773A5039-629F-4E1B-BE38-E4605ABD1B67")]
public string outOnLow
{
    get { return OutputOn.Instance.lowerLimit; }
    set { OutputOn.Instance.lowerLimit = value; }
}

and some variations in between.

I don't need to get values back from the DaqValidateAiCh101 function, as that will pass/fail the measurement, and also write in the report, but I do need to get the correct limits into the DaqValidateAiCh101, as I currently gets a PASS verdict everytime, as the default values are the entire range of possible measurements.

Dang that was a long text/description, but hope it makes some sense, so someone can help me to understand what I'm missing.
Best regards
/KAB

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

Re: Binding variables to recorded modules called via user code

Post by Support Team » Thu Jul 05, 2012 1:42 pm

Hi,

That was much information at once ;).
Just a thought did you consider that if you add a CodeModule to your test suite a new/other instance of it is created just for the execution?

Regards,
Markus
Ranorex Support Team

KAB
Posts: 10
Joined: Mon Jan 09, 2012 1:30 pm

Re: Binding variables to recorded modules called via user code

Post by KAB » Thu Aug 09, 2012 9:59 am

Support Team wrote:Just a thought did you consider that if you add a CodeModule to your test suite a new/other instance of it is created just for the execution?
No I hadn't considered that, but for now readability of the test is more important than memory use.

Still haven't figured it out though, so I'll try phrasing the question differently.

Scenario:
One project handling instruments, converted to .dll for use in other projects. Names in the instrument project refers to instrument name/type and instrument channels. These functions may contain variables to set output (e.g. voltage on PSU) or limits for validating outputs (e.g. device output voltages)

Instrument.dll is used in new project, where I would like to obfuscate/wrap the instrument.dll functions, so they now make sense in respect to the current project (e.g. ValidateRecorderOn instead of ValidateCurrentPsuChannel2). Also, sometimes it is nice to combine multiple "small" functions in one bigger one(e.g. config multiple PSU channels and toggle multiple inputs to achieve one new state for the device/program under test), so the Project Test suite does not get so cluttered/long.

Problem:
Getting the variables set in the instrument.dll functions when I call them from user code.

Calling functions that takes no arguments (e.g. toggling an output on/off) is not a problem as there is created a function in instrument.dll for each output.
Calling functions that validate an arbitrare range, requires limits, as it is not "possible" to create functions for all different ranges.

I can drag the functions from the module browser to the project test suite, and then bind the variables to the step, but this gives for long project test suites, that are not easily maintained or understood, and especially so if the project is assigned a new person.

Short version of the question:
Is it possible to set the function test variables any other way than the data binding in project test suite?

/KAB

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

Re: Binding variables to recorded modules called via user code

Post by Support Team » Thu Aug 09, 2012 12:09 pm

Hi,

Yes, there are also other ways how you can set the variables of your classes from your Library, but how do you execute the methods respectively the classes?
I think the problem is that you create more than one instance of the same class, respectively you set the variable in a different instance of the same class.
Maybe it would help if you would use static classes or the singleton pattern.

Regards,
Markus
Ranorex Support Team