I have 5 APIs which uses different form of ids like Uid, Sid and Did .
With each request any one from those three is required.
List of Uid, Sid and Did are stored in separate CSV file.
My req samples looks like
http://Host:port/Users?me=checkUser&Uid=U_User1
http://Host:port/Users?me=checkUser&Sid=S_12
http://Host:port/Users?me=checkUser&Did=D_90101
http://Host:port/AddrUsers?me=checkUser&Uid=U_User1
http://Host:port/AddrUsers?me=checkUser&Sid=S_12
http://Host:port/AddrUsers?me=checkUser&Did=D_90101
Pulling Uid, Sid and Did from CSV randomly is doable but expected is
http://Host:port/Users?me=checkUser&Uid=${UID} or Sid=${SID} or Did=${DID}
http://Host:port/AddrUsers?me=checkUser&Uid=${UID} or Sid=${SID} or Did=${DID}
So without creating set of three for each APIs I want to pass Param name and Ids to single request [Ignore OR that just to differentiate param. Each request will only have one Id from Uid, Sid, Did]
I am aware about using CSV values through Uid = ${UID} in http request parameters section
Right now I am using 3 cvs and 3 version of same APIs to call the requests with Uids, Sids and Dids
But is it possible to have one CSV having all the Ids (mix of ids) and send those values to each requests randomly?
So you should create your bzm-Random CSV set like:
ID,Value //CSV header
UID,UidValue1
SID,SidValue1
DID,DidValue1
UID,UidValue2
SID,SidValue2
DID,DidValue3 and so on...
Under the bzm-Random set check the "Random Order" & "First Line is CSV Header"
and now your URL would be like:
http://Host:port/Users?me=checkUser&${ID}=${Value}
This way you will be able to iterate the values using single request.
Related
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}
I am taking input from Csv file in jmeter to test my API request. I need to to skip a few column values. Is there any way to do this?
Let's say my .csv has columns:
User, password, Location, Status, Amount
I am interested to take User, Password, Amount columns as input into my api request.
How can I do that?
You can just ignore using them in your API request. E.g., if you API requires a JSON payload with only the three columns, you have mentioned above, you just need to substitute them as shows below (assuming everything is a String value except Amount in this JSON).
{
"username": "${User}",
"password": "${Password}",
"Amount": ${Amount}
}
Since you are selectively substituting only the three column values, you are controlling the skip/ignore and not JMeter.
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
I need to read two values from two different rows in a csv and pass those values as a part of the body of a POST request.
Through CSV data set config I'm able to read only one value at a time. Is there any way I can read two values in the same request?
Example:
sourceSystemGuid,sourceSystemName
sourceSystem_733,sourceSystem733 sourceSystem_590,sourceSystem590
sourceSystem_959,sourceSystem959
I need to read two values for sourceSystemGuid in one request.
Without custom scripting it’s not possible.
But you can put 4 columns per line and that will do what you want.
Let us consider we have an excel/csv containing multiple columns, column1 contains the website and the other columns contain the parameters, how to perform http GET login and map parameters of each site and get the result sheet in jmeter. Can someone help in solving this issue....
Thanks...
you can map columns of the csv file with CSV_Data_Set_Config
by setting variables names to : url,user,pwd.
after that you can use them on another components like this '${user}'
do http request HTTP_Request
and save the result with Save_Responses_to_a_file or to see them View_Results_Tree