Ask a questionAsk a question
 

AnswerHow to use same jsessionid value throughout the webtest

  • Friday, November 06, 2009 7:55 PMKuldeep Mathur Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    I am using VSTT 2008. I need to use the same jsession id value through out the test. Here is what my test does
    When it opens the main page, a cookie is set in the request header as Cookie=JSESSIONID=<value>. Now i need to carry over this value to all the subsequent requests. I cannot hardcode that since the ID is valid for some time and it expired soon.

    What my test is doing is that it created a new session id for each step, hence the test fails after 3 steps. I need to carry the Session id generated in the first requests to all the subsequent requests. 

    Thanks in advance for help. 

Answers

  • Tuesday, November 10, 2009 6:22 AMEdwer FangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hello Kuldeep,

    As I do not know how your web site works, if you want to extract value from request, you may utilize web test request plug in to extract this value and have it binded to context parameter which you could use in the whole web test.

    The below codes work fine on my machine and you may refer to:

    public class Class1:WebTestRequestPlugin
        {
            public override void PostRequest(object sender, PostRequestEventArgs e)
            {
                string extractValue = "";
                foreach(WebTestRequestHeader t in e.Request.Headers)
                {
                    if (t.Name == "Host")    //find the specific header value and bind it to context parameter
                        e.WebTest.Context["Jsession"] = t.Value;
                }
            }
        }

    More detailed information about request plug in, you can refer to the following article:
    http://msdn.microsoft.com/en-us/library/bb514192.aspx
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Send us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.

All Replies

  • Sunday, November 08, 2009 10:17 AMMiro1977 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    you just need to add Extraction rule -"Extract Text" and extract the value that you need and set Content Parameter Name = J_id (or any other name ).
    In the other request attach the Context Parameter (J_id) to somewhere you need it.
    MIRO77
  • Monday, November 09, 2009 3:28 AMEdwer FangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello,

    Based on your description, you want to carry the Session id generated in the first requests to all the subsequent requests. You may follow Miro1977's suggestion to do it. As extraction rule could extract specific value from the response and bind it to a context parameter which could be used in all test. You just need to verify the response of the first request and create proper extraction rule.

    More detailed information about Extraction Rule, you may follow the following article:
    http://msdn.microsoft.com/en-us/library/ms404703.aspx
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Send us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.
  • Monday, November 09, 2009 1:49 PMslumley Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    The cookie value from the first request should be carried forward to following requests.  Does each of the following responses also get a SET-Cookie header for jsessionid?
  • Tuesday, November 10, 2009 12:58 AMKuldeep Mathur Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    Thanks for the reply. I don't have the Session id value in my response. Its only in the request. So i cant play with response too. One more thing i wanted to know is that can we set the asynchronous property  of cookies in the test or is it read only.
  • Tuesday, November 10, 2009 6:22 AMEdwer FangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hello Kuldeep,

    As I do not know how your web site works, if you want to extract value from request, you may utilize web test request plug in to extract this value and have it binded to context parameter which you could use in the whole web test.

    The below codes work fine on my machine and you may refer to:

    public class Class1:WebTestRequestPlugin
        {
            public override void PostRequest(object sender, PostRequestEventArgs e)
            {
                string extractValue = "";
                foreach(WebTestRequestHeader t in e.Request.Headers)
                {
                    if (t.Name == "Host")    //find the specific header value and bind it to context parameter
                        e.WebTest.Context["Jsession"] = t.Value;
                }
            }
        }

    More detailed information about request plug in, you can refer to the following article:
    http://msdn.microsoft.com/en-us/library/bb514192.aspx
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Send us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.