I need to pass the csv values to the http request for single user - csv

I have csv data set config of locations and i need to pass those to http request in single run for each user i.e if i have 4 locations then i need the http request to be called 4 times wherein those locations are passed one by one sequentially.
HTTP REQUEST:https://api.drivevegas.k8.devfactory.com/rest/acdr?latitude=${Latitude}&longitude=${Longitude}&heading=0&speed=0&course=90&sequence=1670427622&carCategories=REGULAR
The latitude and longitude are passed form csv file
Latitude,Longitude
36.10803655487475,-115.16748588704128
36.10805389068134,-115.16570490025539
36.106112256560955,-115.16570490025539
36.10547081331421,-115.16656320714016
36.10546214512636,-115.16748588704128
36.097084543359564,-115.17586335211487

You should use csv data set config, here is a link that may come handy
https://guide.blazemeter.com/hc/en-us/articles/206733689-Using-CSV-DATA-SET-CONFIG

Add CSV Data Set Config somewhere, i.e. as a child of the HTTP Request and provide full or relative path to your CSV file in the "Filename" field:
In the HTTP Request sampler refer the variables from CSV as ${Latitude} and ${Longitude} where required, i.e. in the Parameters tab:
That's it, with default Sharing Mode setting of the CSV Data Set Config JMeter will pick up the next line on each iteration of each thread (virtual user) and substitute JMeter Variables placeholders with the respective values from the CSV file

Related

How to pass different CSV value for every occurance in Jmeter

I am trying to pass different CSV Value in sequential manner for every occurrence in Jmeter.
I applied
Loop count
Counter
Beanshell Sampler
Value from CSV
JMS Point to Point Request
With this i am able to pass different value for every occurrence for multiple users.
But my script fails when i run for multi user multiple iterations.
It is not picking up sequential value.
My beanshell sampler code-
String variablename=vars.get("variable");
String csvvalue=vars.get("valuefromcsv");
vars.put(variablename,csvvalue);
It doesn't seem to me that you need to use scripting at all, it's quite sufficient to set up CSV Data Set Config and:
Point it to CSV file
Set up "Sharing Mode" to be All Threads
This way each thread (virtual user) will be picking up the next value from the CSV file on each iteration.
Also be aware that starting from JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting
You don't need to write the script for this. you can "Config Element-> CSV data set config" for the HTTP request. under CSV data set config page set the below values.
Variable names: give column names.
Delimiter : should be ,
Recycle of EOF: True
stop thread on EOF : false
Sharing mode : All threads.

How to use csv to provide different values for json assertion for different inputs in Jmeter?

I am relatively new to API Testing.
Currently I have a setup where I am having different request jsons and for each request json there is different repsonse json assertion configuration provided with the appropriate values in Jmeter.
Since my json structure will be same and only the input values will be different, I am thinking to generalize the input values using csv and keep only one request configuration.
But would I be able to provide different values(like jsonpath and expected value) to one response json assertion configuration using csv? Because the jsonpath and expected value both will depend upon the input provided and it can have major difference as per the case.
If yes, then how to do it please let me know.
Also if I can achieve my use case using other free API Testing Tool like Postman then also let me know.
You can normally parameterize any JMeter Test Element using CSV Data Set Config
For example you have the following response:
{ "name":"John" }
And the following CSV file:
$.name,John
$.name,Jane
Add CSV Data Set Config to your Test Plan and configure it like:
Add JSON Assertion as a child of the request which returns the above JSON and configure it like:
That's it, each virtual user and/or iteration will pick up the next line from the CSV file and the ${jsonPath} and ${name} placeholders will be replaced with their respective values:
as you can see, the first request passed because name matched John and the second failed because the assertion expected name to be Jane and got John

Read Excel data .csv file sequentially in Jmeter

I have a scenario to use data from each row for validation using a HTTP Request. have tried with the CSV config but it reads the first row only for the iteration.
I have a single iteration and all my samplers are in a single thread group. The data from csv file is retrieved sequentially only when i give the iterations to a value say 3 (each iteration each row is taken)
How to achieve on reading the csv file rows sequentially for single iteration ,where the thread group contains many HTTP request and i need the value from each row for each requests.
Kindly suggest me a solution
As per CSV Data Set Config documentation:
By default, the file is only opened once, and each thread will use a different line from the file. However the order in which lines are passed to threads depends on the order in which they execute, which may vary between iterations. Lines are read at the start of each test iteration. The file name and mode are resolved in the first iteration.
So implementing your scenario using CSV Data Set Config doesn't seem to be possible, I would recommend considering using JMeter functions instead such as:
__StringFromFile()
__CSVRead()
These functions read next line from the file each time they're called so you can use them instead of CSV Data Set config in each of the HTTP Request samplers. Check out Apache JMeter Functions - An Introduction to get familiarized with JMeter Functions concept.

Using Jmeter, I need to add UUID extracted from JSON in CSV in same column (multiple values of UUID) So to pass in Delete Path

Using Jmeter, I need to add UUID extracted from JSON and add that in CSV in same column (multiple) to feed in Delete Request (REST). This is to test multiple delete calls which has unique UUID generated from POST call. Or is there any other way I can test multiple delete call after extracting from POST calls. Lets say 50 Post then 50 Delete calls.
I don't think you need to do anything as given threads reside in the same Thread Group you should be able to use the same variable for the Delete request.
JMeter Variables are local to a thread so different threads will have different variable values.
If you are still looking for a file-based solution be aware of fact that you can write an arbitrary JMeter Variable into a file using Groovy code like:
Add JSR223 PostProcessor after the JSON Extractor
Make sure you have groovy selected in the "Language" dropdown
Make sure you have Cache compiled script if available box ticked
Put the following code into "Script" area
def csvFile = new File('test.csv')
csvFile << vars.get('your_variable')
csvFile << System.getProperty('line.separator')
This way you will get any extracted UUID written into test.csv file in JMeter's "bin" folder, you can use it in the CSV Data Set Config for your Delete request.
More information:
Groovy Goodness: Working with Files
Apache Groovy - Why and How You Should Use It

How to use CSV data set config inside a while loop in JMeter?

I need to test the same set of urls against 5 to 10 servers. URLs are defined in the CSV file. Server names are defined in User Defined Variables config.
I'm using While Controller based on the number of servers to iterate and execute the url requests. My current logic is defined as below:
Thread group
While controller
Counter (defines number of servers)
While controller (inner check "${URL}" != "<EOF>")
CSV Data Set Config (stop EOF is true)
HTTP Sampler (with url data)
As per the logic my script will run and read the CSV file once and stop. It's not reading the outer loop. Only inner loop and stopped.
Quote from JMeter Manual of CSV Data Set:
By default, the file is only opened once, and each thread will use a
different line from the file. However the order in which lines are
passed to threads depends on the order in which they execute, which
may vary between iterations. Lines are read at the start of each test
iteration. The file name and mode are resolved in the first iteration.
Thread groups cannot be nested. So you have to use the threadgroup to iterate in CSV and foreach to iterate in something else. The second option is to generate a CSV with the URL+Server variations, and using simply a single threadgroup to read the CSV.
First option is here.
Iterating URLs outer loop, iterating servers inner loop. You just need a threadgroup and a foreach inside it. See the pictures:
Sample results:
And of course 3 more results...
You can also play with CSVRead function if you have time :)