Extracting Cookies from header

Hi,

I would like to know how to extract the cookies in from One WebRequest and pass it to the same webRequest if this.context.IsUserNew is false for another run of the same webTest during load run.

Thanks.
Prash




Answer this question

Extracting Cookies from header

  • vijay_kbp

    An extraction rule is used to scrape information from the response of one request and pass the value to another request. The extracted value is placed into the "Test context". Any value in the test context can be bound to a property of a subsequent request.

    The built-in extraction rule "Extract HTTP Header" may be able to handle your case. If there is not a built in extraction rule, you can write a custom extraction rule. Here are some links to help you with extraction rules.

    http://msdn2.microsoft.com/en-us/library/ms243190.aspx

    Adding an extraction rule to a web test:

    http://msdn2.microsoft.com/en-us/library/ms182545.aspx

    Creating a custom extraction rule:

    http://msdn2.microsoft.com/en-us/library/ms243179.aspx

    Thanks,

    Rick


  • AndyHammer

    I don't see anything obviously wrong, but what's special about this cookie Session cookies should be automatically carried over between requests within a web test.

    Josh



  • thehomerj

    Rick,

    Thanks for the reply. Basically, I am using Coded Test and I extract the values using extraction handler. It is something like this:

    void request1_ExtractValues(object sender, ExtractionEventArgs e)

    {

    if (e.Response.ResponseUri.ToString() != null)

    {

    cpcsCookie = e.Response.Cookies["ML_SAML_ASSERTION"];

    e.WebTest.Context.CookieContainer.Add(new Uri(WSURL), cpcsCookie);

    //this.Context["cookie"] = e.Response.Cookies["ML_SAML_ASSERTION"];

    e.Success = true;

    return;

    }

    else

    {

    e.Success = false;

    e.Message = String.Format("No response URI found");

    }

    }

    when for second request i go to the grab the cookie using following code:

    System.Net.CookieCollection coll = this.Context.CookieContainer.GetCookies(new Uri(WSURL));

    I don't get the my cookie in the collection.

    Am i using "Test Context" correctly If not, please let me know the right approach.

    Thanks a lot.

    Prash



  • Paul_siq

    Have you looked into using the % new users setting It can be set on your load test scenario. New users start with no cookies and no file cache, but existing users will automatically carry over cookies and cached files.

    Josh



  • Extracting Cookies from header