Passing Multiple JSON parameters in JMeter - jmeter

My registration form is accepting body in JSON format, and I need to run the test with 5 different user names.
How do I pass JSON as request body? Also I was unable to pass parameter from CSV file. How can I solve this issue?

Add CSV Data Set Config to your Test Plan
Configure it like:
Filename: full path to the file with your emails
Variable Names: anything meaningful, i.e. EmailId
In your HTTP Request sampler copy the recorded value to Body Data" tab and replace hard-coded email with JMeter Variable like:
{"EmailId" : "${EmailId}"}
In Thread Group set "Number of Threads" to 5
Next time you run your test JMeter will read next line from the file.csv and substitute the ${EmailId} variable with the value from the CSV file.
See Using CSV DATA SET CONFIG article for more information on parameterising your JMeter tests via CSV files.

Related

How to save value from multiple requests to one file in Jmeter

I have one GET request which returns a token. I need to run this request 50 times and each returned token is appended to a single file or array which I can randomly choose and use tokens for other requests. Is it possible in Jmeter
Add a Post-Processor to extract the token and save it into a JMeter Variable
Declare the variable as a Sample Variable
Save the extracted value into a CSV file using Flexible File Writer
Use Random CSV Data Set Config to read the random token from the CSV file created in the previous step

Graphql in jmeter

I am using graphql in jmeter for API testing. Where in graphal we have the query and variable section.
My query would require a client ID which is int. Where as in Variable if I try to pass "{clientid : ${clientid}}"(here I am passing the CSV config variable, for testing the app for multiple users). But it is throwing an error like $ is unauthorised and expecting a (json,null,true or false).
Please help me out how I can pass the clientid which is a csv config variable.
Thanks in advance.
It looks like your CSV Data Set Config setup is not very correct so the JMeter Variable placeholder isn't getting substituted with its respective value from the CSV file.
We cannot help without seeing first couple of lines of the CSV file and your CSV Data Set Config setup so far I can only suggest re-visit the configuration and cross-check it with JMeter Documentation
You can observe JMeter Properties and Variables with their values using Debug Sampler and View Results Tree listener combination, if you don't see clientid line there - the variable is not set and JMeter sends it as it is, to wit "{clientid : ${clientid}}" and doesn't substitute ${clientid} with the value from CSV

How to hit parameterized url in Apache Jmeter?

This is my test URL " http://appr.seconddemo.org/hitssurveys/survey?uid=113&offerid=311&subid=subvalues&offr_id={Email} "
I want to hit the url 1500 times per second , and want to change the "{Email}" with real value in each iteration.
How it's possible please give me a step by step guide.
Considering that you need to pass the emails from the external file, the most efficient way that we are using in software testing companies is to pass the variable from .csv or .txt files using 'CSV Data Set Config' element of the JMeter.
Please find the steps that you need to follow:
Add a 'CSV Data Set Config' element from 'Config Element' by right-clicking the thread group
Set Filename field with complete path to your .csv or .txt file that contains your emails
Set Variable field as 'Email' [This variable name should be same as you set in your url request]
Ignore first line to False
Set other fields as per your requirement
Now add HTTP Sampler in your Thread Group and set the Protocol, Server Name, Method & Path as instructed in the screenshot:
Create .csv or .txt file and add all emails separated by new line:
Hope this answer is useful.
You can use the CSV Data Set Config. Put all your email credentials in the CSV file and make sure you have put this CSV file in your JMeter /bin directory.
Add a CSV dataset config in your test plan. Your CSV dataset config should be like:
Now in your thread group, define the number of threads you want to execute and then in your sampler put the path as follows:
http://appr.seconddemo.org/hitssurveys/survey?uid=113&offerid=311&subid=subvalues&offr_id=${Email}
Depending on where do your emails live there are following options:
If they are in a text file, each email on a new line you can use __StringFromFile() function like:
If they are in a database you can use JDBC PreProcessor to fetch the data from the database table column and put your request under ForEach Controller
If you need to provide just some random characters you can use __RandomString() function.
More information: JMeter Parameterization - The Complete Guide

How to do parameterization for file name text of csv data set config in jmeter

I am passing the value for file name text filed in csv data set config as ${filename}, this variable contains entire path and fetching it form one more csv data set config which is present immediate to the thread group and the variable which I am passing to csv data set config that is inside the if controller here I couldn't able to pass that value to file name text filed, getting problem.
CSV Data Set Config cannot use JMeter Variable as the "Filename". However it is possible to use __property function there.
So your test plan should look as follows:
Read some value into a JMeter Variable i.e. foo via 1st CSV Data Set Config
Convert foo variable into foo property via __setProperty function
Use ${__property(foo,,)} as a "Filename" in 2nd CSV Data Set Config.
For more information on different JMeter's functions see How to Use JMeter Functions post series

JMeter using a variable as input for a response assertion pattern

I have a test plan in JMeter that has a Response Assertion where I'd like to use a variable that comes from a CSV Data Set Config. So my Pattern looks like:
${assert1}
Which corresponds (at least in my thoughts) to what comes from the file used in CSV Data Set Config, but it doesn't work. I have seen multiple suggestions to use a Regular Expression Extractor, but the examples I saw refer to something they're trying to capture from a page. In my case I am using an external csv file.
My question: how can I use a variable as input for a Response Assertion pattern ?
I have successfully used a CSV Data Set Config as a source of string that I use in a url parameter, and then use a Response Assertion to seek out that parameter in the response.
Variable name: P.
URL: /product/${P}.
The response assertion Parterns to Test: ${P}.
I wonder if it is not necessary to use the CSV data variable in the request in order for it to be available in the response assertion?
If my understanding is right,
here your problem:
You want to use the value from your CSV as part of URL and that too via variable.
Solution:
Configure your CSV Data Set Config like this:
Filename: url csv path
variable name : assert1
Delimiter : , (if your CSV comma separated)
leave remaining unchanged
That's it you can use the variable assert1 anywhere: ${assert1}.

Resources