Search code examples
visual-studio-2015web-testing

Web and Load testing VS 2015 - getting query string from last redirection of a request


I am new to web and load testing in VS. I am not using the recorder since there is too much garbage traffic to weed out. Recorders tend to confuse and obfuscate to me rather than illuminate. I am simulating the login process of our application in order to retrieve an authentication token to pass to services I want to test. I am walking step-by-step while watching the traffic in Fiddler.

So step 1, navigate to the URL of the AUT. When I do this, I see a series of redirects whose outcome is a new URL with a cookie and a query string in the request, and the login form in the response.

In my next request, I would like to include that cookie and query string of the former redirect into the request I am now issuing. I am not writing code yet at this point but am using the test designer. How do I retrieve the values to include in the next request?

Thanks


Solution

  • Possible ways include:

    (1) Set the Follow redirects property on the request to False and then create requests for each URL in the chain of redirects. Add extraction rules at relevant places and use the extracted values in the subsequent requests. This is the normal approach when there is just one redirect, or perhaps a very small number of them.

    (2) Similar to the above, but write a plugin that does the redirect handling and adds the next request in the chain to the test.


    Generally cookies and query string parameters are extracted from responses and written into requests, they are not normally extracted from requests. Visual Studio web tests normally handle cookies without needing help.

    Values of query string parameters can come from many places in a response. If special cookie handling is needed then they can be extracted from responses the ExtractHttpHeader extraction rule for the header field Set-Cookie.

    If you really need to extract values from a request then the PreRequest plugins can access the pieces of the request just before it is sent.

    For the request you are trying to handle I would envisage using three requests, each with Follow redirects set to False. They are:

    (1)

    Request: http://localhost:12345
    Response: extract port number and other url fragments to context parameters `PortNumber1` and `UrlFragment1`, etc.
    

    (2)

    Request: http://localhost:{{PortNumber1}}/{{UrlFragment1}}
    Response: extract redirected url to `Url2` and cookie(s) to `Cookies2`
    

    (3)

    Request: http://{{Url2}}/
        Query string parameters written to header fields,
            either by fields in the web test
            or by plugin creating the values            
    Response: ...
    

    You might reconsider using the web test recorder. I find it does a good job in creating a web test. Additional work is needed to handle dynamic parameters but that kind of work would be needed with or without the recorder. You say "there is too much garbage traffic to weed out" but that should only take a few moments if it really is garbage. However it is part of the system being tested and if it is deleted then will the web test correctly simulate the real activity on the website being tested?