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.
Join the DZone community and get the full member experience.
Join For FreeIf 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.
Steps to Handle "Too Many Request Parameters" With Dynamic Values
- Correlate the request parameters using variable extractors.
- Using Javascript, construct the string with all the request parameters and store that in a variable.
- Change the Post Content Type to Text in HTTP Request.
- Pass the variable into the request.
Here is a practical explanation.
Capture the variables using variable extractors from the preceding request as below.
Click on edit and create the Regular expression as below and select Extract All Occurrences.
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:
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.
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
This way we can handle any number of dynamic parameters.
Opinions expressed by DZone contributors are their own.
Comments