JMeter: CSV Data Set Config "Lines are read at the start of each test iteration." - how exactly should it work? - jmeter

I'm concerned with work of CSV Data Set Config along JMeter rules set with scoping rules and execution order.
For CSV Data Set Config it is said "Lines are read at the start of each test iteration.". At first I thought that talks about threads, then I've read Use jmeter to test multiple Websites where config is put inside loop controller and lines are read each loop iteration. I've tested with now 5.1.1 and it works. But if I put config at root of test plan, then in will read new line only each thread iteration. Can I expect such behaviour based on docs only w/out try-and-error? I cannot see how it flows from scoping+exec order+docs on csv config element. Am I missing something?
I would appreciate some ideas why such factual behaviour is convenient and why functionality was implemented this way.
P.S. how can I read one line cvs to vars at start of test and then stop running that config to save CPU time? In 2.x version there was VariablesFromCSV config for that...

The Thread Group has an implicit Loop Controller inside it:
the next line from CSV will be read as soon as LoopIterationListener.iterationStart() event occurs, no matter of origin
It is safe to use CSV Data Set Config as it doesn't keep the whole file in the memory, it reads the next line only when the aforementioned iterationStart() event occurs. However it keeps an open file handle. If you do have really a lot of RAM and not enough file handles you can read the file into memory at the beginning of the test using i.e. setUp Thread Group and JSR223 Sampler with the following code
SampleResult.setIgnore()
new File('/path/to/csv/file').readLines().eachWithIndex { line, index ->
props.put('line_' + (index + 1), line)
}
once done you will be able to refer the first line using __P() function as ${__P(line_1,)}, second line as ${__P(line_2,)}, etc.

Related

Forcing thread to take a particular value from CSV and does not change till the test is completed

I have CSV file which contains Mobile Number, for e.g. number.csv
1276543281
1276543282
1276543283
1276543284
1276543285
Configured CSV Data Set Config with following options
Recycle on EOF? : True
Stop Thread on EOF? : False
Sharing Mode: All Threads
Thread Group settings are given below:
Number of Threads: 5
Ramp-up: 1
Loop Count: 10
Now, when I execute it, threads take any number from CSV and on next iterations based on the thread completion takes the value from CSV.
I want to force Thread1 to take 1st row, Thread2 to take 2nd row and so on... till the loop count is reached or the duration is reached.
You won't be able to achieve the described behaviour using CSV Data Set Config, with the above configuration each thread will pick up the next value on each iteration.
There is no guarantee that 1st thread will pick 1st line and 2nd thread 2nd line.
If you want to "stick" each thread to the respective line from CSV you should use __groovy() function instead like:
${__groovy(new File('/path/to/your/number.csv').readLines().get(ctx.getThreadNum()),)}
where ctx stands for JMeterContext class instance, see Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information.
you can achieve this solution by two ways
You can achieve by keeping the CSV dataset config only once in the controller
You can achieve by using Baolu CSV Data Set Config, in your scenario, set block size for each threads as 1
In these two scenarios, the value picked in first iteration those same values would be picking in next iterations.

JMeter - How to execute multiple CSV Data Sets

I have two CSV files, test1.csv and test2.csv. These two tests are slightly different, but I want to test them through the same test plan and report on them together. Therefore, I thought I would create two test fragments.
I have a thread group called 10 Concurrent Users because it's a thread group that will have 10 threads. I want this thread group to first run the Test 1 Test Fragment and then Test 2 Test Fragment. I want each test fragment to end after the corresponding CSV file reaches EOF.
I understand I can set Stop thread on EOF to true, but I don't want to stop the thread. I just want to "end" this test fragment. How do I do this?
This is what my Thread Group looks like. I don't want it to run infinitely, and I don't want to hard code the number of iterations.
One way I found was to just have two separate thread groups. One thread group for the first CSV file and one thread group for the second CSV file. Set the Thread Groups to "Infinite" and have "Stop Thread on EOF" set to true for each Data Set Module. However, it would be nice to not have to have separate thread groups as they are just duplicates of each other
In same thread group define a While Controller per CSV Data Set Config
Define in While's condition the value you get from CSV
Define an while controller with the Condition as ${url}
And don't recycle list on EOF:
To stop execution after the end of the CSV file is reached: within the CSV Data Set Config set Recycle on EOF? = False and Stop thread on EOF? = True.
If you want to iterate all the values in the CSV file and then continue you can configure the CSV Data Set Config like:
and put your Sampler(s) under the While Controller using the following __jexl3() function as the condition:
${__jexl3("${myVar}" != "<EOF>",)}
Another option is putting the logic under the Loop Controller, the number of lines in the CSV file can be determined dynamically using the following __groovy() function
${__groovy(new File('/path/to/your/file.csv').readLines().size(),)}

Regarding WebDriver Sampler and Config/Listener Folder Path

While trying to write Webdriver sampler with Config/listener element ,I have below issue ,Could any team assist me for the same?
1:- In config /listener element/webdriver browser setup file , if we want to enter some value from external resource (' or if we want to save summary report in PC, Is there any procedure to give unique path that can be run in any workstation /pc/ any directory after giving file name only because if we execute in other station or move file in other directory, everytime we need to change file location?Could you please guide me for the same?
While writing webdriver sampler request,I am able to execute script but i am getting below error in log viewer window and also wanted to break functionality as very small unit label for one webdriver sampler request{launch site/login successfully,validate record, logout} so after searching on google , i used sub sample start or samplestart function multiple time , but i am not getting label name in view tree listener result after setting one jmeter property. Could you please guide me for the same?
3:- Could we run three thread group at same time(all three thread run at same time) or some interval (first and sec run on same time but third start after 10 minute)
Thanks you for giving valuable time in advance?
Thanks Amit
You can give only the filename and JMeter will look for the CSV file and write results file into JMeter's "bin" folder (or the place where you launched JMeter from). You can also use __P() function to parameterize the file name or even path, for example if you do set your CSV Data Set Config like:
${__P(testdata,TestData.csv)}
you will be able to override the path using -J command-line argument like:
jmeter -Jtestdata=/path/to/somefile.csv
If you don't provide the property, default value of TestData.csv will be used. More information: Apache JMeter Properties Customization Guide
You're getting this "Invalid call sequence" error because you have duplicate WDS.sampleResult.sampleStart() function call, just remove one of them and that would be it.
Add a Constant Timer as a child of the first request or Flow Control Action sampler at the beginning of the Thread Group 3 and configure them to sleep for 600000 milliseconds.

How can run JMeter with limited CSV login details for multiple threads ?

Im just trying to run my JMeter script for 20 threads. I'm use CSV data set config for read login data. I set there are only 5 login details in CSV file. When i run the script only first 5 request got pass and rest of the thread request got fail. Anyone can suggest a solution. Thanks.
Apply the following configuration to your CSV Data Set Config:
Recycle on EOF - True
Stop thread on EOF - False
When JMeter reaches the end of the CSV file it will start over so 6th thread will get <EOF> as the value, 7th thread will pick 1st line, 8th thread will pick 2nd line, etc.
You can put your login request under the IF Controller and use the following condition:
"${line}" != "<EOF>"
to avoid the login failure due to this <EOF> variable value.

jmeter loop through multiple files

I have a Jmeter test with multiple while controler, each looping through data in separate files
I want each while loop to loop through the end of that file.
Structure:
While controller 1
- CSV Data Config 1
- Http sampler 1
While Controller 2
- CSV Data Config 2
- http sampler 2
When I set as an end condition: ${__javaScript(${myVar}!="<EOF>")} with stop thread on end of file to true, it stops the whole test completly.
If I set stop on end of file to false it loops on the also, meaning it loops one time too many
Is there another way to do this?
Thanks
A possible solution would be use beanshell processor and find the number of records in each file. Use the number of lines as the condition to break out of the loop. Please note that you will have to use parseint in the while condition as discussed in this thread.
Another option could be changing your While Controller to do the infinite loop and control thread stopping via CSV Data Set Config.
As per Using CSV DATA SET CONFIG guide:
It is worth mentioning that every CSV Data Set Config is visible to all Thread Groups by default. If you need to use separate CSV Data Set Config for every Thread, you create a number of data files that you need and in every CSV Data Set Config set “Sharing mode” to “Current Thread”
So the following combination:
Recycle on EOF = false
Stop Thread on EOF = true
Sharing mode = Current Thread
Should do the trick for you.

Resources