Azure DevOps, Scrum, & .NET Software Leadership and Consulting Services

Introducing Slide Speaker: Videos with Voice-over from your PowerPoint and Google Slides Presentations

Validation & Extraction Rules for Visual Studio 2012 Web Performance Tests


(Update August 5, 2014: The latest version now has the ability to do math as part of your web performance and load tests.)

I’ve been doing a lot of work with Visual Studio 2012 Web Performance Tests and as part of that, I’ve written a handful of custom Validation Rules and Extraction Rules.  I think they’re pretty useful so I figured I’d share them out.

In the zip file for this blog post, you’ll find a very simple sample application and a Web & Load Test project that contains a web test that uses all of these rules.  The sample web test is called SampleWebTest.webtest.  The screenshot below shows you the validation rules and extraction rules in this web test.

SNAGHTML93b77e

Validation Rule: SleepValidationRule

This rule doesn’t actually do any validation but it hooks into the WPT execution and causes the WPT to wait for a given number of milliseconds.  Under the surface, it’s executing a C# Thread.Sleep() call.  This is helpful for slowing down your test a little (or a lot) for when you’re trying to test asynchronous logic.  In the Properties dialog below, the validation rule will sleep for ‘1000’ milliseconds.

image

Validation Rule: TableColumnValueValidator

Looks at a <table> and verifies that a value exists in a table in a given column.  The Properties dialog below will look for a table with an id of ‘m_grid’ and check to see if the ‘Artist’ column contains the value ‘Branford Marsalis’ in one of the rows.

image

Extraction Rule: ExtractRandomValueFromTable

This extraction rule looks the columns in an html <table> and extracts a column value from a random row.  This is helpful for Load Tests where you want to simulate multiple users clicking through your application and viewing different data.  This helps you to avoid hardcoding the same records over and over again and gives some variety to which records are being worked with by your Load Test’s virtual users.  In the Properties dialog below, the rule will look for a table with an id of ‘m_grid’ and randomly pull a value from the ‘Id’ column and put it into the ‘RandomIdValue’ context parameter.

image

Extraction Rule: ExtractResponseContainsString

This extraction rule looks at the text of the HTTP Response for the Web Test and looks to see if a particular value exists.  If the value exists, it will set the context parameter to be ‘true’.  If it doesn’t exist, it will set the context parameter to ‘false’.  In the Properties dialog below, this will look in the response for the string ‘Crazy’ and set true or false into the ‘DoesCrazyExistInTheResponse’ context parameter variable.

image

Extraction Rule: ExtractResponseUrlFilename

This rule looks at the URL for the web test request and extracts the filename portion of the URL.  This is helpful for verifying the name of the file where the web performance test ends up after following a number of HTTP redirects.  In the Properties dialog below, this request will extract the filename from the URL to a context parameter named ResponseFilename.

image

Extraction Rule: LabelValueExtractor

This extraction rule will extract the value of an ASP.NET Web Forms Label control and put the value into a context parameter.  In the Properties dialog below, the rule will look for a Label control named ‘m_labelRowCount’ and store the value in a context parameter named ‘RecordCount’.

image

 

Click here to download the code.

 

I hope you find this useful.

-Ben

 

— Got performance problems in your application?  Need some help creating load tests with Visual Studio 2012?  Want some training on how to create Web Performance Tests and Load Tests with Visual Studio 2012 or Visual Studio 2013?  Drop us a line at info@benday.com.

SUBSCRIBE TO THE BLOG


15 responses to “Validation & Extraction Rules for Visual Studio 2012 Web Performance Tests”

  1. bob Avatar

    Hi Ben , I am just learning the VS ultimate performance/load test and I cannot find any useful training material. would you by any chance able to suggest something ?
    My specific issue is here now and if you can help me with that you have made a good soul very happy!
    so I am trying to create a load test of a service that we have here.
    steps are:
    1- I send the request to the service
    a- this I can do via the VS tool
    b- I can also run the load test against it ,no problem.
    2- But that request in step1 returns a response like below
    where I need to read the URI from the response and submit
    to the same service again.
    3- Pretty straight forward but being new to this I do not
    know how to do it 🙁

    the following is the result of the first request in step 1 and the URL in the LOACTION: section is what I want to extract and resubmit

    HTTP/1.1 202 Accepted
    Cache-Control: no-cache
    Pragma: no-cache
    Expires: -1
    Location:
    http://Svername/xxxExchange/xxx/nextjobresponse/dcdaeb76-ation: 02dc-45b8-83f6-6524f6a07c36
    Server: Microsoft-IIS/7.5
    xxx-response-code: complete
    xxx-response-status: RequestAccepted
    X-AspNet-Version: 4.0.30319
    X-Powered-By: ASP.NET
    Date: Sat, 19 Apr 2014 22:18:38 GMT
    Content-Length: 0

    1. Ben Day Avatar

      Hi Bob —

      As far as training goes, I’m partial to this course that I published on Pluralsight:
      http://pluralsight.com/courses/load-testing-visual-studio-2012

      I think that what you want to do is use an Extraction Rule to grab that URL. The extraction rule will let you save that extracted url value to a Context Parameter (aka. a variable) and then you can plug that value in to other requests. If you check out that video course above, I cover all that stuff.

      Thanks,
      -Ben

  2. Pooja Avatar
    Pooja

    Hi

    I ‘ve extracted the value but need to pass the incremented value in form post parameters. How to perform arithmetic function in context variables??

  3. […] been writing and maintaining a library of useful utilities for Visual Studio Web Performance Tests and Load Tests for a while and I got an email from a reader today asking for a new one.  She asked if there […]

  4. Ben Day Avatar

    Hi Pooja —

    That’s not possible out of the box but that’s a FANTASTIC idea and I just implemented it. Here’s a link: http://www.benday.com/2014/08/05/adding-simple-arithmetic-to-web-performance-test-load-tests/

    -Ben

  5. HP Avatar
    HP

    Hey Ben! I am running a web performance test on a Salesforce site and the request before the request that displays the query string parameters has no reference to the query string. Is there an extraction method where I can make a call to the DB and get the values before the request that has the query string parameters?

    Thanks!
    Hanna

  6. Bindu Avatar
    Bindu

    Hi Ben,

    I am new to VSTS 2013Ultimate. I was using HP loadrunner for past 10 years. Now our company want us to move to VSTS2013 utilimate. I am doing some evaluation of VSTS Tool on how is best fits our needs…

    I have a question on how to validate the transaction names using the validation rule “Find Text”.

    For example:
    Added the transaction name “LaunchGoogle”
    launch google app “Http://google.com/
    Add Validation rule to capture the text “Google” displayed on the web page.
    Using the above validation rule ” If the text shows correctly, then i would like to pass the transaction”LaunchGoogle”, Other wise Fail the transaction “LaunchGoogle” and Throw an exception, and exit the iteration.

    My question is, how can i implement the above in WebTest in visual studio ultimate 2013.

    I started taking “Visual Studio Utilimate 2013 Web Performance Testing” Couse from Plural site.

    Your help is much appreciated!

    Thansk,
    Bindu.

    1. Ben Day Avatar

      Hi Bindu —

      Transactions don’t have the concept of success/failure. They’re basically just there for reporting and analytics. So if that “Find Text” rule fails, it’s better to think of it as failing the web test rather than any particular transaction.

      Make sense?

      -Ben

  7. Amin Avatar
    Amin

    Hi Ben,
    I need little help with my web performance test script. I am creating a UI script where the response URL is multiple dynamic values, also I found all values as a query string parameters, so my question is how do I know which extract rules I need to use . I have tried all but not working, please help me figure that out .

    I have also sent a Email to you with that Webtest .

    Thanks
    Amin

  8. Madhuri Avatar
    Madhuri

    Hi Ben,

    Currently I have a webtest in which a request pulls the details of all the users in a json format. I have added an extraction rule to pick one user and then perform other actions on that user. Am using extract text and setting the index to 0 or 1. The problem here is, the same user is being extracted every time because the json returns the data in the same order. All actions are performed on the same user in the load tests and I don’t want that. Is there any way a random user can be extracted in an extraction rule. I mean without the index value.

    Sample json:
    {
    “results”: {
    “Users”: [
    {
    “Id”: 54965,
    “Name”: “Roxann Parker, Carol”,
    “Age”: “98”,
    “Gender”: “F”
    },
    {
    “Id”: 45698,
    “Name”: “Aron, James”,
    “Age”: “33”,
    “Gender”: “M”
    },
    {
    “Id”: 78962,
    “Name”: “Kingston, Cathy”,
    “Age”: “59”,
    “Gender”: “F”
    },
    {
    “Id”: 95368,
    “Name”: “Willams, Jack”,
    “Age”: “43”,
    “Gender”: “M”
    }
    ]
    }
    }

    My extraction rule always picks the first value and its always the same.

    Appreciate your help
    Madhuri.

    1. Ben Day Avatar

      Hi Madhuri —

      You should adjust your rule so that it looks at specific “index” values for that result.

      -Ben

  9. Chandan Avatar
    Chandan

    Hi Ben,
    Thanks a lot for sharing knowledge on how to leverage VS Studio for Web Performance and Load Test. I have a small blocker. I have a Rest API which i set up in Web Performance Test Project. I want to capture the response of the same and write them in a csv or excel file. The reason is I want to compare the run time value of the responses with that of expected values in excel(or csv). If the above cannot be achieved, please let me know a workaround. Thanks

  10. Amin Avatar
    Amin

    Hi Ben,

    I have two Webtest and Webtest2 will use some data which is generated by Webtest1. So when I will run the Webtest1 , it will create new transaction ID. And in webtest2 I have to search that current transaction ID and use it for rest of the scenario. So please can you help me to figure out how can I save the ID in agile from webteat1 and use the same ID in webtest2. If you can provide me any code that will be great. Thanks in advance.
    Thanks
    Amin

  11. munther Avatar
    munther

    this info, and the pluralsight course were very helpful. thank you.
    but, is there any other way for waiting/sleeping?
    the thread.sleep function you use seems to put the counters to sleep too. and my times come out off by however much time was spent sleeping

    if not, is there a way of adding values to the timers during execution?

  12. Ravitej Aluru Avatar
    Ravitej Aluru

    Hi Ben,

    I recently started off exploring VS 2015 performance and load testing. Your course on Pluralsight is a good starter. Thanks for that.

    I’ve now come to a point where I need a custom validator and/or extractor which can verify/get an attribute value or inner text of an HTML element identified by a CSS selector rather than by tag, matching attribute and index. In other words, I would like to get the value of href attribute of 4th anchor under the div with id ‘commonspanel’. CSS Selector = “div#commonspanel a:nth-of-type(4)”. As far as I know there is no way of doing this with out-of-the-box tools. Have you ever had such a requirement? If yes, how did you resolve it?

    As a side note, I think it would be great if you can package your code as a NuGet package and publish it.

    Thanks,
    Ravitej

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.