Skip to main content

VSTS 2008 Data-Driven Web Test

During a client demo this afternoon, I mind-blanked on creating a data-driven web test. Sure enough, I stepped out of the client offices and figured it out. Super. But, I think it's counterintuitive enough to outline in a blog post (...trying to make myself feel better ;-). Somewhat in my defense, I was thinking about data-driven unit tests. These, IMO, are easy to implement. Data-driven web tests are a bit more effort and challenging.

Create a web test: Right-mouse on your test project selecting Add >> Web Test. Use the browser recorder to capture your web test scenario. Let's assume you're submitting an age and credit rating to an insurance rate calculator...similar to the screen capture below:

image

Create a table or CSV file (comma-delimited...just use Excel and save as CSV) with relevant headings for your inputs and expected values:

image

From Solution Explorer, double-click on your web test. In the main window, right-mouse on your web test selecting Add Data Source... :

image

Establish a connection to a relational database, CSV or XML file:

image

For each parameter posted, select Properties and then the drop-down next to the Value property:

image

For each of the post parameters, select the appropriate / associated data element:

image

Ok, so that covers our inputs. Now we need to verify the page produces the expected result. Right-mouse on the URL/page request including the form post selecting "Add A Validation Rule..."

image

Use the best option for your situation. Hopefully you can simply check a Form Field. In our circumstance, we're writing out an ASP.Net label to the form with the calculated results. So, we need to leverage the Find Text option (I tried Required Attribute Value but since labels output as <span id="lblSomething">Output Value</span> I wasn't able to grab the value...because it's an element vs. an attribute). Unfortunately, there's no nice drop-down for connecting to the data source's expected value. You'll need to enter it manually. The format looks like: {{DataSourceName.FileName#csv.FieldName}}. It's easiest just to copy from the input parameters and surround with the double curly brackets. Here's what the dialog looks like:

image

Finally, we need to instruct the test to execute once for every data record instead of the web test values captured in the recording. Within Visual Studio, select Test >> Edit Test Run Configuration >> Local Test Run:

image

Select Web Test from the left and select the "One run per data source row" option and click Close (save to the project if prompted):

image

Now we can execute our data-driven web test! (Make sure to check the Details tab confirming the Validation worked as expected and you're not experiencing a false positive):

image

Comments

Najam said…
Hi,

I want to thank you to post this article. its a very informative for me.

Thanks and Regards,
Najam
Anonymous said…
Hi

It's really very helpful for the beginners like me.

Thanks,
Nirmala
Anonymous said…
This Information is really very good to implement for my Project
Juan Trujillo said…
Hi Jeff,

Thanks for the post, very helpful. One question: I want to do the same thing for a coded UI test that I have previously recorded, how can I do this ?
Juan Trujillo said…
Hi Jeff,

Thanks for the post, very helpful. One question: I want to do the same thing for a coded UI test that I have previously recorded, how can I do this ?

Popular posts from this blog

Hero Write-up: Now this is Customer Service!

My best friend Scott is president/C-everything of a small northeastern Ohio manufacturing concern, KirkKey Interlock . I hadn't spoken with him for a while and wanted to see how Canton fared with the Blizzard of '08 (that's what they're calling it...not me). I say, "So what's new?" He replies that on Tuesday his primary server (which essentially runs the business) came up with lame with not one, but [a statistically improbable] *two* physical disk failures on a RAID5 hardware array. My friend attempts the fix but gives up pretty quickly after seeing some Linux nasty-grams on the boot screen. His service provider is an old college buddy who lives down in Raleigh, Cerient Technologies led by Jason Tower . Scott couldn't email out because Exchange was on the toasted server. Being creative, Scott started Treo-emailing photos of the screen. Unfortunately, Jason couldn't receive email because a storm had knocked out a lot of local hosting. [Sigh] After...

Certified or Certifiable?

As a senior technology professional, I interview a lot of candidates. I also maintain solid relationships with other folks in the community. Frequently, the topic of certifications arises: A good investment? Valuable? A clear measurement of skill? Consensus appears to draw the line related to one's seniority. If you're (for example) just out of school and looking for an instant creditability boost, by all means pursue a certification. Likely, this credential will assist you in overcoming the "junior" tag and likely land you more interviews and client roles. (Note: I'm going to use the terms senior and junior here...no offense to either. Can't think of a better one word description. I was a junior once too.) In stark contrast, the value of certifications drops off the table around the 2-3 year mark. Some in my circles even perceive certifications as a negative for the senior professional. They think, "If this guy is so solid, why is he wasting valuable...

Fast and Reliable Home Internet: Your Livelihood Depends on It

You're on yet another Zoom call and...wait what did she say? Dang it...Internet glitching again! You quickly mute your audio and video. "Kids! Get off YouTube...I'm on a call!" With everyone working and schooling from home, your Internet can't keep up. The cable company keeps claiming you're on their "super-fast Internet" but everything keeps lagging. It's all so frustrating and you just want to get your work done.  It may not be the cable company's fault. Use this approach to ensure your household enjoys a super-fast, reliable Internet! Start with the Source Run a speed test. Google "speed test" . Run that test a few times on a given day. If you're not getting at least 50Mbps download and 10Mbps upload speeds, keep reading.  Check with your Provider and do your Homework Reach out to your Internet provider. This may be your cable company or telephone provider. Understand your current plan: What package are you currently on? Wha...