using command line variable to create URL at runtime?

Ranorex Spy, Recorder, and Studio.
hporter
Posts: 35
Joined: Wed Jan 23, 2013 4:49 pm

using command line variable to create URL at runtime?

Post by hporter » Mon Feb 04, 2013 8:09 pm

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!

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

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

Post by Ciege » Mon Feb 04, 2013 9:57 pm

If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

hporter
Posts: 35
Joined: Wed Jan 23, 2013 4:49 pm

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

Post by hporter » Wed Feb 06, 2013 5:03 pm

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.

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

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

Post by Ciege » Wed Feb 06, 2013 5:11 pm

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.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

hporter
Posts: 35
Joined: Wed Jan 23, 2013 4:49 pm

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

Post by hporter » Wed Feb 06, 2013 5:28 pm

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.

hporter
Posts: 35
Joined: Wed Jan 23, 2013 4:49 pm

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

Post by hporter » Thu Feb 07, 2013 3:33 pm

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.