How do I invoke multiple http requests dynamically in jmeter - json

I have fetched multiple paths of multiple urls from the JSON response using JSON Path extractor in jmeter. The paths are stored in the jmeter variables like url_0,url_1, url_2 and so on. The server IP address is constant.
These urls fetched from the JSON response have to be invoked after parsing the JSON response as stated earlier. How do I achieve this particular behaviour in jmeter?

Use ForEach Controller as it described in Using Regular Expressions in JMeter
If you have variables like:
url_0=/some/path
url_1=/some/other/path
url_2=/some/another/path
etc.
Configure ForEach Controller as follows:
Input Variable Prefix: url
Start index for loop: -1
Output variable name: path
Add "_" before number: check
And use ${path} variable in underlying HTTP Request sampler

Related

I have been trying to add a dynamic value in the url path of an api in Jmeter script from response code of other api. Help me out

I have an api which has many folder to it and each folder have more than two contents and I want to compare each contentid in folder from response code with other duplicate api response code which has same contents as this api in Jmeter
For eg. The folders are in a path something like https://apple.test.com/user/folder(just an example url)
To extract each folder I have used json extractor for above url in http request and extracted the folder id (with json path as $..folderid...if I select ALL in the extractor and try to use ${folderid_ALL} in url path I am getting an error), then created another http request and passed this variable in the url something like
https://apple.test.com/user/folder/${folderid}
And used beanshell assertion to compare their contentid
When I execute this only the first folder is picking up and it's contents are compared and rest of the folders are not shown
Can you help me out on how to extract all the files and compare their contents!!
If you have multiple folder IDs extracted into JMeter Variables using JSON Extractor you can use ForEach Controller to iterate all the IDs.
Also since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting so consider migrating to the JSR223 Assertion
In order to get the comprehensive answer you should include:
The JMeter Variables generated by the JSON Extractor
The format of the "next" request for the "folder"
The response you're getting
What do you want to compare with what

JMeter Json Extractor for Multiple Http Requests

I have setup a ForEach Controller to execute multiple HTTP requests but I would like to then extract JSON values from the response bodies from each of the HTTP requests.
When I try to add a JSON Extractor PostProcessor to the HTTP Request, I am only able to get a json value from the last HTTP Request. Is it possible to get values from all of the HTTP requests?
You're getting the values from each HTTP Request, you just overwrite the previous value when the next iteration of the ForEach Controller starts, you can double check yourself by adding Debug Sampler after the HTTP Request sampler under the ForEach Controller
Just add ${__jm__ForEach Controller__idx} pre-defined variable as a prefix or postfix for the name of the created variable in JSON Extractor so on each iteration it will create a separate JMeter Variable holding the current value extracted from the response.
Example configuration:
Demo:
JSON extractor is ok but something that you can try and is more flexible i add beanshell post processor and choose your language, then you can extract the JSON from HTTP requests.
You can choose java as language and use following code to extract the JSON as string
String jsonString = prev.getResponseDataAsString();

JMETER store request JSON Element as variable

Trying to figure out how I can access elements of a post request body (JSON) and store it as a variable. One of my tests creates a user using ${__UUID}#gmail.com - and I'd like to then check that my response includes this same information.
I'm guessing I could probably create the UUID before the request and store it as a variable, and then check against that, but wondering if there is anything similar to JSON Path Extractor for request elements.
There is a JSR223 PreProcessor you can use to fulfil your requirement.
Assuming you have JSON Payload like:
{
"user": "${__UUID}#gmail.com"
}
Add JSR223 PostProcessor and put the following code into "Script" area:
def user = com.jayway.jsonpath.JsonPath.read(sampler.getArguments().getArgument(0).getValue(), '$..user').get(0).toString()
log.info('Random user email:' + user)
vars.put('user', user)
The above code will:
Extract from the request everything which matches $..user JSON Path expression
Print it to jmeter.log file
Store the value into a JMeter Variable so you will be able to refer it as ${user} where required.
More information:
Apache Groovy - Why and How You Should Use It
Groovy - Parsing and Producing JSON

How to create multi-request based on last json response in JMeter?

I will get json response from last request, then I will parse the response and get a variable array, then create new request base on each element in that array one by one. I don't know how to implement it.
Use JSON Extractor and ForEach Controller combination. The idea is to have variables like:
var_1=foo
var_2=bar
var_3=baz
So you would be able to iterate them using foreach loop. See Using Regular Expressions in JMeter article to get the overall idea.
Steps to follow:
Add JSON Extractor (>= 3.0 version) Or JSON Path Extractor (< 3.0 version) plugin, to the HTTP Request sampler, as a child, in which JSON response is received.
Add the JSON Path Expressions to capture the specific values and store it in variable names, say capturedArray. refer JSON Path Syntax.
In later requests, i.e., HTTP Request Samplers, you can retrieve the array value by using the syntax ${capturedArray}

jmeter load testing , Parameterization

I am running a HTTP request test in jmeter where I send a json input. For example:
{ "id":"0", "fieldvalue":"sanket","Source":"todays date" }
I need to parametrize this so that for each thread iteration a different value for id, fieldvalue, source is chosen, possibly from a json file only (not CSV file). Is this possible?
Everything is possible. Here are the options
JMeter can read almost any files. Check out the following functions:
__FileToString()
_StringFromFile()
You can also use HTTP Request sampler to read the file, just use file as protocol and UNC path.
Values for parametrization can be obtained using JSON Path PostProcessor. See:
JSONPath - XPath for JSON - for JSON Path language overview and syntax
Advanced Usage of the JSON Path Extractor in JMeter - for some not obvious scenarios covered