Passing arguments

Ask general questions here.
sujan.gurung
Posts: 4
Joined: Thu Jul 28, 2016 5:43 am

Passing arguments

Post by sujan.gurung » Thu Jul 28, 2016 5:48 am

Hi,

I have a bunch of moduble variables that I want to pass to a powershell script. I am using a ranorex rec module to trigger powershell script:

My arguments look like this: "-File script.ps1 $var1 $var2"

Problem is $var1 and $var2 variables are not parsed though I have initialised them in module.

Thanks in advance for you help :)

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

Re: Passing arguments

Post by odklizec » Thu Jul 28, 2016 8:53 am

Hi,

I'm afraid, there is not enough information in your post to provide a reasonable answer.

If I understand you right, you want to pass some arguments to PS via Ranorex recording/code?
How exactly do you pass the arguments to PS?
Are you doing it via recording action (please post a screenshot of recording table) or via code (please post exact code you are using)?
Also, always post a Ranorex version you are using.
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: Passing arguments

Post by krstcs » Thu Jul 28, 2016 3:38 pm

Try doing this:

Code: Select all

"-File script.ps1 " + var1 + " " + var2
The $var1 notation ('$' + variable name) is only used by Ranorex in the Repository as RanoreXPath replacement notation.

In code, you have to use just the variable name ("var1" without quotes).

Also, you are concatenating a string, so you have to tell the code exactly how you want the string to look after it evaluates the values of the variables, so you use the '+' sign.

I would highly recommend doing some reading on .NET basics if you are going to be working with user code in Ranorex.

In addition, I would recommend completely reading the user guide: http://www.ranorex.com/support/user-guide-20.html
Shortcuts usually aren't...

sujan.gurung
Posts: 4
Joined: Thu Jul 28, 2016 5:43 am

Re: Passing arguments

Post by sujan.gurung » Fri Jul 29, 2016 3:09 am

Hi,

Thank you for your response.

Just to clarify it further, we are using Ranorex 6.0 . We are using recording module (not code module) to trigger a powershell script. I am trying to pass a module declared variable as an argument.

Please see an attached screenshot. As you can see on the "Arguments" column, I am trying to send the value of the module variable $varDbName to powershell.. but it's value is not being passed, instead the string $varDbName gets sent.

btw we are trying to avoid using code module as much as possible at this point. Thanks.
Attachments
ranorex.PNG
ranorex.PNG (18.6 KiB) Viewed 1024 times

ngaruko
Certified Professional
Certified Professional
Posts: 4
Joined: Thu Apr 21, 2016 1:03 am

Re: Passing arguments

Post by ngaruko » Fri Jul 29, 2016 4:00 am

I understand that sometimes it makes sense to avoid writing code. But unfortunately, as it stands, there are a number of things we cannot do with Ranorex (like most recorders). These may include passing parameters and receiving feedback from other tools (Powershell in your case, others like SQL command, visual studio etc), doing some logic (looping, iteration, if statements etc). In these cases, I guess it makes sense to use some code to get the most our of your investment. After all, Ranorex has invested in this feature (user code) and other Apis because they know that there is so much one can do with the recorder. And the price we pay for their license include these features! Also consider using other tools for non-UI related tests. Let me paraphrase from Wikipedia: "Ranorex is a GUI test automation framework for testing of desktop, web-based and mobile applications". The accent here is on GUI. For other tests, maybe consider better suited tools and IDEs. Another paraphrase, this time from Abraham Maslow : "I suppose it is tempting, if the only tool you have is a hammer, to treat everything as if it were a nail".
Meantime, if you find ways around these issues and are able to implement them using exclusively the recorder, please share with the community on this forum.

Best of luck!
Last edited by ngaruko on Mon Aug 22, 2016 4:18 am, edited 1 time in total.

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

Re: Passing arguments

Post by krstcs » Fri Jul 29, 2016 2:51 pm

Yeah, you are going to have to use user code to do what you want. There's no way around it given what you have stated so far.
Shortcuts usually aren't...