Page 1 of 1

Global parameters - recordings' variables binding

Posted: Tue Sep 13, 2011 4:23 pm
by dman
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.

Re: Global parameters - recordings' variables binding

Posted: Wed Sep 14, 2011 11:49 am
by Support Team
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

Re: Global parameters - recordings' variables binding

Posted: Wed Sep 14, 2011 12:31 pm
by dman
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.

Re: Global parameters - recordings' variables binding

Posted: Wed Sep 14, 2011 3:21 pm
by Support Team
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

Re: Global parameters - recordings' variables binding

Posted: Wed Sep 14, 2011 3:44 pm
by dman
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.

Re: Global parameters - recordings' variables binding

Posted: Thu Sep 15, 2011 9:20 am
by Support Team
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

Re: Global parameters - recordings' variables binding

Posted: Thu Sep 15, 2011 9:52 am
by dman
Brilliant! Exactly what I needed :D

Thank you!
D.

Re: Global parameters - recordings' variables binding

Posted: Thu Sep 15, 2011 4:26 pm
by slavikf
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?

Re: Global parameters - recordings' variables binding

Posted: Fri Sep 16, 2011 8:12 am
by dman
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

Re: Global parameters - recordings' variables binding

Posted: Fri Nov 04, 2011 12:53 pm
by kathleen71
Hi,
thank you, exactly what I'm looking for!