Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

web test use values in response as parameters for next request

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?

enter image description here

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.

like image 602
Robin Maben Avatar asked Aug 27 '12 09:08

Robin Maben


2 Answers

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:

  1. For the login 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.
  2. I've added all additional URLs to the original request using Add Dependent Request. You can add access the context variable anywhere by surrounding it with double curly brackets: {{sessionid}}.
like image 56
Pooven Avatar answered Nov 15 '22 17:11

Pooven


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.

like image 30
Robin Maben Avatar answered Nov 15 '22 17:11

Robin Maben