This one took me a little longer then I figured. Maybe I’m just trying to do stuff the wrong way, but I don’t know, I feel like my use case is correct.
What am I talking about anyway? I am talking about creating a set of web tests in Visual Studio Test Edition (well Team Suite) that I can actually use in a real world situation (i.e. Have tests that work on a dev, staging and production server). The problem is/was, hard coded URLs for my dev server, which ultimately would have to be changed to point at staging and production.
Before proceeding, let me spell out what I’m trying to do (use case):
At first, I thought this was going to be a very easy change, as there is a “Parameterize Web Servers” option when you right click on the root node of your web test. This creates a context variable, which I thought was cool, until I realized it was on a test by test basis, not project. I guess I was looking for a project wide context parameters file, but couldn’t find one.
I did some searching and supposedly you can set an environmental (yes, from a command prompt) variable named Test.<ContextParameter>, however I was unable to get this to work. I think this might only work when invoking mstest from the command line which makes some sense, but kind of throws a wrench in the works. While this would be perfectly acceptable for a un-attended build server, what if I needed to point to a new dev server in the GUI?
I then moved to a XML data source with a single “line” of data":
1: <?xml version="1.0" encoding="utf-8" ?>
2: <Config>
3: <UrlRoot>http://dapltp101.dmz.pri</UrlRoot>
4: <LoginUserName>asalvo</LoginUserName>
5: <LoginPassword>123456</LoginPassword>
6: </Config>
This worked pretty good, except that when selecting UrlRoot from the drop down list of available options, it replaced the entire URL, and not just the URLRoot. I do like how they made the property grid “strong typed” in that it gives you the fields you defined for your data source, but I didn’t want to replace my whole URL. Also, I could not edit the value after selecting my XML data source value.
Looking at the format of ContextProperties in values, as well as how the data source was referenced, I decided to try typing what I wanted in myself. I went to the URL value and replaced the URL root with the name my XML data element, and this worked.
For example, given:
Type this in the value field for your URL in the Request object on the test: {{ConfigXml.Config.UrlRoot}}/Location1
Like I said, that took me a little while longer then I would have thought. I should have went with my gut and tried that format soon after getting the regular XML data source to work.
I do have one last issue (well the fist of many I am sure), and that is, I have two URL’s when I really should only have one. When I hit the root of my website, I am redirected to a https:// URL, and that is treated differently. I’d like to capture the redirected URL and use that so I don’t have to maintain two values in my configuration file, but I’m just gonna roll with it for now.
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.