Randomize user name with associated job id for user - jmeter

In my test plan I have two CSV files, one is with user name,password and other one with user name with multiple JOB_Id .
The the JOB_Id is being used for one post call and one get call.
Requirement: When I logged in with the specific user I want the randomly associated JOB_Id should be selected from the other CSV file associated to that User (in the example I have only selected 8 JOB_Id but during run it would be more than 100). How to do it?
Here is my samples CSV files.
User Details Files :
JOB_Id File:
Test Plan:

CSV Data Set Config is initialized when the test starts, if you want to get JOB IDs from another file dynamically - you need to switch to __CSVRead() function
Example setup:
CSV file 1, usernames.csv:
perfuser0001
perfuser0002
CSV file 2, job ids
perfuser0001.csv
perfuser0001-job-id-1
perfuser0001-job-id-2
perfuser0002.csv
perfuser0002-job-id-1
perfuser0002-job-id-2
Demo:
More information: How to Pick Different CSV Files at JMeter Runtime
Also since JMeter 3.1 you're supposed to be using JSR223 Test Elements and Groovy language for scripting so please consider migrating from Beanshell on next available opportunity.

Related

How to relate two variables in JSON POST request

I have a JMeter test scenario as follows: several hundred users have to login to a platform and send a POST request with several hundred of profiles to generate a report. For the data, I use two csv files.
One csv file contains the data of the users with which JMeter will login and send a POST request to generate a report. It contains the following fields:
userid, companyid, password
once logged in, each of these users has to choose profiles from another csv file, to generate reports about those profiles. The other csv file has these fields:
profileid, companyid
Each user can only generate profiles of the profiles that have the same companyid.
The profiles have to be placed inside an array, which in turn is inside an object, in a JSON request. IMPORTANT: all the profiles have to be placed inside the array in a single iteration. That means that if there are 1000 profiles, they have to be set on the array at the same time.
I haven't been able to:
Figure out how to ensure that for each user, the specific profiles available to that user get set in the array.
Figure out how to actually insert the values in the array, all in a single iteration .
Could someone offer advice on how to achieve this?
Disclaimer: I don't know Java and I have just begun using JMeter a few days ago.
It's hard to provide a comprehensive answer without seeing your CSV files structure so I can provide only a generic piece of advice:
If you're looking at CSV Data Set Config be aware that it reads the next line on each iteration, if you need to read multiple lines within the bounds of a single iteration you need to use __CSVRead() function or consider using JSR223 Test Elements for scripting
Solution 1
You can use a CSV Data Set Config element to read the data, userid, companyid, password from the first CSV file.
Add a CSV Data Set Config element to read the user credentials.
It will read one row for each thread and each iteration.
Now you have the companyid available for the entire iteration. You need to filter the data with the companyid from the second CSV file. This can be done with Groovy (you can use Java too).
Add a JSR223 Sampler to retrieve the profileid from the second CSV file. Following code demonstrates reading the CSV file into list of files and then filter the lines with companyid
log.info("Processing profile")
def lines = new File('company_profiles.csv').readLines()
def filteredLine=lines.find { it.contains(args[0])}
def lstRecord = filteredLines.get(currentRecord).split(",")
vars.put("profileid","${lstRecord[0]}")
SampleResult.setIgnore()
NOTE : companyid is passed to the script as an argument. Please see the highlighted areas in the following.
The profileid is set as a variable in the script vars.put("profileid","${lstRecord[0]}"). You can use the profileid within the iteration of the current thread with ${profileid}

Jmeter interactions with UI and Database inserts simultaneosly

When we create a Jmeter script through Blazemeter/third party script recorder and there are some insert/update and delete functions on UI involve in records. Just want to know when we run same JMeter script with 100 users, Do those new records get inserted/update/delete in database as well ? If yes, then what should be remaining 99 users data if there are unifications on UI.
When you record the user action it results into hard-coded values so if you add foo line in the UI it gets added to the database.
When you replay the test with 1 user depending on your application implementation
either another foo line will get added to the database
or you will get an error regarding this entry is present already
When you run the same test with 100 users the result will be the same, to wit:
either you will have 100 identical new/updated entries
or you will have 100 errors
So I would suggest doing some parameterization of your tests so each thread (virtual user) would operate its own unique data, like:
have a CSV file with credentials for 100 users which can be read using CSV Data Set Config
when you add an entry you can also consider adding an unique prefix or postfix to this like:
current virtual user number via __threadNum() function
current iteration via ${__jm__Thread Group__idx} pre-defined variable
current timestamp via __time() function
unique GUID-like structure via __UUID() function
etc.

Jmeter Multiple CSV files

I wanna use 2 CSV files. One CSV file with user id nd passwords.And second CSV file, containing data for adding different producers(agents) against each user.
I mean user id 1 should take 1st row of producer data, user id2 shall take 2nd row of producer data and so on. IS this possible in jmeter and how?
Put user 1, password 1 and other data in the same row which needs to be used. Make sure you CSV is having the headers and do not put any thing in the "Variable Names" of CSV Dataset config.
Now, when you run with multiple thread, 1st thread will pick 1st row and then move to the second row. Other threads will also do the same.
Hope it helps.
You can use multiple csv's but then you have to maintain login and other test data binding. So, it is better to put it in one.

With Jmeter, how can we create users using CSV file, if the user already exist in first execution

With Jmeter, how can we create users using CSV file because at CSV it is picking first userid and if re-running the script it will say user already exist.
Please help me to create users.
If you need to create a new user every time you run the test it doesn't make sense to use CSV files and CSV Data Set Config, I would recommend using following JMeter Functions instead:
__time() - returns current timestamp in different formats
__Random() - returns a random number in given range
__randomString() - returns a random string from given characters
You can also use any of above functions as prefix or postfix for username from the CSV file - this way you will get new unique logins each time you will run your test
Abdul, you can concatenate random number using __Random function in the request where you are passing the userid [picked from the csv file] for creating the user.
For example: Your .csv file contains userid as:
ravi
abdul
Now, in the http request pass the userid picked from the csv file and concatenate __Random function
Example: ${userid}${__Random(1,100000,str_ran)}
Additionally, you can also get the list of userids created in the test run by writing a simple code in Beanshell Postprocessor that can create a separate .txt file with all the userids.
Let me know if you need any further information.
You can get more information on JMeter elements from the knowledge base

JMeter Unique once feature

I want to use Unique once setting in JMeter as used in load runner for a project.
The data are provided through a CSV file and are parameterized.
If the script is ran with multiple users then also the data should be unique, meaning one data can be used only once.
Users in JMeter equal Threads so just use CSV Data Set Config to read your CSV
Sharing mode All threads - (the default) the file is shared between all the threads.
You can consider using HTTP Simple Table Server plugin, it has KEEP option, if you set it to FALSE once record is read from the source file it will be removed guaranteeing uniqueness even if you run your tests in Distributed Mode.
You can install HTTP Simple Table Server plugin using JMeter Plugins Manager
I have come up with the solution for "Unique Once Vuser setting in jMeter"
1) Create excel and insert data in excel column wise i.e. horizontally insert all the data.
2) Use below code in place of your unique parameter.
${__CSVRead(filePath,${__threadNum})}
So it will pick unique data for each thread.
Thread_1 Iteration_1 --- Data from col 1
Thread_1 Iteration_2 --- Data from col 1
Thread_1 Iteration_3 --- Data from col 1
Thread_2 Iteration_1 --- Data from col 2
Thread_2 Iteration_2 --- Data from col 2
Thread_2 Iteration_3 --- Data from col 2
Although every answer works perfectly fine, but just a different way using if control.
CSV Data Set Config settings :
if controller validation code : ${__groovy(${__jm__Thread Group__idx} == 0,)}
In this if controller we keep a JSR223 sampler and in that we can have one or more line of following code : vars.put("VarName",vars.get("CSV_input"))
where we replace VarName : with the variable name we want to use in the script and CSV_input with the the variable name from CSV Data Set Config input

Resources