Reputation: 39
I have recorded and replayed my sharepoint webtest successfully but after a week or two, I get '403 FORBIDDEN' error when I replay it in Visual Studio.
I understand that X-RequestDigest has expired certificate/token details and needs to be updated for every run in my request. However, I'm unable to find preceding X-RequestDigest header value in my recorded web test.
I'm able to extract from response header but I need to bind the value to request prior to response? Can someone give me a code/method to extract X-RequestDigest header value from Sharepoint page and use it in my Visual Studio Webtest?
Upvotes: 0
Views: 1509
Reputation: 812
Answer to your question may vary depends on the version of SharePoint you use. Typically the x-requestdigest value can be extracted from _api/contextinfo that appears just before the request that you need to parameterize. This is a json response body that looks as follows:
{"d":{"GetContextWebInformation":{"__metadata":{"type":"SP.ContextWebInformation"},"FormDigestTimeoutSeconds":1800,"FormDigestValue":"0x258D3700E8E516F8E320BAF6FEFDDC271C54C8C44A1E5DBE8B9CBE6ED2A77EDCCF88CAA901790245D3E9B518FB31AA9B345B0E232C93CD39D4E12999499B7414,6 Jun 2017 10:26:21 -0000","LibraryVersion":"16.0.5521.1202","SiteFullUrl":"https://xxx.sharepoint.com","SupportedSchemaVersions":{"__metadata":{"type":"Collection(Edm.String)"},"results":["14.0.0.0","15.0.0.0"]},"WebFullUrl":"https://xxx.sharepoint.com/Sample_Site"}}}
From here you need to extract the “FormDigestValue” value with an Extract Text extractor. Set the Starts With: "FormDigestValue":" Ends With: “
If you wish to use Fiddler as AdrianHHH suggested, you may also want to use our free StresStimulus add-on that will create all extractors and parameter automatically as described here http://www.stresstimulus.com/blog/post/visual-studio-load-testing-fixing-playback-errors-in-web-tests. You just need to record the test scenario, save it as a webtest and open in Visual Studio. That way, you don’t have to create any extractors and parameters manually.
Upvotes: 1