Page 1 of 1

Passing arguments

Posted: Thu Jul 28, 2016 5:48 am
by sujan.gurung
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 :)

Re: Passing arguments

Posted: Thu Jul 28, 2016 8:53 am
by odklizec
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.

Re: Passing arguments

Posted: Thu Jul 28, 2016 3:38 pm
by krstcs
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

Re: Passing arguments

Posted: Fri Jul 29, 2016 3:09 am
by sujan.gurung
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.

Re: Passing arguments

Posted: Fri Jul 29, 2016 4:00 am
by ngaruko
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!

Re: Passing arguments

Posted: Fri Jul 29, 2016 2:51 pm
by krstcs
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.