JMeter not reading variable from CSV file - csv

I'm new to Jmeter and am trying to use variables from a CSV file in the path of my HTTP GET request.
I've looked through various tutorials and answers to this question, but I still can't figure out what I'm doing wrong. The file just has one header (ID). It works if I enter the ID in the path, but as soon as I try read it from the CSV file, it fails:

Your configuration looks good, double check jmeter.log file for any suspicious entries.
Other recommendations:
Given you have only a single column it might be easier to use __StringFromFile() function directly in the HTTP Request sampler body like:
/api/Users/${__StringFromFile(c:\Automation\Test.csv,,,)}
I believe Content-Type and Authorization should go in HTTP Header Manager, not in the request parameters
See Testing SOAP/REST Web Services Using JMeter article for more details.

The problem wasn't with the reading of the variable. I thought that the first line of the file would be treated as a header, but it reads the first line of the file as a variable, so my file looked like:
ID
001
It read "ID", when I wanted it read "001.

Related

JMeter GET Request – How do you add query parameters from .csv file?

I am having issues with successfully making a GET http request with query parameters reading from a .csv file. I am working with a JSON application. Thank you bunches in advance!
Path: /mortgagecalc/?amount=${amount}&years=${years}&maxInterest=${maxInterest}
CSV Data Set Config
HTTP GET Request
I don't see any "issues" with your configuration
Given you have test.csv file which looks like this:
1,2,3
4,5,6
7,8,9
your setup should read the next line on next iteration and populate request details with the values from the CSV file:
If this is not the case for you:
Check the path to the CSV file, it must exist and be readable otherwise your request won't be executed
Check jmeter.log file for any suspicious entries
Check generated JMeter Variables using Debug Sampler and View Results Tree listener combination

When i tried to send a part of Json body from the csv file in the request getting **ERR**

Issue : When i tried to send a part of Json body from the csv file in the request getting ERR . I know as per the reference document it throws ERR when uable to open the csv file Or spaces.
Not sure what went wrong.
Below are the screenshots
Check what's in jmeter.log file
Normally you cannot use JMeter Variables as the CSV file path in the CSV Data Set Config, as per JMeter Test Elements Execution Order the CSV Data Set Config is being executed before anything else so the variable might not be yet initialized.
If this is the case - consider using __CSVRead() function instead, check out How to Pick Different CSV Files at JMeter Runtime article for more details.
If this is not the case - check both variables values using Debug Sampler and the presence of the file under the path where ${dealmemodetails} variable is pointing.

Send Multiple JSON Files from Directory to a REST API with JMETER

I'm really struggling with getting Jmeter to work with sending multiple json files in Jmeter to a REST API. I have tried other questions on stack and tutorials online and none of them answer my specific requirement.
My requirement is that I will have various json messages saved to a file directory and I'm trying to use JMeter to loop through the folder, pick up the json's and pop it into a HTTP request one at a time i.e. one file = one request and view the result.
Does any one know how to do this?
The easiest solution would be:
Directory Listing Config plugin to read file names into a JMeter Variable
__FileToString() function to read the file content

How can i pass files to a CSV Sampler in JMeter

I have a directory with CSV files. each file contains a list of GET requests I'd like to make with JMeter. What I'd like to do is read all the files in a directory, and then loop through each CSV to send the requests in JMeter. The number of files isn't consistent so I don't want to hard code the file names into CSV samplers.
So in effect I'd like to read all the files in the directory and store the files in an array variable. The loop through the array and send the CSV file to the CSV sampler which will in turn read the CSV file and pass the content to an HTTP Request sampler to send the GET requests.
I created a beanshell script to read the files in the directory and store them in an array, but when I try to pass this to the CSV config element, I get errors stating the variable doesn't exist.
I've tried another beanshell script to read the file and pass the lines to an HTTP request Sampler as a variable, but the issue was, it would store all the file contents in memory per thread.
I'd like to know the best approach to read the files, send the requests and use the response data to generate reports
You will not be able to populate CSV Data Set config using Beanshell as CSV Data Set Config is a Configuration Element and according to Execution Order user manual chapter Configuration Elements are executed before anything else.
Since JMeter 3.1 you should not be using Beanshell, it is recommended to switch to JSR223 Elements and Groovy language
I would recommend going for Directory Listing Config plugin, it scans the provided folder (in your case with CSV files) and stores the found paths to files into a JMeter variable
So you can use the Directory Listing Config in combination with __StringFromFile() or __CSVRead() functions and that should be more or less good way of implementing your requirements.

Loading JSON data with CSV Data Set Config

I'm new to Jmeter so I hope this question is not too off the wall. I am trying to test an HTTP endpoint that accepts a large JSON payload and processes it. I have collected a few hundred JSON blobs in a file and want to use those as my input for testing. The only way that I have come across for loading the data is using the CSV config. I have a single line of the file for each request. I have attempted to use \n as a delimiter and have also tried adding a tab character \t to the end of each line. My requests all show in put of<EOF>.
Is there a way to read a file of JSON objects, line at a time, and pass them to my endpoint as the body in a POST?
You need to provide more information, to wit: example JSON file (first 2 lines), your CSV Data Set Configuration, jmeter.log file, etc. so we could help.
For the time being I can state that:
Given CSV file looking like:
{"foo":"bar"}
{"baz":"qux"}
And pretty much default CSV Data Set Config setup
JMeter normally reads the CSV data
Be aware that there are alternatives to the CSV Data Set Config, for example:
__CSVRead() function. The equivalent syntax would be ${__CSVRead(test.csv,0)}
__StringFromFile() function. The equivalent syntax would be ${__StringFromFile(test.csv,,,)}
See Apache JMeter Functions - An Introduction to get familiarized with the JMeter Functions concept.