Global parameters - recordings' variables binding

Ask general questions here.
dman
Posts: 64
Joined: Mon Aug 29, 2011 9:33 am
Location: München

Global parameters - recordings' variables binding

Post by dman » Tue Sep 13, 2011 4:23 pm

it's described pretty clear ("Lesson 3") how to "combine" them but... what exactly does that mean? does the binding have one direction? I'm asking because I created a global parameter and gave it a value, after wich I created a variable for a recording and performed the binding in a testcase - as I ran the TC, the variable was empty... am I missing some small print somewhere?

All the best!
D.

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

Re: Global parameters - recordings' variables binding

Post by Support Team » Wed Sep 14, 2011 11:49 am

Hi,

As the global parameters are set/saved in the Test Suite file you have to execute the whole Test Suite, otherwise Ranorex is not able to get the values of the global parameters out of the Test Suite.

Regards,
Markus
Ranorex Support Team

dman
Posts: 64
Joined: Mon Aug 29, 2011 9:33 am
Location: München

Re: Global parameters - recordings' variables binding

Post by dman » Wed Sep 14, 2011 12:31 pm

Hi Markus,

Thank you for the reply. Indeed, when running the suite, the bound variable gets the parameter's value. Your remark should be emphasized in the documentation.

What about the binding’s direction? What happens if I modify (in code) a variable (bound to a parameter)? What happens if I modify (in code) a parameter (is this possible?) to which a variable was bound?

All the best,
D.

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

Re: Global parameters - recordings' variables binding

Post by Support Team » Wed Sep 14, 2011 3:21 pm

Hi,
What happens if I modify (in code) a variable (bound to a parameter)?
As module variables are normal properties you can also use them like properties. That means if you set the variable to another value (in code at runtime) the new value will be taken instead of the value of the global parameter.
What happens if I modify (in code) a parameter (is this possible?) to which a variable was bound?
This is possible but not recommended.
You can set or create global parameters at runtime, but you have to make it before the specific TestCase, where you have bound the variables, is called.
TestSuite.Current.Parameters.Add("GlobalParam3", "30"); //creates a new one
            TestSuite.Current.Parameters["GlobalParam2"]="30"; //overrides the parameter with the specific name
            var testSuite = (TestSuite)TestSuite.Current;
            var testCase = (TestCase)TestSuite.Current.GetTestCase("TestCase");
            var testSuiteModule = testCase.AllModules[0]; // the first module from the specific test case
            testSuiteModule.AddDataBinding(new ModuleVarItem("variable1", new Guid("07bef6aa-2cd3-4ac5-92de-ae42bc078ccf"), "Recording1", ""),
            new ParameterDataBindingInfo("GlobalParam3", 
            testSuite.TestSuiteEntry.Id.ToString(), (TestCase)TestCase.Current));// the new data binding, variable1 is the variable from the specific recording
Kind Regards,
Markus
Ranorex Support Team

dman
Posts: 64
Joined: Mon Aug 29, 2011 9:33 am
Location: München

Re: Global parameters - recordings' variables binding

Post by dman » Wed Sep 14, 2011 3:44 pm

Support Team wrote: ... That means if you set the variable to another value (in code at runtime) the new value will be taken instead of the value of the global parameter.
Does this mean that binding is just an initialization (of the variable with the global parameter's value)?

The second part of your answer is unfortunately of no help to me.

My problem: I have a solution, with multiple projects (and hence multiple repositories). There are certain solution-relevant values which I set as "global parameters" (I would only need to read them, though writing would also help). I can do the global parameter - recording variable binding (which works just fine) but I'd have to create a variable every time I need a global parameter - not quite optimal.

Long story, short: what I basically need is a way to globally access some information/variables.


All the best!
D.

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

Re: Global parameters - recordings' variables binding

Post by Support Team » Thu Sep 15, 2011 9:20 am

Hi,
Long story, short: what I basically need is a way to globally access some information/variables.
There are more ways to handle this, you can generate a C# Code file (static class or normal public as you like) where you can collect all your "global" parameters or you can directly access the "Ranorex global parameters" through this code:
IDictionary<string, string> idict = TestSuite.Current.Parameters;
Regards,
Markus
Ranorex Support Team

dman
Posts: 64
Joined: Mon Aug 29, 2011 9:33 am
Location: München

Re: Global parameters - recordings' variables binding

Post by dman » Thu Sep 15, 2011 9:52 am

Brilliant! Exactly what I needed :D

Thank you!
D.

User avatar
slavikf
Posts: 104
Joined: Mon Sep 13, 2010 9:07 pm
Location: Toronto, Canada
Contact:

Re: Global parameters - recordings' variables binding

Post by slavikf » Thu Sep 15, 2011 4:26 pm

There are more ways to handle this, you can generate a C# Code file (static class or normal public as you like) where you can collect all your "global" parameters
So, this code (with global variables) should be part of Program class? Or what is the right way?
or you can directly access the "Ranorex global parameters" through this code:
IDictionary<string, string> idict = TestSuite.Current.Parameters;
Can you bring an example?

dman
Posts: 64
Joined: Mon Aug 29, 2011 9:33 am
Location: München

Re: Global parameters - recordings' variables binding

Post by dman » Fri Sep 16, 2011 8:12 am

this is how I did it:

Code: Select all

IDictionary<string, string> idict = TestSuite.Current.Parameters;
string PBDomain = idict["MyDomain"];
with MyDomain defined as global parameter

kathleen71
Posts: 1
Joined: Fri Nov 04, 2011 12:52 pm

Re: Global parameters - recordings' variables binding

Post by kathleen71 » Fri Nov 04, 2011 12:53 pm

Hi,
thank you, exactly what I'm looking for!