JMeter - CSV Config with same variables - csv

I have 8 transaction (crud1, crud2) using 8 Transaction Controllers. I want each Thread (user) to perform all the 8 txns. Txn 1-4 are different from txn 5-8. The data for txn 1-4 are also different from txn 5-8. However, they have similar fields like name, address, etc.
All txns will run within a Thread Group.
Thread Gp
|- txn1
|- http req1
|- http req2
|- http req....
|- txn2
|- http req1
|- http req2
|- http req....
| .....
|- txn8
|- http req1
|- http req2
|- http req....
I read from https://www.perfmatrix.com/jmeter-config-element/ and it seems like I can only have CSV config in Test Plan and Thread Group. I've wanted to test duplicate names for different Transaction Controller and Samplers, however, I got inconsistent results.
Are CSV Config supported at the Controller and Sampler level ?
How do I handle the duplicate field names ? I use unique field names for the different txns in the same CSV row for each Thread loop ? Any other way ?
In terms of CSV Config scoping, how does JMeter handle duplicate field names at Test Plan, Thread Group, Controller, Sampler ?
Thanks
Edit:
"duplicate field names": As I have 8 Transaction in each thread looping, there are some transaction using the same field name, eg Txn 1 has an "Address" field and Txn 2 also has an "Address" field but they have different values. Since the CSV file is read per looping, I can only have 1 field called "Address". Does it mean that I have to called it Address1 and Address2 ? Is there feature in JMeter to handle this situation ?

You can have CSV Data Set Config wherever you want: https://imgur.com/a/xQpYpg8, CSV Data Set Config obeys JMeter Scoping Rules.
I don't know what do you mean by "duplicate field names", by default JMeter reads next line from the CSV file on each iteration. If this is not something you're looking for - take a look at Sharing Mode setting.

Related

How to pass different CSV value for every occurance in Jmeter

I am trying to pass different CSV Value in sequential manner for every occurrence in Jmeter.
I applied
Loop count
Counter
Beanshell Sampler
Value from CSV
JMS Point to Point Request
With this i am able to pass different value for every occurrence for multiple users.
But my script fails when i run for multi user multiple iterations.
It is not picking up sequential value.
My beanshell sampler code-
String variablename=vars.get("variable");
String csvvalue=vars.get("valuefromcsv");
vars.put(variablename,csvvalue);
It doesn't seem to me that you need to use scripting at all, it's quite sufficient to set up CSV Data Set Config and:
Point it to CSV file
Set up "Sharing Mode" to be All Threads
This way each thread (virtual user) will be picking up the next value from the CSV file on each iteration.
Also be aware that starting from JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting
You don't need to write the script for this. you can "Config Element-> CSV data set config" for the HTTP request. under CSV data set config page set the below values.
Variable names: give column names.
Delimiter : should be ,
Recycle of EOF: True
stop thread on EOF : false
Sharing mode : All threads.

Read Excel data .csv file sequentially in Jmeter

I have a scenario to use data from each row for validation using a HTTP Request. have tried with the CSV config but it reads the first row only for the iteration.
I have a single iteration and all my samplers are in a single thread group. The data from csv file is retrieved sequentially only when i give the iterations to a value say 3 (each iteration each row is taken)
How to achieve on reading the csv file rows sequentially for single iteration ,where the thread group contains many HTTP request and i need the value from each row for each requests.
Kindly suggest me a solution
As per CSV Data Set Config documentation:
By default, the file is only opened once, and each thread will use a different line from the file. However the order in which lines are passed to threads depends on the order in which they execute, which may vary between iterations. Lines are read at the start of each test iteration. The file name and mode are resolved in the first iteration.
So implementing your scenario using CSV Data Set Config doesn't seem to be possible, I would recommend considering using JMeter functions instead such as:
__StringFromFile()
__CSVRead()
These functions read next line from the file each time they're called so you can use them instead of CSV Data Set config in each of the HTTP Request samplers. Check out Apache JMeter Functions - An Introduction to get familiarized with JMeter Functions concept.

Using Jmeter, I need to add UUID extracted from JSON in CSV in same column (multiple values of UUID) So to pass in Delete Path

Using Jmeter, I need to add UUID extracted from JSON and add that in CSV in same column (multiple) to feed in Delete Request (REST). This is to test multiple delete calls which has unique UUID generated from POST call. Or is there any other way I can test multiple delete call after extracting from POST calls. Lets say 50 Post then 50 Delete calls.
I don't think you need to do anything as given threads reside in the same Thread Group you should be able to use the same variable for the Delete request.
JMeter Variables are local to a thread so different threads will have different variable values.
If you are still looking for a file-based solution be aware of fact that you can write an arbitrary JMeter Variable into a file using Groovy code like:
Add JSR223 PostProcessor after the JSON Extractor
Make sure you have groovy selected in the "Language" dropdown
Make sure you have Cache compiled script if available box ticked
Put the following code into "Script" area
def csvFile = new File('test.csv')
csvFile << vars.get('your_variable')
csvFile << System.getProperty('line.separator')
This way you will get any extracted UUID written into test.csv file in JMeter's "bin" folder, you can use it in the CSV Data Set Config for your Delete request.
More information:
Groovy Goodness: Working with Files
Apache Groovy - Why and How You Should Use It

using single csv file for multiple http requests in single thread group

I have a thread group with 2 different HTTP requests to test 10 users with CSV file of 10 rows of data.
In this scenario first HTTP request execute with 3 users with first 3 values from CSV file and remaining 7 users should used by second HTTP request with same CSV file used by remaining 7 data values.
You can use Switch_Controller with 2 HTTP Samplers under it and use Switch Value with changing values: 0,0,0,1,1,1,1,1,1,1 - it'll execute 3 times first HTTP Sampler and 7 times second HTTP Sampler.
Such switch value can be obtain using JSR223 Sampler or JSR223 Pre Processor (with groovy language) before Switch_Controller with the code:
vars.put("switchValue", "0001111111".substring( vars.getIteration()-1, vars.getIteration()) );
and then use in Switch Controller Value: ${switchValue}

How to use CSV data set config inside a while loop in JMeter?

I need to test the same set of urls against 5 to 10 servers. URLs are defined in the CSV file. Server names are defined in User Defined Variables config.
I'm using While Controller based on the number of servers to iterate and execute the url requests. My current logic is defined as below:
Thread group
While controller
Counter (defines number of servers)
While controller (inner check "${URL}" != "<EOF>")
CSV Data Set Config (stop EOF is true)
HTTP Sampler (with url data)
As per the logic my script will run and read the CSV file once and stop. It's not reading the outer loop. Only inner loop and stopped.
Quote from JMeter Manual of CSV Data Set:
By default, the file is only opened once, and each thread will use a
different line from the file. However the order in which lines are
passed to threads depends on the order in which they execute, which
may vary between iterations. Lines are read at the start of each test
iteration. The file name and mode are resolved in the first iteration.
Thread groups cannot be nested. So you have to use the threadgroup to iterate in CSV and foreach to iterate in something else. The second option is to generate a CSV with the URL+Server variations, and using simply a single threadgroup to read the CSV.
First option is here.
Iterating URLs outer loop, iterating servers inner loop. You just need a threadgroup and a foreach inside it. See the pictures:
Sample results:
And of course 3 more results...
You can also play with CSVRead function if you have time :)