locked
Custom extraction rule for redirecting URLs RRS feed

  • Question

  • HI

    Im Facing an issue with my webtest. for a single request, it actually gets redirected to 3 URLs. from one of the redirecting URL I have to capture a header respose value. for the same I had writer a custom extraction rule. But what happens is while executing the webtest the extraction rule gets excuttted with the parent request. How can we make the extraction rule to get excutted with redirecting URLs. below given is the extraction rule I had tried. Please share your valuable comments.

    public string header

            {

                get; set;

            }

            public string header_name

            { get; set; }

            public override void Extract(object sender, ExtractionEventArgs e)

            {

                if (e != null && e.Response != null && e.Response.Cookies != null)

                {

                    string headertext = e.Response.Headers[header].ToString();

                    foreach (string nameValuePair in headertext.Split('&'))

                    {

                        string[] nameAndValue = nameValuePair.Split(new char[] { '=' }, 2);

                        if (nameAndValue[0].Trim() == "access_token")

                        {

                            var fieldsValue = nameAndValue[1].Trim();

                            e.WebTest.Context[header_name] = fieldsValue;

                            e.WebTest.Context.Add(this.ContextParameterName, fieldsValue);

                        }

                    }

                    e.Success = true;

                    return;

                }

    Wednesday, August 17, 2016 10:56 AM

Answers

  • I see two ways you might handle this.

    (1) Rewrite the extraction rule as a PostRequest method of a WebTestRequest plugin. It should then be called on the parent and on each redirection.

    (2) Change the parent request in the webtest to have its "Follow redirects" property set to false and add the redirected URL manually as a new request to the test. Then put the extraction rule on this new request. This is more complex than the first suggestion.

    Some additional thoughts:

    When plugins and custom extraction rules do not do what I expect I link to add calls of e.WebTest.AddCommentToResult("..."); with suitable messages. One as the very first statement in the method, others to show context values written or values extracted. These calls appear in the run log and let me know when the method is (or is not) being called as expected.

    Page 12 of VSPTQRG (see http://vsptqrg.codeplex.com/) says an extraction rule is attached to a specific request whereas WebTestRequest plugins apply to the request plus all redirects. Page 36 shows this in the handling of the "ParamPage4.aspx" example.

    Regards
    Adrian

    Wednesday, August 17, 2016 12:07 PM

All replies

  • I see two ways you might handle this.

    (1) Rewrite the extraction rule as a PostRequest method of a WebTestRequest plugin. It should then be called on the parent and on each redirection.

    (2) Change the parent request in the webtest to have its "Follow redirects" property set to false and add the redirected URL manually as a new request to the test. Then put the extraction rule on this new request. This is more complex than the first suggestion.

    Some additional thoughts:

    When plugins and custom extraction rules do not do what I expect I link to add calls of e.WebTest.AddCommentToResult("..."); with suitable messages. One as the very first statement in the method, others to show context values written or values extracted. These calls appear in the run log and let me know when the method is (or is not) being called as expected.

    Page 12 of VSPTQRG (see http://vsptqrg.codeplex.com/) says an extraction rule is attached to a specific request whereas WebTestRequest plugins apply to the request plus all redirects. Page 36 shows this in the handling of the "ParamPage4.aspx" example.

    Regards
    Adrian

    Wednesday, August 17, 2016 12:07 PM
  • Thanks Adrian for response. I had tried the first way WebRequest plugin. That worked :)

    Wednesday, August 17, 2016 1:41 PM
  • Hi Karthik MA,

    Glad to know that you have resolved this issue, and thanks for Adrian’s reply. Would you please mark it as answer, which could help others who have the same issue as you.

    Sincerely,

    Oscar



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.


    • Edited by Oscar_Wu Thursday, August 18, 2016 5:08 AM
    Thursday, August 18, 2016 5:06 AM