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

Class library usage, coding and language questions.
Poblarp
Posts: 7
Joined: Thu Oct 20, 2016 3:23 pm

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

Post by Poblarp » Thu Nov 10, 2016 9:01 pm

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

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

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

Post by odklizec » Fri Nov 11, 2016 12:53 pm

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 ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

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

Post by krstcs » Fri Nov 11, 2016 2:30 pm

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.
Shortcuts usually aren't...

Poblarp
Posts: 7
Joined: Thu Oct 20, 2016 3:23 pm

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

Post by Poblarp » Fri Nov 11, 2016 4:01 pm

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.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

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

Post by odklizec » Fri Nov 11, 2016 4:27 pm

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?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration