JMeter: response assertion for each line in CSV file - jmeter

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.

Related

While loop in 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

jMeter how to re-execute CSV Data Set Config

Using jMeter to set up a soak / load test that needs to run each request with different data. The structure I currently have is
Thread Group (2 Users, 2 Loops)
- Simple controller
-- Java Sampler (Custom Plugin) to convert CSV Formula data into NewThreadData.csv (as variable)
-- Java Sampler (Custom Plugin) to create directory of files created with NewThreadData.csv merged into a template
-- While Controller Condition - js NewThreadData column not = EOF
--- CSV Data Set Config NewThreadData.csv (Recycle False / Stop of EOF False) - filename passed as variable
--- JMS PUblisher with the FileName a variable using the filename column from within NewThreadData.csv
My problem is the on the second loop, the data is updated in NewThreadData.csv, but the CSV in the while loop never runs again.
Appears that the CSV Data Set Config "knows" it has been run, regardless of the actual CSV data.
Questions
How can I get the CSV Data Set Config to be rerun / re executed in this scenario?
Are there undocumented variables or means of getting the config to reprocess?
Is there a way to spawn a new thread on each iteration rather than reusing the existing thread, as the CSV does execute once for each "User"[thread]. I also tried Stop on EOF : True, but that stopped the second loop.
Aim is to eventually ramp up the user count and the number of loops (changing to forever); with there being about about 100 different combinations of data to be inserted on each loop. The formula I am using has time and thread number to give me data uniqueness along with other data that is dynamically created from a formula. Recycle on EOF is not feasible as I need to regenerate the csv contents on each loop. A super-csv I don't think is feasible to cover the load and soak scenarios.
Thanks in anticipation. Andrew
I don't think it's possible to "reset" the CSV Data Set Config, it's a configuration element hence once it reads the file in its current state it will "stick" to its content.
If you're manipulating file content dynamically I would rather recommend going for __CSVRead() function instead which is evaluated in the runtime just where it's placed therefore it doesn't reserve file and it "rewinds" to the beginning of the file when the last line is read.
More information: How to Pick Different CSV Files at JMeter Runtime
CSV Data Set Config element is executed first and only once even though you have placed it within the while controller. Hence CSV Data Set Config element is not suitable for your requirement.
You could use JSSR223 Pre-processor to work with the dynamic CSV files using a supported programming language/script (Java , Groovy)

Sharing mode in CSV Data Set Config in Http Request

In a Http Request, how the values from the CSV file can be shared.
In the Https request I have a variable in 100 places but wanted the different values from CSV to distribute among 100 places having one variable name in the same http request of the thread group.
You cannot achieve this using CSV Data Set Config as it will update the variable value either for each virtual user or for each iteration.
You can consider __CSVRead() function as an alternative, it is pretty easy:
${__CSVRead(test.csv,0)} reads 1st column from test.csv file in "bin" folder of your JMeter installation
${__CSVRead(test.csv,1)} - reads 2nd column
${__CSVRead(test.csv,2)} - reads 3rd column
etc.
${__CSVRead(test.csv,next)} - goes to the next line
Demo:
More information: How to Pick Different CSV Files at JMeter Runtime

Reuse parameters from single CSV Dataset for multiple users

I am using "CSV Dataset config" to read a parameter from the specified CSV file. I have set the "Sharing Mode" as all threads. For that Thread Group, I have specified "Number of Threads" as four (for four users). I have set "Recycle on EOF" as "True" (I tried with "False" too, but no difference).
When I start the test, It ran for just one user, read all the data from the CSV file, completed the test and stopped. For the other three users, it did not run at all. My guess is - because the CSV file was closed once the testing for user 1 completed.
I tried using multiple Thread Groups in the same Test Plan and each Test Group had just one user. Even then it did not work.
The expectation is- the same CSV file can be used for multiple users and across different Test Groups. There must be a way to rewind the CSV file either by JSR223 Post Processor or otherwise.
I cannot reproduce your issue using JMeter 5.2 and it is quite hard to tell anything comprehensive without seeing your Test Plan.
My expectation is that you violated JMeter Scoping Rules somewhere somehow, i.e. you placed CSV Data Set Config inside one Thread Group while it should live at the same level as all Thread Groups
Given
The following CSV file stored as test.csv in JMeter's "bin" folder:
line1
line2
line3
And the following CSV Data Set Config:
2 Thread Groups set up like:
You should see that each virtual user in each Thread Group is reading next line from CSV file on each iteration:

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 .....

Resources