Page 1 of 1

How to copy the value of Global Variable to a code variable?

Posted: Thu Nov 10, 2016 9:01 pm
by Poblarp
Hi,

I defined a global variable say: InputFilePath.

I don't have any recording module in my test suite. All of my modules are code modules in C#. The management specifies that we don't use the recording module and can only use the code module in C#.

How do I copy the value from my global variable, InputFilePath, to a local variable in one of my code modules in C#?

Thanks,

Poblarp

Re: How to copy the value of Global Variable to a code variable?

Posted: Fri Nov 11, 2016 12:53 pm
by odklizec
Hi,

What exactly do you mean by a "Global Variable"? Where exactly did you define such a variable? Do you mean Global Parameter defined at Test Suite level? I believe there is nothing like a global variable in C#?

PS: please tell your managers they are "a......s" ;) Forcing people not to use "recording modules", just to look "cool" or "more professional", is a very silly thing! Recording modules make things easier and significantly speed the development, not to mention they reduce the number of human errors caused by typos or limited knowledge of C#. Every recorded (or manually added) action in Recording module has a proper C# code generated (and validated) by Ranorex Studio. So by using recording modules, you can be sure the code behind the action is correct. Of course, there are cases, when it's better to use code modules. But doing everything in code modules is a complete waste of time, energy and money. Just my humble opinion ;)

Re: How to copy the value of Global Variable to a code variable?

Posted: Fri Nov 11, 2016 2:30 pm
by krstcs
I would agree with Pavel. Using the tools that are already available not only makes it easier, but it takes less time, which means it cost the company less money to finish the same amount of 'work'. Mandating the use of only code modules and doing everything manually is actually costing your company more money in the long run because of the greater demands of maintenance and new creation of modules.

Re: How to copy the value of Global Parameter to local variable?

Posted: Fri Nov 11, 2016 4:01 pm
by Poblarp
Thank you for your replies and input.

I actually mean "global parameter" of Ranorex and not the "global variable".

I would like to use a global parameter to pass in the file location to a library module in my test automation.

So in the command line, it will be like:

C:\Users\my user\testsuite.exe /pa:InputFileLocation=C:\myInputFileLocation

So how do I create a module variable in my C# library ?

My C# library was created by the following ?

New File -> Templates = An empty class declaration

Then I can bind the global parameter to the module variable in my C# library.

Re: How to copy the value of Global Variable to a code variable?

Posted: Fri Nov 11, 2016 4:27 pm
by odklizec
Hi,

Instead of creating empty C# class, create a new Ranorex Code module. Then simply right-click inside this newly created module and in the appeared context menu select "Insert New Module Variable". Then simply connect this new variable with Global Parameter of your choice. Hope this helps?