The web test uses the values ​​in the response as parameters for the next request

How to pass a field / value that will be part of the response received from the current request as a parameter for the next request ?

I can only set the static parameters of the POST form. Is there a way to do this in an accessible user interface for setting up a web test?

enter image description here

I searched, but this seems possible with jMeter and other web tests. And seeing that these people make me give up (for now) and start exploring the Coded Web Test approach in the meantime.

Any suggestions / pointers appreciated.

+6
source share
2 answers

I was able to do this after quite a bit of digging. It turns out to be quite simple (i.e. with a code 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 anyone knows a better approach, post a response.

+4
source

I know this is an old question about Visual Studio 2012, but maybe this can help someone who is trying to achieve this for Visual Studio 2015. There are probably many ways to do this; this is how i dealt with this:

  • To enter Request configure the extraction rule: right-click on Request and select Add Extraction Rule... This will allow you to store data from the response for use in subsequent requests. There are several ways to extract data, for example, from the POST field. Data is stored in a named variable, Context Parameter Name . Suppose you set this to sessionid .
  • I have added all additional URLs to the original request using Add Dependent Request . You can add a context variable anywhere by surrounding it with double curly braces: {{sessionid}} .
+2
source

Source: https://habr.com/ru/post/923843/


All Articles