Page 1 of 1

using command line variable to create URL at runtime?

Posted: Mon Feb 04, 2013 8:09 pm
by hporter
Hi, the app I am automating involves SharePoint, and is browser-based. The URL defines which farm is loaded (e.g. http://MyFarm1/product.aspx vs. http://MyFarm2/product.aspx). I've defined a variable called 'farm', and it has a default value of 'MyFarm1'.

The first step in my test case is an Open Browser action, and is currently set to 'http://MyFarm1/product.aspx'. Is there a way I can incorporate the 'farm' variable in the URL globally? Ultimately, I'd like to be able to use a command line like this to run my test:

test.exe /param:name="MyFarm1"

This way, I could switch the farm URL that loads by just changing the command line switch. Any help would be appreciated!

Re: using command line variable to create URL at runtime?

Posted: Mon Feb 04, 2013 9:57 pm
by Ciege

Re: using command line variable to create URL at runtime?

Posted: Wed Feb 06, 2013 5:03 pm
by hporter
Thanks again for your reply. The second blog post seems to cover what I need to do, but I'm missing something somewhere. I've added the code snippet to my Program.cs as it says to, but when I try to use the /url param in my command-line, it still loads the default that was part of the Open Browser action when I recorded it initially.

Again, I want to have this command-line switch added to the existing URL, not necessarily defining the entire URL as a parameter. I might imagine the URL would look like "http://<FarmURL>/product.html", or something like that in the code, so that my command-line would be MyTest.exe /farmURL MyFarm1. My skills as a developer are somewhat meager, so a step-by-step would be extremely helpful.

Re: using command line variable to create URL at runtime?

Posted: Wed Feb 06, 2013 5:11 pm
by Ciege
Since you say that you recorded your tests you will need to read the User Guide about using variables in recordings. You will need to get the URL passed in on the command line as and ARG and set your variable to the value of that ARG. Then in your recording you will have to manipulate the URL parameter you are using to use the portion of the URL you passed in with the portion on the URL that remains static.

Re: using command line variable to create URL at runtime?

Posted: Wed Feb 06, 2013 5:28 pm
by hporter
I'm already using several variables in my test, via an Excel spreadsheet that contains the values. Those values are used in different ways (primarily to pass key sequences to a dialog). So I'm familiar with how to use variables in Ranorex, but in this case I don't want the variables to be populated via Excel (or other file) - I want them defined at runtime.

Re: using command line variable to create URL at runtime?

Posted: Thu Feb 07, 2013 3:33 pm
by hporter
I've finally got this working (though the code involved could stand a polish or two). I basically did away with the existing recording module that opened the browser, and created my own code module that calls OpenBrowser and passes in the global variable for the farm name as part of its URL.