Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

So we have the following type of a URL:

http://www.myurl.com/mypage.aspx?suid=145db467-907e-4e3d-b944-c1666f9d08d6

This suid query string is generated dynamically and is unique to the specific process the user is going through at that point.

How can I get my web performance test in Visual Studio 2010 to pick up on the first instance of it and pass it through to future URL's in the current test's context?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

There's a couple of ways that you could do this. The easiest would be to create a variable that the value goes into when you first get it.

Because there's bound to be (and have been) cases where they need to be separated out a bit more, I typically write the value into an xml file that is used as a data source in the tests that will use this value.

There's the possibility of taking a little bit of a hit on the performance of your tests, but, from my experience, it's ended up being negligible.


Resolution ##

edited by @anicho

1) Create a querystring parameter under the request for the relevant querystring, in our case its "suid". Give it a context parameter value ours would be {{suid}}.

2) Next you need to create a custom extraction class, you can follow enter link description here to create an extraction class.

3) To caputre the query string use the code I have written below.

using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.WebTesting;
using System.Globalization;

namespace CustomExtractionRule
{
    //-------------------------------------------------------------------------
    // This class creates a custom extraction rule named "Custom Extract Input"
    // The user of the rule specifies the name of an input field, and the
    // rule attempts to extract the value of that input field.
    //-------------------------------------------------------------------------
    public class SuidExtraction : ExtractionRule
    {
        /// Specify a name for use in the user interface.
        /// The user sees this name in the Add Extraction dialog box.
        //---------------------------------------------------------------------
        public string DisplayNameAttribute
        {
            get { return "SuidExtraction"; }
        }

        /// Specify a description for use in the user interface.
        /// The user sees this description in the Add Extraction dialog box.
        //---------------------------------------------------------------------
        public string DescriptionAttribute
        {
            get { return "Extracts the suid from query strings"; }
        }

        // The queryname of the desired query string you wish to capture, when you add the custom extraction to a request you can set the following value to be what ever you like, it's like this so it can be reused over and over again.
        private string _queryNameValue;
        public string QueryName
        {
            get { return _queryNameValue; }
            set { _queryNameValue = value; }
        }

        // The Extract method.  The parameter e contains the web performance test context.
        //---------------------------------------------------------------------
        public override void Extract(object sender, ExtractionEventArgs e)
        {
                if (e.Response.HtmlDocument != null)
                {

                    foreach (QueryStringParameter item in e.Request.QueryStringParameters)
                    {
                        if (item.Name.Equals("suid"))
                        {
                            // add the extracted value to the web performance test context
                            e.WebTest.Context.Add(this.ContextParameterName, item.Value);
                            e.Success = true;
                            return;
                        }
                    }

                }


            // If the extraction fails, set the error text that the user sees
            e.Success = false;
            e.Message = String.Format(CultureInfo.CurrentCulture, "Not Found: {0}", QueryName);
        }
    }
} 

4) Once the code executes it picks up the query strings value and assigns it to a context parameter. The context parameter we ask our query string value to grab should be the same. As soon as the code sets it our query string picks it up and hey presto it should all be gravy.

Extra hint I need to use the same query string value in future requests within the same test so I set up a permenant context parameter so it can get picked up out side the one request.

share|improve this answer
    
I am trying to see if writing a custom extraction to extract the query string from the url, and then setting the value of a context parameter to it will work. –  Anicho Nov 2 '12 at 13:43
    
You will want to do an extraction rule or custom extraction rule on the response of the request prior to the one with the query string. Something in that response is being used for the query string parameter in the subsequent request. You probably will not need to use a custom extraction, it's most likely a value in the header or body of the previous response. –  Sam Woods Nov 2 '12 at 16:44
    
custom extraction rule on where the suid appears, setting it to a context parameter that can be used on all future instances where suid parameter is used. Will test tomorrow, and edit your answer with my code. –  Anicho Nov 2 '12 at 17:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.