Jmeter interactions with UI and Database inserts simultaneosly - jmeter

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.

Related

Variable value reset to default when new user iteration starts in Jmeter

i am using JMeter BeanShell Preprocessor to generate unique date value in each iteration. I am using two (2) users for my load test on database . for user 1 the date value generating as expected but when the user change to 2 then date variable value reset to default. what should i do to prevent the reset of date variable value as on insertion i am facing violation of unique key constraint error.[enter image description here](https://i.stack.imgur.com/euEc9.png)
i have mentioned in the screen shot what I tried . I need help to solve my problem
Don't post code as images
Don't use Beanshell, since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language for scripting
Your problem is that both users are adding 1 day to the date and if the database is configured that way it doesn't allow the same dates - the insert or update will fail.
I don't know the details of your test scenario but you could consider adding current iteration number and/or current virtual user number to the date from the User Defined Variables, the relevant functions are:
vars.getIteration() - for the iteration number
ctx.getThreadNum() - for the user number
However the best option would be pre-generating the list of dates somewhere in setUp Thread Group
Example Groovy code:
def now = new Date()
1.upto(200000,{index ->
def date = now.plus(index)
new File('dates.csv') << date.format('yyyy-MM-dd') << System.getProperty('line.separator')
})
And then use CSV Data Set Config to read the generated dates from the dates.csv file in your main Thread Group
Given you have 2 users and 100k iterations which means that the last date would be 2570-08-11 so make sure it matches your requirements and the database is capable of accepting the date such far in the future

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}

Randomize user name with associated job id for user

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.

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

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.

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

Resources