Multiple json data to jmeter request - jmeter

I have around 6 json request data, How can i send to jmeter to use all 6 request data for different threads.
In Body data I can put only only one json data.
Whats the best way to do this?

Put your 6 JSON values into separate files like:
d:\1.json
d:\2.json
etc.
Use combination of
__eval()
__threadNum()
__FileToString()
functions in order to get data loaded like
${__FileToString(${__eval(d:\\${__threadNum}.json)},,)}
See How to Use JMeter Functions posts series to learn more about different JMeter functions and what can be done with their help.

Related

Correlation in JMeter

If we have dynamic values in JMeter, in Response Body, Response Headers, and Request Headers, then we can correlate using Post Processors. But If we have dynamic values in the Request Body, then how can we correlate.
Could anybody please help me.
Where do these "dynamic values" come from?
If you need to populate them with the data from the response - correlation approach applies
If you need to populate them from external sources - it's called parameterization, the most commonly used approach is CSV Data Set Config
If you need to provide random/unique values - look at JMeter Functions

How can i generate a coulmn value as a random value in a csv file while doing load test with Jmeter

I am using Jmeter for load testing. I am passing parameters of the body from a csv file for an api. But our application will not receive the duplicate value. So when i load test by multiple users, the request get failed.because i am passing same parameter value for all users.So i need to make some of the columns with an instant value(random). so that different users will get different values.
{
"clinic_name":"clicnic",
"first_name":"provider1",
"initial":"v",
"last_name":"doc",
"salutation":"salu",
"address_1":"testttadd1",
"address_2":"testtttadd2",
"city":"ckdy",
"state":"Arizona",
"zip":"12365",
"fax":"",
"email":[{"email_id":"dfdf#dzcz.in","type":"Work","note":null}],
"phone":[{"number":"1235974444","note":"","type":"Mobile","extension":""}]
}
here i have given the request body and i need different email for different users. How can i do this?Can anyone help me..Thanks in advance.
you can use __RandomString function for the value of email_id:
"${__RandomString(15, abcdefghijklmnopqrstuvwxyz)}#${__RandomString(10, abcdefghijklmnopqrstuvwxyz)}.in"
The easiest is using Faker library like:
Download Java Faker jar and drop it to JMeter Classpath
Restart JMeter to pick the .jar up
You can use the following __groovy() function directly in the HTTP Request sampler body:
${__groovy(new com.github.javafaker.Faker().internet().emailAddress())}
Alternatively you can put the above expression into your CSV file, however make sure to wrap the variable reference into __eval() function, for example if you had ${email} you will need to change it to ${__eval(${email})}

Jmeter can get parameters?

My question is - if I run a test via Jmeter, for example , if it's a site which enables you to book a flight, and you choose your source and destination when you record it.
Is it possible to pass different values to the destination field? I mean, maybe a txt file with some destinations and pass it to the Jmeter test and then, you will have some tests which each of them is running with a different destination?
If yes, how can I do it?
It's not necessary that it will be a txt file. Just a way to pass different values to one parameter.
Important: I'm using blazemeter plugin for chrome.
Thanks a lot,
appreciated.
You can use CSV Data Set Config. It is very easy to use for parameterizing variables in the test plan.
Check this article on blazemeter to understand the CSV Data Set Config quickly.
Depending on what you're trying to achieve you can go for:
HTML Link Parser. See Poll Example which shows how you can use it for selecting random values from inputs
You can extract all the possible values from the previous response using a Post-Processor, most probably CSS Selector Extractor and configure each thread to use its own (or random) value from the input
And last, but not the least, you can use an external data source like .txt or .csv file and utilize __StringFromFile() function or CSV Data Set Config so each thread (virtual user) would read the next value from file instead of using recorded hard-coded values.

How to read excel file and use it as a variable for different body in jmeter

I have a url. I have created 50 threads in jmeter. I want to post 50 different bodies to 50 different threads. The parameter that should be unique in each body is stored in an excel file, in 50 rows. For each body i want to use these 50 variables in excel sheet , one by one row wise. How can this be done?
If your file is realy excel (i.e. xls or xlsx) you can read them using i.e. JSR223 Sampler and Apache POI library like described in the How to Implement Data Driven Testing in your JMeter Test guide.
You should get variables like:
var_1=foo
var_2=bar
var_3=baz
There are 2 ways of iterating the variables:
Using ForEach Controller
Using __V() and __threadNum() functions combination like ${__V(var_${__threadNum})}
However if you can control the Excel file it will be much easier to save it as .csv and use CSV Data Set Config

How can I dynamically post Request body (xml) and validate the response (xml)?

Is there a way to send the XML request dynamically and validate the XML response?
My scenario is:
I will have a CSV dataset config and inside the csv file I will have two column, the first one is for the inputXMLFilePath and the second column is the expectedXMLResposneFilePath.
So I need to have a JSR233 PreProcessor under HTTP request sampler, read the input file path convert it to the post body, and also has another JSR233 sampler for load the expected response from the expectedXMLResponseFilePath and compare it with the previous XML response. I have a snippet for JSON which is working fine. but for XML how can I do it?
You can use __FileToString() function for both use cases:
To send the XML request body, like ${__FileToString(${inputXMLFilePath},,)} (where ${inputXMLFilePath} is the variable from the CSV Data Set Config)
To validate the response using Response Assertion configured like:
Field to Test: Text Response
Pattern Matching Rules: Equals
Patterns to test: ${__FileToString(${expectedXMLResponseFilePath},,)}
You can use JMeter Functions literally at the any place of your Test Plan so their flexibility is higher than for other test elements. Also JMeter Functions are being compiled into native Java code therefore their execution speed will be higher and footprint will be less comparing to Groovy scripting.
Check out Apache JMeter Functions - An Introduction article to learn more about JMeter Functions concept.

Resources