Jmeter CSV data config element not working - csv

I have created jmeter script for load testing and added CSV data element to read Username and Password of 300 Users.Also followed below steps;
Created CSV file using a notepad and stored it in a directory where created script stored.
Defined variables and file path in CSV data set element
Used variables as parameters of HTTP request
Increased number of Threads
But it doesn't worked as expected.How can i fix this?

Temporary reduce threads count to 1-2, add View Results Tree listener and inspect request and response details.
If don't see proper username/password combination in the request body - your script is misconfigured. Check out Using CSV DATA SET CONFIG guide for detailed setup instructions.
If you see valid username/password pair but login is not successful, follow below checklist:
Add HTTP Cookie Manager to your test plan
If point 1 doesn't help - check for dynamic request parameters. Probably you'll need to extract some value from the first response (when you execute GET request for the login page) with the Regular Expression Extractor, convert it into a JMeter Variable and add it as a parameter to the request which performs login.

Related

Jmeter - when there are number of threads are running, the variable from JSON extractor is not working sometimes

I am now using Jmeter to run the test of APIs.
The situation is that I have a login Api which will return a token inside response. I use a JSON extractor to save the token as a variable. Then, I use the ${token} is the header of other requests.
However, I found that when I was trying to run 40-50 threads, the ${token} in some threads would be empty, and caused a high error rate.
Therefore, may I ask is there any method to solve it and why?
Thanks very much.
Try saving full response from the Login API, most probably your server gets overloaded and cannot return the token and returning some error message instead.
There are following options:
If you're running JMeter in command-line non-GUI mode you can amend JMeter's Results File Configuration to store the results in XML form and include the response data, add the next lines to user.properties file:
jmeter.save.saveservice.output_format=xml
jmeter.save.saveservice.response_data=true
and when you run your test next time the .jtl results file will contain response bodies for all the requests.
Another option is using a Listener like Simple Data Writer configured like:
and when you run the test the responses.xml file will contain the response data
Both .jtl results file and responses.xml can be inspected using View Results Tree listener
More information: How to Save Response Data in JMeter

Unable to capture request and response values into csv by using sample variables

Could some one please advise me where am i doing wrong.
When i tried to capture request and response values into csv using sample variables by adding in the next line to user.properties file: sample_variables=request,response
it's throwing null in the request and response columns in the csv file.
Is there is any another work around to achieve this?
Thanks,
Rajani
Please follow the below steps to capture the request URL and response. Alternatively, you can extract the request/response using Bean Shell sampler.
Open JMeter.Properties and configure the sample variables. Restart JMeter.
In your test plan, create two Regular Expression Extractors for your HTTP request, one is to capture 'request' and another is to capture the 'response'. Use (?s)(^.*) regular expression to extract everything.
To capture the request, configure as shown below. If you want to capture the request headers, select Request Headers radio button.
To capture the response, configure as shown below.
In the Aggregate report, make sure you checked the options as shown below and provide a name in Filename e.g. google.csv.
Here is my JMeter test plan for Google.com
Here is the expected output. Check in the JMETER_HOME\bin\google.csv.

JMeter remote server - hundreds of one to one tests

I need to test a set of HTTP Tomcat servers using JMeter. I have a list of 'n' target servers and a list of 'n' JMeter remote test servers and a list of a single variable parameters that will be tested in the URL against each Tomcat server. However, each JMeter remote test server should test only a single target server with a set of threads cycling through all the parameters - so the test is 1 to 1 but I need to collate the results as the target servers form a CDN edge set with a common origin URL.
How could I ensure that each target server is tested by a single JMeter server using the same set of parameters? Using a CSV DATA SET CONFIG for the list of parameters is obvious but I can't see how I could use the same type of config element for the list of target servers.
The only way I can envision it is that I distribute a csv file containing a single unique target URL to each remote JMeter server. That way all the hundreds of threads on each JMeter server only know about one target but can use a single filename for the source URL. Does anyone know of a better way?
JMeter remove "slaves" basically execute the same test plan which is being specified on the "master" machine so default configuration is not something you can use.
There are 2 options:
You can modify user.properties file on each slave machine to contain the single unique endpoint (URL) like:
in user.properties file define a property which will specify the endpoint:
url=http://some.cdn.1
in the Test Plan use __P() function to read the value like:
${__P(url)}
So given different url property on each remote slave each slave will be hitting different endpoint. See Apache JMeter Properties Customization Guide for more information regarding JMeter properties and ways of working with them.
You can use __machipeIP() or __machineName() function in conjunction with the If Controller so switch execution branches basing on the "slave" IP address or hostname, something like:
If Controller, condition: ${__machineIP()} == "172.30.40.50"
do something specific for CDN1
If Controller, condition: ${__machineIP()} == "172.30.40.51"
do something specific for CDN2
etc.

Logging a cookie in CVS logs with JMeter

When logging in a CSV format in JMeter, is it possible to log a cookie value?
It seems to be possible log all cookie data when using XML logs (the option "Save Sampler Data (XML)"), but is there something like that, or better more specific (just a single specific cookie), for .csv?
We would like to use this to log a session ID cookie for all requests, so that it's possible to follow the requests in other application logs.
There are 2 JMeter Properties which can help you to get what you want:
CookieManager.save.cookies - CookieManager behaviour - should Cookies be stored as variables, can be "true" or "false". If it is set to "true" any cookie which is in scope will be accessible as a JMeter Variable in form of "COOKIE_cookieName". So if you have i.e. SESSIONID cookie it may be referred as "COOKIE_SESSIONID"
sample_variables- Optional list of JMeter variable names whose values are to be saved in the result data files.If you need more than 1 - the list should be comma-separated.
So if you set these 2 properties in i.e. user.properties file (in the /bin folder of your JMeter Installation) as
CookieManager.save.cookies=true
sample_variables=COOKIE_SESSIONID
your .jtl response will look something like:
1417446424571,459,HTTP Request,200,OK,Thread Group 1-1,text,true,10503,1,1,190,your SESSIONID cookie value here
NB
JMEter restart is required to read properties from user.properties file
You can override properties by passing them via -J command line argument as
jmeter -JCookieManager.save.cookies=true -Jsample_variables=COOKIE_SESSIONID -n -t /path/to/your/test/plan -l /path/to/results/file.jtl
See Apache JMeter Properties Customization Guide for more information on different JMeter properties and ways of setting and overriding them

How to use responses from a Jmeter JDBC Request in a HTTP Request

Here's my situation:
I want to do this:
I have a list of URLs in a MySQL database which I want to hit using a HTTP Request to see if the response is a HTTP Status code of 404 or not.
I have done this:
Added and configured a JDBC Config Element.
Added and configured a JDBC Request Sampler. Basically a select statement that returns a table with 8 columns. I have provided 8 comma-separated variables for the 'Variable names' field, so that the results of the JDBC request can be identified with these variable names.
Created a HTTP Request Sampler that uses one of those variables ${url} in the 'Server Name or IP' field.
Though the JDBC request works flawlessly and returns a table with a bunch of rows, the problem with this is that the HTTP Request Sampler never picks up the variable from the JDBC Request result.
The HTTP Request looks like this in the 'View Results Tree':
GET http://${url}/
I have tried these solutions:
Add 'Save Responses to a File' listener to the JDBC Request. This creates a file of type '.plain' and not a CSV. Had it been a CSV, I could have utilized that CSV file by creating a CSV Data Set Config. So this attempt failed.
I have tried forcing the file name in the above attempt to always use 'C:\JMETERTest\data.csv'. But it ends up creating a new file named 'C:\JMETERTest\data.csv1.plain'. This attempt failed too.
I tried to reference the URL column as ${url_1} in the HTTP Request's Server Name field. It worked. But the problem now is that in the results tree, all the requests are going for the the URL from only the first row of the result set. I see that this is because of the row number '_1' specified in the ${url_1} above. I can use this if someone can suggest a way to parameterize the '_1' into a variable that I can loop through (probably using a 'Counter' element). I created a Counter Config Element by the Reference Name 'loopCounter'. And used this in the Server Name field of the HTTP Request:
${url_("${loopCounter}")}
But now my HTTP Requests look lamer:
GET http://${url_("${loopCounter}")}/
This did not work too.
Solution 3 looks more doable to be only if I could resolve the parameterization of the row number.
I am open to JMeter Plugin suggestions too.
I will update anything else that I try as we go on.
P.S. Please let me know if my question is not clear in anyway.
Have you tried wrapping the HTTP sampler in a ForEach controller (parent) where the variable for the controller is the URL variable obtained from the JDBC sampler?
Also, the output variable in the ForEach will be the variable you now use in the HTTP sampler.
That way it will iterate through each variable from the beginning of the index to the end and run the sampler once each time.
In 'Save responses to a File' Listener, Select Checkboxes "Don't add Suffix and Prefix". Checking these two options will ensure, you get exact Log file name.