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

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.

Related

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(),)}

JMETER nested while loop is stopping at first line of the CSV data file

I have to make a GET call on IDs stored in a CSV while and I have to retry on GET call till it returns 200 response code.
This is what my current structure looks like ..
GET thread group
Once only controller to grab authentication for each thread
While Controller with condition "${__javaScript("${index}"!="<"EOF">")}" to check for end of the CSV
file
CSV data config file (Each file is unique for each thread) , variable name is "index", Recycle on
EOF - False, Stop thread on EOF - True,
sharing mode - current thread
While Controller with condition "${__javaScript(parseInt(vars.get("Response_code"))!=201)}"
User defined variables - Response_code
Http GET request
JSR233 post processor - "vars.put("Response_code",prev.getResponseCode());"
JSR223 post-processor - To write ID returned in successful call to another CSV file
Now I am not getting error or anything .. but I was expecting first while controller to loop through CSV file for each id, then make a GET request for each id and then second while loop would wait for success code but for some reason, GET call is only executing for the first entry in the csv and then exit out of it. What am I missing here?
CSV data config file (Each file is unique for each thread)
this is not how it works, the CSV Data Set Config is being initialized once with the filename resolved at the time of its execution, it doesn't load the new CSV file for each virtual user.
If you're looking for an option of supplying the CSV file name(s) dynamically in the runtime - consider switching to __CSVRead() function. See How to Pick Different CSV Files at JMeter Runtime article for more details.

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

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.

Execute csv rows, one by one, on all threads

My Test plan has a csv dataset config element, a thread group with a http sampler.
I would like to read first element from csv, run it using 20 threads for 50 iterations, then repeat this sequential process for all the 30 rows of my csv.
I have set the toggle for stop on eof to true.
Most solutions,I have gone through on Stack Overflow, andother blogs, for a suitable solution, suggest adding a loop controller or a while loop, reading the rows using a preprocessor and looping, however, in these cases, I am not able to achieve my objective.
TestPlan
-- User Defined Variables
-- HTTP Request Defaults
-- HTTP Header Manager
-- JSR223 PreProcessor (To get the CSV line count)
-- CSV Data Set Config (Recycle on EOF - False, Stop on EOF - True)
-- Thread Group
-- HTTP Sampler (GET,pass each of the csv dataset element as part of path)
-- View Result Tree
With the above setup, I see that the whole csv is iterated, I inlcuded a loop controller, with loop count, moved the HTTP sampler, under it.
However, when I do this, I was unable to get the usage of Iterations in thread-group.
Article References:
Use same row per thread from a CSV data set in JMeter
How to read each and every row of csv by single user in JMeter?
How to loop each thread with unique data from CSV Data Config file
JMeter - multiple user taking unique row from CSV file
Your requirement is too "exotic", I would recommend creating a new CSV file out of your existing one with:
1st line repeated 100 times (20 threads x 50 iterations)
2nd line repeated 100 times
3rd line repeated 100 times
...
30th line repeated 100 times
If you have problems generating the file you can do this in the runtime, like:
Add setUp Thread Group with 1 thread and 1 loop to your test plan
Add JSR223 Sampler to the Thread Group
Put the following code into "Script" area:
SampleResult.setIgnore()
def generated = new File('/path/to/new/csv/file')
generated.delete()
new File('/path/to/old/csv/file').readLines().each { line ->
1.upto(100, {
generated << line << System.getProperty('line.separator')
})
}
In main Thread Group use CSV Data Set Config "normally", just point it to use the /path/to/new/csv/file
See The Groovy Templates Cheat Sheet for JMeter for more examples of useful Groovy code snippets which you can use to enhance your JMeter tests.

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