Alternatives to using CSV in JMeter (for generating usernames) - jmeter

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.

Related

How to Save all Responses to a file with loop count more that one?

This is a part of my test plan, and the loop count is 2.However only one set of responses generated
even i select "Add timestamp"
so, how to save data base on loop count ?
If you want to have separate files with the responses for each thread (virtual user) and Thread Group iteration you can use
__threadNum() function
${__jm__Thread Group__idx} pre-defined variable as prefix or postfix for the filename
So given the following configuration:
Here is the textual representation just in case:
user-${__threadNum}-loop-${__jm__Thread Group__idx}-response.txt
You will have the following files:
user-1-loop-0-response.txt
user-1-loop-1-response.txt
user-2-loop-0-response.txt
user-2-loop-1-response.txt
More information: Performance Testing: Upload and Download Scenarios with Apache JMeter

How to ramp up users every second with different URLs and stack the URL requests with the next user?

My requirement is as below:
I have 5 different URLs and I have to ramp up 5 users, with each new user added every second. However, when every new virtual user gets added, the previous user should also hit their URL again. Something like below:
Ramp-up 5s:
Loop 1: sec1.
VU1 URL1
Loop 2: sec2.
VU1 URL1
VU2 URL2.
Loop 3: sec3.
VU1 URL1.
VU2 URL2.
VU3 URL3 and so on.
How to achieve it in JMeter? Is there some other tool where we can achieve this?
The easiest way is to put the URLs into a text file, each on a new line and use __groovy() function to read the line from file equal to the number of the current thread (virtual user), something like:
${__groovy(new File('urls.txt').readLines().get(ctx.getThreadNum()),)}
Demo:
More information on JMeter Functions concept: Apache JMeter Functions - An Introduction
There are SaaS platforms online that do just that, eg https://rungutan.com

JMeter and random variable along with if controller

i want to control my sampler execution by using a random variable . I have a sequence of hits login,welcome,Bla,log out . i want the log out to be performed for 6/10 requests and let others do not login(so to speak 6 requests will perform the whole sequence including log out, 4 of them will perform will not perform log out ).How to achieve the same in JMETER
I have added a random variable rand and set it between 1-10 at the beginning of the thread group .Then just above Logout sampler i placed an IF controller were i check ${rand}>4 . How ever i always get all sequence executed . Please suggest what am i doing wrong
Your approach is a little bit weird, my expectation is that the problem is in the following areas:
Your IF Controller condition is wrong (check jmeter.log file for any suspicious entries)
Your random variable setting is wrong, i.e. it has the same value for all virtual users (threads) so they will either be executed all or none
So I would recommend using Throughput Controller or Switch Controller in order to set up this 60/40 distribution.
See Running JMeter Samplers with Defined Percentage Probability article for more details.
Random Variable in Jmeter is saved in long format be default so
${rand} > 4 won't work. You need to change
Condition to ${rand} > 4.0
or change Random Variable Output format to 00 (2 digits)
see Manual
This was accomplished by creating a combination of config element- random variable and an IF controller
1) a random variable was created with Minim and maxim value to meet above condition
2) and IF controller was able to check ${myrand}>4;
This had derived the desired result - thank you all

how to use separate csv file for each thread

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 :

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