Get global parameter value in code (alternative way)

Ranorex Spy, Recorder, and Studio.
gridle
Posts: 11
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: 272
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: 11
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: 11996
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

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
(12.38 KiB) Downloaded 1 time
Regards,
Bernhard
.
Image

gridle
Posts: 11
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...