Anti forgery token and web testing

后端 未结 3 762
渐次进展
渐次进展 2021-02-09 18:16

I am trying to do a web test in VS2012 for an MVC site. One of the scenarios is to login and go through a list of products, select the one you want and follow through to the pu

3条回答
  •  天命终不由人
    2021-02-09 18:50

    Once you run your script and it fails, go to the call proceeding the one that fails.

    • Go to the response tab

    • In the body, find the __RequestVerificationToken name which is in an input tag and extract everything in between the value attribute.

    • Select the value and right click > add extraction rule and press OK.

    • You will find an Extraction rules folder and underneath it, the Extraction rule we just created. Feel free to rename the Context Parameter Name.

    • Go to the next page , which should be the one that failed, and find the Form Post Parameter named "__RequestVerificationToken". View it's properties

    • Bind it to the Context Parameter Name created previously. To do so, view the properties of this post parameter and set the "Value" to be:

    {{Name Of Context Parameter}}

    (Include the 2x curly braces)

    • Press enter to confirm/save

    Next time you run the script - all works

    This is how it worked for me...

提交回复
热议问题