JMeter :: Parameterization Query for mapping test data with user ID - jmeter

The issue is with JMeter parameterization Logic.
I have a csv file with user id and pwd - which is fine
Another CSV has 10 records, one for each user ID. How do I map these records to user ids?
Csv1:
UserID, Pwd
TestUser1, Password1
TestUser2, Password1
CSV2:
Record
Rec1forUser1
Rec2forUser1
Rec3forUser1
Rec1forUser2
Rec2forUser2
and so on..
How do I arrange the mapping when multiple users (say 2) are going to run for a Loop of 3 records each.

It's not possible with standard JMeter equipment, what you're asking for.
I would suggest to use the User data set as a driver, and for the record read at each iteration then split second dataset to separate files (1 per user), then ingest 'em in the custom JSR223 element - actually, the file operations toolset Groovy equipped with makes that task pretty easy, smth. like:
new File(path + userID + "_someSuffix.csv").eachLine { line ->
line.split(',').each { field ->
... use fields here somehow ...
}
}
In case you have to have multiple iterations per user, you probably would have to read the Users dataset that way as well.
And finally, yet another way is to denormalize/flatten your dataset: include (repetitive) User records into second dataset along with data belonging to user, like:
TestUser1, Password1, Rec1forUser1
TestUser1, Password1, Rec2forUser1
TestUser1, Password1, Rec3forUser1
That may not look pretty, but would do the job.

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

Spring Batch, read whole csv file before reading line by line

I want to read a csv file, enrich each row with some data from some other external system and then write the new enriched csv to some directory
Now to get the data from external system i need to pass each row one by one and get the new columns from external system.
But to query the external system with each row i need to pass a value which i have got from external system by sending all the values of a perticular column.
e.g - my csv file is -
name, value, age
10,v1,12
11,v2,13
so to enrich that i first need to fetch a value as per total age - i.e 12 + 13 and get the value total from external system and then i need to send that total with each row to external system to get the enriched value.
I am doing it using spring batch but using fLatFileReader i can read only one line at a time. How would i refer to whole column before that.
Please help.
Thanks
There are two ways to do this.
OPTION 1
Go for this option if you are okey to store all the records in memory. Totally depends how many record you need to calculate the total age.
Reader(Custom Reader) :
Write the logic to read one line at a time.
You need to return null from read() only when you feel all the lines are read for calculating the total age.
NOTE:- A reader will loop the read() method until it returns null.
Processor : You will get the full list of records. calculate the total age.
Connect the external system and get the value. Form the records which need to be written and return from the process method.
NOTE:- You can return all the records modified by a particular field or merge a single record. This is totally your choice what you would like to do.
Writer : Write the records.
OPTION 2
Go for this if option1 is not feasible.
Step1: read all the lines and calculate the total age and pass the value to the next step.
Step2: read all the lines again and update the records with required update and write the same.

Resources