Get global parameter value in code (alternative way)

Ranorex Studio, Spy, Recorder, and Driver.
gridle
Posts: 19
Joined: Mon Mar 10, 2014 5:13 pm

Get global parameter value in code (alternative way)

Post by gridle » Wed Oct 16, 2019 3:08 pm

Hi,

I created global parameter "VarName" for Test Suite.
There is a code module in the current Test Suite. I created local variable (right click in code file->insert new module variable) "LocalVarName" inside this code module. During the test (code module) execution I try to use this variable.
In *.rxtst file I binded local variable with global variable (right click on code module->data binding)
Global parameter <TestSuiteName>.VarName to local parameter <CodeModuleName>.LocalVarName

I try to execute test via command line:

Code: Select all

<projectName>.exe /pa:VarName="TestData"
And during the execution local parameter from code module returns empty string every time.

Is there any possibility to get global parameter value in code module instead of line below?

Code: Select all

TestSuite.Current.Parameters["VarName"]
Can anyone help me with it?
Thanks!

Code from code module:

Code: Select all

...
	string _LocalVarName = "";
        [TestVariable("ac442751-aeb7-4b10-b4af-66ac5fa0e8c9")]
        public string LocalVarName
        {
        	get { return _LocalVarName; }
        	set { _LocalVarName = value; }
        }
        
        /// <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()
        {
        	Install.InstallApp(LocalVarName); //LocalVarName is empty (always) 
        	//Install.InstallApp(TestSuite.Current.Parameters["VarName"]);
        }
  ...
 
Binding screenshot:

Image

User avatar
Stub
Posts: 515
Joined: Fri Jul 15, 2016 1:35 pm

Re: Get global parameter value in code (alternative way)

Post by Stub » Wed Oct 16, 2019 3:33 pm

I think I do that, using /pa:VarName="My Value". Works very well as far as I have seen.

Do you have multiple Test Suites? Do you specify the appropriate Test Suite on the command-line via /ts:"Path to .rxtst file"? I am wondering if the parameter is being applied to the wrong Test Suite, though you suggest that TestSuite.Current works for you, so it might not be that after all.

gridle
Posts: 19
Joined: Mon Mar 10, 2014 5:13 pm

Re: Get global parameter value in code (alternative way)

Post by gridle » Wed Oct 16, 2019 3:47 pm

Hi Stub,

thanks for answer.
Stub wrote:
Wed Oct 16, 2019 3:33 pm
Do you have multiple Test Suites?
Nope, i have one Test Suite only that is why I don't specify it in command line arguments.
I added /ts:Testsuite argument to command line arguments. And it didn't help (after some investigation)...

So it still doesn't work. Any suggestions?

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

Re: Get global parameter value in code (alternative way)

Post by Support Team » Fri Oct 18, 2019 12:50 pm

Hello gridle,

your description looks correct. I attached a Ranorex Soluiton (with Ranorex version 9.1.2 ) that worked for me. Please try if this also doesn't work.
GlobalParameterFromCommandLine.zip
Regards,
Bernhard
You do not have the required permissions to view the files attached to this post.

gridle
Posts: 19
Joined: Mon Mar 10, 2014 5:13 pm

Re: Get global parameter value in code (alternative way)

Post by gridle » Fri Oct 18, 2019 4:05 pm

Support Team wrote:
Fri Oct 18, 2019 12:50 pm
your description looks correct. I attached a Ranorex Soluiton (with Ranorex version 9.1.2 ) that worked for me. Please try if this also doesn't work.
GlobalParameterFromCommandLine.zip

Regards,
Bernhard
Hi, thanks for reply.

Your solution worked for me as well. I compared my solution to yours - and seems they are the same in Global/Local parameters.
I checked my solution several times already but it still doesn't work as expected...

AdamG
Posts: 9
Joined: Tue Sep 10, 2019 1:30 pm

Re: Get global parameter value in code (alternative way)

Post by AdamG » Tue May 11, 2021 4:04 pm

Not sure if something has changed in the last 1.5 years but this solution no longer works - returns empty string every time.

Commands attempted:

GlobalParameterFromCommandLine.exe /tc:TestCase /pa:MyVariableCreatedInCsFile="testy"
GlobalParameterFromCommandLine.exe /tcpa:TestCase:MyVariableCreatedInCsFile="testy"
GlobalParameterFromCommandLine.exe /pa:MyVariableCreatedInCsFile="testy"

Result:

Image

EDIT: Ranorex 9.3.3

EDIT 2:

Adding [your_variable] = TestSuite.Current.Parameters["GlobalParameter"] seems to solve this issue.
Last edited by AdamG on Thu May 13, 2021 10:29 am, edited 1 time in total.

User avatar
Stub
Posts: 515
Joined: Fri Jul 15, 2016 1:35 pm

Re: Get global parameter value in code (alternative way)

Post by Stub » Wed May 12, 2021 9:07 am

I use the first and third forms of your examples (the middle one is malformed) but we're still on Ranorex v9.3.2 here at the moment (it all works, haven't felt the need to upgrade everything yet, it's on the ToDo list).