How can I pass a field/value that will be part of the response received from the current request as a parameter for next request?
I am able to set only static Form POST parameters. Is there a way to do this in the available UI for configuring the web test?
I have searched around but these seem possible with jMeter and other web test frameworks. And seeing those lead me to giving up (for now) and start exploring the Coded Web Test approach in the meantime.
Any suggestions/pointers appreciated.
I know that this is an old question about Visual Studio 2012, however perhaps this might help someone trying to achieve this for Visual Studio 2015. There are probably many ways to get this done; here's how I've handled it:
Request
, setup an extraction rule: right click on the Request
and select Add Extraction Rule...
. This will allow you to store data from the response to use in later requests. There are several ways to extract the data, such as from a POST field. The data is stored in a named variable, the Context Parameter Name
. Let's suppose you've set this to sessionid
.Add Dependent Request
. You can add access the context variable anywhere by surrounding it with double curly brackets: {{sessionid}}
.I was able to do this after quite some digging around. Turns out its pretty simple (i.e. with Coded Test).
.
.
.
var request1 = new WebTestRequest("http://localhost/Home/Index");
var sessionId = "";
request1.ExtractValues += (s, e) => {
sessionId =
e.Response.HtmlDocument.HtmlTags.SingleOrDefault(tag =>
tag.Name == "somename"
&& tag.Attributes.Any(a => a.Name == "attrName"
&& a.Value == "attrValue"));
};
yield return request1;
Then,
var request2 = new WebTestRequest("http://localhost/SomeController/Index/");
var request2Body = new FormPostHttpBody();
request2Body.FormPostParameters.Add("sessionId", sessionId);
request2.Body = request2Body;
yield return request2;
If anybody knows of a better approach please post an answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With