how to use separate csv file for each thread - jmeter

My scenario is like,
1. Login by multiple users (100 users)
2. Select 50 items by id's specific to user
I have placed id's for each user in separate csv file say user1.csv, user2.csv, user3.csv and so on.
My result should be like Thread 1 should take user1.csv and process all 50 id's in loop controller.
Thread 2 should take user2.csv and so on.
I tried with below example, but still couldn't find the solution.
Eg. I used file path as C:\abc\user${_threadNum}.csv
Or
C:\abc\user${_threadNum}.csv
Variable name in csv file is user_id
Requeat will look like /home/abc/${user_id}
I want thread 1 to use the user1.csv file and substitiue the value of user_id in the request and thread 2 should use user2.csv and so on.
If I execute my above plan, I am getting error as /home/abc/EOF
How is this possible in JMeter? Or any other approach?
Please provide solution with an example, since I am new to JMeter.

Create your files like comman_name_1,comman_name_2,comman_name_3
etc. & select current thread option from dropdown list present in csv data config set.This will allow threads to use different files per thread or put values in a single file and select current thread option.

It's easy, just add CSV Data Set Config to each thread (user1.csv for thread1 and so forth). Configure CSV Data Set config, and select one of this values in Sharing mode field:
Current thread group - each file is opened once for each thread group
in which the element appears
Current thread - each file is opened separately for each thread
UPD: I have done it right now, it works
Script looks like this:
I selected 'Current thread' in each CSV Data Set Config

I was making the mistake of using single underscore in fetching the count of thread.
We need to use double - underscore like this : ${__threadNum}
Note :

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 Uploading files using multiple threads

I want to test file uploading using Jmeter.
I want to upload files using 5 threads concurrently.
1 Thread successfully uploads all the files but after that all threads says file exist (which makes sense)
Is there a way i can upload all files successfully from all 5 threads, may be generate new file name each time ?
This solution will work for the configurations that you shared, 5 concurrent users uploading 10 files each.
First of all, create separate files for each thread (you have 10 files, copy them into 50) and rename them as below
Thread1_file1_0
Thread1_file2_0
Thread1_file3_0
.
.
Thread1_file10_0
Thread2_file1_0
Thread2_file2_0
.
.
Thread5_file10_0
Then create a csv file and add file extensions in column A. Make sure that row 1 reflects the extension of Threadx_file1_0 and row 2 reflects the extension of Threadx_file2_0 file as below and save the csv file in the same folder of your jmx script
Now to the script configurations, add 2 counters before your POST request (which uploads the files) with below configurations
First counter
Start 0
Increment 1
Reference Name originalName
Track counter independently for each user Yes
Reset counter on each Thread Group Iteration No
Second counter
Start 1
Increment 1
Reference Name Iteration
Track counter independently for each user Yes
Reset counter on each Thread Group Iteration No
Now add a loop controller with loop count set to 10, then add another counter, OS Process Sampler and CSV Data Set Config as children of the loop controller with below configurations
Counter configurations
Start 1
Increment 1
Reference Name fileNumber
Track counter independently for each user Yes
Reset counter on each Thread Group Iteration Yes
CSV Data Set Config
Filename extensionsCSVFile.csv
Variable Names extension
OS Process Sampler configurations
Command cmd
Command parameters
/C
ren {path to your folder}\Thread${__threadNum}_file${fileNumber}_${originalName}.${extension} Thread${__threadNum}_file${fileNumber}_${Iteration}.${extension}
Each line as a separate parameter. Now use file name in your post request as below
{path}\Thread${__threadNum}_file1_${Iteration}.pdf
{path}\Thread${__threadNum}_file2_${Iteration}.pdf
.
.
{path}\Thread${__threadNum}_file10_${Iteration}.docx
This will do the job, but i suggest that you also add a way to revert the names back to Thread1_file1_0. You can do it by following the below steps
Add a BeanShell PostProcessor as a child of the OS Process Sampler with below code in the code area
props.put("lastIteration", vars.get("Iteration"));
Now add a tearDown Thread Group, then copy the loop controller with all its elements from previous above steps and paste into the tearDown Thread Group (except the BeanShell PostProcessor, remove it after you paste).
Now go the OS Process Sampler within the tearDown Thread Group and adjust the second parameter as below
ren {}\Thread${__threadNum}_file${fileNumber}_${__P(lastIteration)}.${extension} Thread${__threadNum}_file${fileNumber}_0.${extension}
Finally, just make sure that number of threads in both main thread group and tearDown Thread Group is the same, which in this case 5. The structure will be as below

Alternatives to using CSV in JMeter (for generating usernames)

I have a JMeter Test Plan with following structure
Test Plan
**ThreadGroup1**
--CSV Data Config-001
----SimpleController
--------------LoginRequest
--------------Action-abc-Request
**ThreadGroup2**
--CSV Data Config-002
----SimpleController
--------------LoginRequest
--------------Action-xyz-Request
I have two CSV files which contain list of users like this..
**CSV-001**
Username1
Username2
.. ..
Username50
**CSV-002**
Username51
Username52
.. ..
Username100
In my scenario, I need to run a load test with say 100 users. 50 users login from ThreadGroup1 and other 50 users login from ThreadGroup2. Users from both threadgroups login simultaneously.
Currently, I have to go through process of manually creating/editing these CSV files whenever I change the number of total users.
Please suggest if there are any alternative time-saving & performance-efficient approaches through I which can fulfill my scenario requirements (without using CSV files).
I will appreciate, if you can explain the alternative solution with some details as I am quite new to JMeter stuff. Thanks.
Another idea is to use
Username${__threadNum}
for the first thread group and
Username${__BeanShell(ctx.getThreadNum()+Z+1)}
for the second, where Z equals the total number of threads in thread group 1. You also need to add 1 since ctx.getThreadNum() returns a thread number using a 0 based index, whereas the __threadNum function is 1 based.
You can use a counter in each thread. The start value for the counter in the first thread would be 1, in the second 51. Be sure the 'Track counter independently for each user' check box is unchecked.
If you set the reference names to thread1Count and thread2Count respectively, you can use
Username${thread1Count}
for the first thread and
Username${thread2Count}
for the second.

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.

How to do load-testing for 100 concurrent users login with unique username and passwords using Jmeter?

My test plan scenario is to do load-testing for 100 concurrent users login to website.
I have created Threadgroup with Number of threads as 100.
Created CSV file which contains 100 users login details (unique usernames and passwords).
Under Sign in sample added a “User Parameter” from Thread Group -> PreProcessors to it. Added variables using __CSVRead function which reads values from file test.csv.
Selected the login sample and changed the values of userid and password to ${A} and ${B}.
Is this the right way to do or is there any alternative way to achieve this?
If this works for you and works as you expect, that's enough.
But looks like CSV Data Set Config is more suitable and easier to use for multi-user scenarios than __CSVRead function:
Thread Group
Number of Threads: N // count of your test-threads (users)
Loop Count: 1
CSV Data Set Config
Filename: [path to your csv-file with usernames / passwords]
Variable Names: username,pwd // extracted values can be referred as ${username}, ${pwd}
Recycle on EOF? False
Stop thread on EOF? True
Sharing mode: Current thread group
. . .
HTTP Request // your http call
. . .
As per documentation:
The function is not suitable for use with large files, as the entire
file is stored in memory. For larger files, use CSV Data Set Config
element or StringFromFile.
Pretty detailed guides available here:
How to use a CSV file with JMeter
Using CSV DATA SET CONFIG

Resources