While loop in Jmeter - jmeter

I am trying to create a jmeter test in which I am taking the http requests and their bodies from the csv file.
I want to run it for 2 users which will fire the http requests mentioned in the csv file 2 times. Which means 2 users will simultaneously start the test, they will fire the http requests mentioned in the csv file once and then will do the same with 2nd iteration. I tried doing it with different settings for Recycle EOF to TRUE/FALSE and Stop thread on EOF to TRUE/FALSE but either it is going in infinite loop or it is firing the requests as . I am definitely missing something here. Any help is appreciated. I am using Jmeter version 5.3

The easiest would be just replacing your While Controller with the Loop Controller with the number of loops equal to the number of lines in the CSV file.
You can determine the number of lines using the following __groovy() function:
${__groovy(new File('c:/full.csv').readLines().size(),)}
In the CSV Data Set Config set "Recycle on EOF" and "Stop thread on EOF" to false

Related

how to take data from CSV file without retaking, using multiple threads in jMeter?

I have a CSV file with data, that is dynamic and is changed every test run (it could be 3k or 80+k lines). This data - is uuid, that I extract from CSV and set as a variables to my http requests. HTTP request has DELETE method, so after getting each uuid from CSV file - I can't use it again cause I would have a 404 status code. I've already set up CSV Data Set Config and there is no problems when I do it in 1 thread (Number of Threads (users): 1). But, for proper performance testing I need to run test in multiple threads, i.e. 30 or 50. And the point is - that I don't know how to set up logic to be agile and if I have a CSV file with 50k+ uuids that should be used in one Thread Group that has 30 threads - each thread will take only assigned to him uuids, won't retake them and won't take not assigned to him uuids.
Thanks in advance!
If you're using CSV Data Set Config (and this is what you should be using for 80+k lines file) with default Sharing Mode setting of "All Threads"
each JMeter thread (virtual user) will be taking next line on each iteration which means that each UUID will be used only once no matter how many users are there.
If you additionally set Recycle on EOF to "False" and Stop thread on EOF to "True" your test will be stopped when JMeter reaches the end of the CSV file so no duplicate requests will be sent.

Delay between HTTP requests which is from a CSV file

I'm using JMeter. I have a thread group that pulls multiple parameters from a CSV file and makes HTTP requests. I want each request to have 3 seconds in between. I tried to use constant timer, but it sends one request and stops. How can I do this?
My CSV file has 8073 lines. Each line is one request.
This is what my thread group looks like:
Thread Group
CSV Data Set Config
HTTP Request
Save Responses to a File
View Results Tree
If you want delay before each request - add a Constant Timer like:
if you want delay after each request - add Flow Control Action sampler like:
With regards to your "sends one request and stops" behaviour, by default Thread Group makes only one "iteration":
you either need to change this 1 to 8073 or just tick "Infinite" box and configure CSV Data Set Config to stop when it reaches the end of the CSV file:
Make the Thread Group Loop Count Infinite and CSV Data Set Config's Stop thread of EOF true, it'll execute all CSV records
See also option to execute CSV rows in parallel

How to make Jmeter use each login only once

I am writing a JMeter webdriver test for 8 concurrent users.
In my test, I created a CSV Data Set Config with 10 logins.
I have noticed that JMeter is reusing the same login for at least 2 users.
This causes an issue where the 2 logins are trying to do the same task and one of them will fail waiting for specific elements to appear.
Is there a way to force JMeter to always use an unique login per user?
It depends on the nature of your test and how you set up the CSV Data Set Config.
If you set "Sharing Mode" to All Threads - each thread will be reading new value on each iteration:
however if you will have more than 1 iteration:
1st user will read line # 9
2nd user will read line # 10
3rd user will read line #1
If you want to have "unique" data consider the following approaches:
Using __CSVRead() or __groovy() function to read the data from file, this way you will have control on when to proceed to the next line
Using HTTP Simple Table Server which "READ" endpoint has KEEP=FALSE parameter so once data is used it is removed so no other thread can use it.

Proper way to save Jmeter Results to csv - how to finalize results file

I do the same scenario that was already described in other topics not at once: I'm trying to save Jmeter results to database from csv file.
I have an Aggregate Report listener that saves results to csv file, and everything is OK here.
I also added TearDown Thread Group to my scenario that gets strings from this csv file (by CSV DataSet config) and processes it to database. This part also works fine with static CSV.
Two problems here:
Aggregate Report listener is added on the top level of scenario. So, it adds all samplers from TearDown group to results file as well. So, it's like a recursion: if I do teardown until end of result file, I'll never reach the end, as every new iteration adds some new rows.
At the moment when CSV dataset config takes csv file, it's still in memory only and not finalized to disk. So, file is just empty. How to tell Jmeter that it should write the content from memory to a file and close input stream?
Any ideas how to solve it?
I know that I can move Listener into threads, but in this case I have to duplicate it for every thread group. It's always better to have one listener in one place as I can potentially change its settings.
Thanks in advance.
There is a JMeter Property jmeter.save.saveservice.autoflush defaulting to false
# AutoFlush on each line written in XML or CSV output
# Setting this to true will result in less test results data loss in case of Crash
# but with impact on performances, particularly for intensive tests (low or no pauses)
# Since JMeter 2.10, this is false by default
#jmeter.save.saveservice.autoflush=false
You can amend its value by setting it to true so JMeter will write down each single line of results into the file and closing the file once done. It can be done in 2 ways:
Permanent: add the following line to user.properties file (located in JMeter's "bin" folder)
jmeter.save.saveservice.autoflush=true
You will need to restart JMeter to pick the change up
Ad-hoc: pass the property via -J command-line argument
jmeter -Jjmeter.save.saveservice.autoflush=true -n -t .....

JMeter: response assertion for each line in CSV file

I am learning JMeter and trying to do the following:
0) I only use 1 thread and only 1 loop
1) I have a CSV Data Set Config that loads a file with a bunch of strings (I am required to use CSV Data Set config)
2) I have a http request that responds with a web page. I need to make an assertion to it to verify if every string from the CSV is present on the page
I figured out that JMeter iterates to the next line in CSV file either for each thread or for each thread or loop.
But I only use 1 thread and 1 loop, and I don't want to repeat the whole test plan multiple times to verify if it contains multiple strings (it also does other stuff than this). How do I do this?
The CSV Data Set Config only increments to the next line on the next iteration. If you want access to all(or several) values in the CSV file in the same iteration, you should probably use the __CSVRead() function. Or possibly even the __StringFromFile() function.
If you're just doing this as a one of exercise, you can also put all the values you need to check in 1 CSV line and read them as different columns.
Lastly you can use a while controller to read the next line from CSV Data Set Config as explained here.

Resources