Ask a questionAsk a question
 

AnswerWeb Test - Extracting data from QueryString?

  • Wednesday, August 01, 2007 4:54 PMRobertV Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    I have a page in my application that I'm testing where it redirects to a 2nd page which takes a querystring parameter to indicate the ID of the record that was just entered.

     

    I need to extract that id# from the querystring so I can use it to test several more pages where i must pass that id number.

     

    Here's the basic simplified flow.

     

    add.aspx - Page 1 - Add a record, redirects to page 2.

    page2.aspx?id=1 - Page 2 - Page 1 redirects here and places an id number in the querystring.  Page2 needs this value.

    page3.aspx?id=1 - Page 3 - I need to be able to pass the id # to this page and several more.

     

    Looking at the options for Extraction Rules there seems to be none that will allow me to get this querystring value.  I can get a value from a hidden form field or the text on page2.  But this id# is not output to page 2 except in the querystring.

     

    Seems like a common pattern so what am i missing here?

     

    Thanks in advance.

     

    R-

Answers

  • Thursday, August 02, 2007 1:44 AMDennis StoneMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    It seems like you would want to get the querystring value from Page 1, rather than Page 2, as you need it to get to the valid Page 2 in the first place.  How does Page 1 get the value that it uses when it adds the querystring?  Does it come back embedded in the initial response, or is it gotten by some javascript, or some other means? 

     

    The key is to figure out where Page 1 gets the value and then add the appropriate rule to your webtest to duplicate that funcitonality.  The Playback engine is only sending the http requests to the web server as you recorded them , it's not running any of the script on your page so if the value used is gotten via some ajax or other scripting method your next step would be to figure out what http requests are made by the script and get those added into the web test, as they are not recorded by the Web test recorder in VS 2005 (2008 does record them though.).  Here's a link that should help with that:

     

    http://blogs.msdn.com/slumley/pages/enhanced-web-test-support-in-fiddler.aspx

     

    If the value used in the querystring is embedded in the initial response from the Page 1 request then you need to extract it from there.  For example, maybe in the html that is returned you have something like:

    <a href="mysite.aspx?Id=1231">Click here to add new record!</a>

     

    If that's the case then you could use FindText if it's something simple, or you might find this blog post helpful:

     

    http://blogs.msdn.com/densto/pages/dynamic-querystring-correlation-custom-extraction-rules-and-webtest-plug-in.aspx

     

    And, lastly I would recommend the following article by Sean Lumley for a nice overview of figuring out some of the more common problems you may have in setting up a web test:

     

    http://blogs.msdn.com/slumley/pages/how-to-debug-a-web-test.aspx

  • Thursday, August 02, 2007 2:06 AMRobertV Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Thanks for the suggestions.  I'll take a look at some of those links which look like they have some helpful information.

     

    Prior to your response i found a sample of code for creating your own extraction rule.  This was succesful in allowing me to find the solution i needed.

     

    If anyone else needs the code, feel free to send me a message.

     

    To answer your questions, the first page inserts data into a database and during that obtains the primary key of the inserted value.

     

    It then does Response.Redirect("page2.aspx?id=1")   where 1 is the value of the record it just inserted.

     

    Therefore my need was to get that id value from the URL from the redirect.  The id was not embedded in page 1 or 2 in any place nor did i want to add it just to do a webtest.

     

    This seems like a pattern common to many web applications.

     

    I thing a general querystring extraction rule such as what i found and adapted should be included in VS.  It was simple enough to create however but just my 2 cents that it should be in the release.

     

     

All Replies

  • Thursday, August 02, 2007 1:44 AMDennis StoneMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    It seems like you would want to get the querystring value from Page 1, rather than Page 2, as you need it to get to the valid Page 2 in the first place.  How does Page 1 get the value that it uses when it adds the querystring?  Does it come back embedded in the initial response, or is it gotten by some javascript, or some other means? 

     

    The key is to figure out where Page 1 gets the value and then add the appropriate rule to your webtest to duplicate that funcitonality.  The Playback engine is only sending the http requests to the web server as you recorded them , it's not running any of the script on your page so if the value used is gotten via some ajax or other scripting method your next step would be to figure out what http requests are made by the script and get those added into the web test, as they are not recorded by the Web test recorder in VS 2005 (2008 does record them though.).  Here's a link that should help with that:

     

    http://blogs.msdn.com/slumley/pages/enhanced-web-test-support-in-fiddler.aspx

     

    If the value used in the querystring is embedded in the initial response from the Page 1 request then you need to extract it from there.  For example, maybe in the html that is returned you have something like:

    <a href="mysite.aspx?Id=1231">Click here to add new record!</a>

     

    If that's the case then you could use FindText if it's something simple, or you might find this blog post helpful:

     

    http://blogs.msdn.com/densto/pages/dynamic-querystring-correlation-custom-extraction-rules-and-webtest-plug-in.aspx

     

    And, lastly I would recommend the following article by Sean Lumley for a nice overview of figuring out some of the more common problems you may have in setting up a web test:

     

    http://blogs.msdn.com/slumley/pages/how-to-debug-a-web-test.aspx

  • Thursday, August 02, 2007 2:06 AMRobertV Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Thanks for the suggestions.  I'll take a look at some of those links which look like they have some helpful information.

     

    Prior to your response i found a sample of code for creating your own extraction rule.  This was succesful in allowing me to find the solution i needed.

     

    If anyone else needs the code, feel free to send me a message.

     

    To answer your questions, the first page inserts data into a database and during that obtains the primary key of the inserted value.

     

    It then does Response.Redirect("page2.aspx?id=1")   where 1 is the value of the record it just inserted.

     

    Therefore my need was to get that id value from the URL from the redirect.  The id was not embedded in page 1 or 2 in any place nor did i want to add it just to do a webtest.

     

    This seems like a pattern common to many web applications.

     

    I thing a general querystring extraction rule such as what i found and adapted should be included in VS.  It was simple enough to create however but just my 2 cents that it should be in the release.

     

     

  • Tuesday, August 14, 2007 10:55 PMdans0042 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    Hi Robert - would you mind sharing that code.  This sounds like the exact scenario that I am running into trying to test a web app. 

     

    Thanks,

    Dan

  • Wednesday, October 24, 2007 2:39 PMAlex Oliver Campbell Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Robert,

    I am interested in getting ahold of that sample code.

    Alex.
  • Thursday, December 06, 2007 2:58 PMTaavi KoosaarMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    Has anyone gotten this code? I am looking at the same issue.

     

    Any hints/links?

     

    Taavi

  • Wednesday, June 10, 2009 12:08 PMTaavi KoosaarMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Just as an information - the "Web and Load Test Plugins for Visual Studio Team Test" at codeplex contains the extraction from querystring plugin. There's other neat plugins for web and load tests there as well. http://teamtestplugins.codeplex.com/

    Thanks,
    Taavi
    Taavik