Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Handling Variable Number of Request Parameters in Neoload

DZone's Guide to

Handling Variable Number of Request Parameters in Neoload

This brief tutorial will show you how to handle multiple request parameters using Neoload and JavaScript for efficiency.

· Performance Zone ·
Free Resource

Learn how error monitoring with Sentry closes the gap between the product team and your customers. With Sentry, you can focus on what you do best: building and scaling software that makes your users’ lives better.

If your request has a lot of parameters which are being passed to HTTP Request, creating a request to manually correlate the data will be a cumbersome process when instead, we can use scripting capabilities using JavaScript in Neoload to make a much easier and effective way of handling them.

Image title

Steps to Handle "Too Many Request Parameters" With Dynamic Values

  1. Correlate the request parameters using variable extractors.
  2. Using Javascript, construct the string with all the request parameters and store that in a variable.
  3. Change the Post Content Type to Text in HTTP Request.
  4. Pass the variable into the request.

Here is a practical explanation.

Capture the variables using variable extractors from the preceding request as below.

Image title

Click on edit and create the Regular expression as below and select Extract All Occurrences.

Image title

You would be able to see the extracted value under the test header as above.

Now drag and drop Javascript action on to the userpath as below and enter the following JavaScript Code:

Image title


var countinstring = context.variableManager.getValue("KeyString_matchNr"); // getting count of captured values and storing into the string
var countinint = parseInt(countinstring); // converting count to integer value

var string = "";

for (var i = 1; i <= countinint; i++) {
    var key = context.variableManager.getValue("KeyString_" + i); // getting each key variables
    var value = context.variableManager.getValue("ValueString_" + i); // getting each value variables

    string = string + key + "=" + value + "&"; // concatenating each key and value pairs

}
logger.debug("concatenated string=" + string);
string = string.substring(0, string.length - 1); //remove extra & 

// Inject the computed value in a runtime variable
context.variableManager.setValue("variableString", string); // storing the constructed concatenated string to a variable


Please refer to JavaScript API of Neoload community.

The final step is to change the Post Content type to Text as below and pass the captured value as a parameter.

POST requests with a text/... -type content. The contents of these requests may contain NeoLoad variables for generating dynamic content.

Image title

Now click on check user path and click on start checking to validate the scripts to check the variables being captured currently or not as below

Image title

Source.

This way we can handle any number of dynamic parameters.

What’s the best way to boost the efficiency of your product team and ship with confidence? Check out this ebook to learn how Sentry's real-time error monitoring helps developers stay in their workflow to fix bugs before the user even knows there’s a problem.

Topics:
neoload ,scripting ,performance ,java-to-javascript ,organization ,request parameters

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}