How to add csv data config in switch controller - jmeter

I want to randomly select 1 csv data config out of 9 in jmeter. I am using switch controller and added 9 csv data configs. But it is not selecting any one. I am getting data from all csv's.

Create 9 variables in "User Defined Variables" and assign different file names for each variable (file1=file1.csv,file2-file2.csv,.....).
Create another "User Defined Variables" and use ${__RandomFromMultipleVars(file1|file2|file3|file4|file5|file6|file7|file8|file9)} to select any of the above variables randomly and use it in CSV data set config.
Script
User defined variables 1
User defined variables 2
CSV data set config
Results Tree

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}

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 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

How to do data driven testing using jMeter if the values are present in the body not in parameters

I know using of data driven in jMeter by passing the values in parameters, but my concern is how to the data driven testing when the values are sending in request of a body. Any help will be appreciated
You can use CSV Data Set Config, Add > Config Element > CSV Data Set Config
In the CSV file you can set the value for the parameters.
example csv file
Provide csv file path in CSV Data Set Config
Imported CSV file will be the data to perform data driven testing for login page, where first row of the csv file is variable name and rest is test data.
Set the number of thread user under Thread Group same as number of rows present in the csv file.
Have you tried fill body like this?
MyVariable is user defined variable

How to start reading from second row using CSV data config element in jmeter

CSV data config always reads from first row. I want to add column headers in the CSV file. Hence I want the CSV config to start reading from second row.
Below is the setting in Thread Group.
No.of threads = 1
Loop Count= 10 (depends on no.of rows in CSV file)
What version of JMeter are you using? It seems like leaving the Variable Names field empty will do the trick. More info here:
Versions of JMeter after 2.3.4 support CSV files which have a header
line defining the column names. To enable this, leave the "Variable
Names" field empty. The correct delimiter must be provided.
Leave the variable names empty like on an attached snapshot.
In csv file add header. Header values will act as variable names which could be used as parameters in requests.
~sample facility.csv file
facility1,name
GG1LMD,test1
Request
There is a field called "Ignore first line (only used if Variable Names is not empty)", set this to true.

Resources