How to execute ForEach loop 100 times in Jmeter? - json

I have a thread group with loop count set to 5. Inside it, I have used a JSON extractor with 1st request which creates a total of 100 variables with purchaseOrderId_1 pattern. I used it in ForEach controller next so the loop shoud execute 100 times ideally. Inside the ForEachLoop, I have a while controller, which executes the child requests 5 times until all the 5 rows of data in Csv Dataset config is read. The goal is to run the 3rd request 5 times for one value of output variable of ForEach controller and in the end, 500 times for the 100 values. The 3rd request should run 2500 times in total. But, the test stops after executing the 3rd request 5 times only for purchaseOrder_1.
Screenshot of my test plan flow.

There is quite a lot of nesting. I tried to interpret your statements and created a test plan. Please check if this is the requested pattern you are expecting.
This is the Sample JMX
CSV File csv
Note: Update CSV file path after you download both the files

Related

how can we create a block size in jmeter with csv config? Each thread should pickup specific set of values

how can we create a block size in JMeter with CSV config?
I have 5 multiple users and one Bulkuser.csv file with 4 columns,
The file has around 2000 values.
I wish to create a block of 400 values for my 5threads[users].
1st USER WILL USE 1st – 400 VALUES (Values in ROW 1-400)
2nd USER WILL USE NEXT 5 VALUES (Values in ROW 401-800)
and so on..
How can we implement this? is there a beanshell pre-processor script for each data read and decide to read the specific file as per thread number?
As of JMeter 5.3 this functionality is not supported, the only stable option I can think of is splitting your Bulkuser.csv into 5 separate files like user1.csv, user2.csv, etc. and use __threadNum() and __CSVRead() functions combination for accessing the data like:
${__CSVRead(user${__threadNum}.csv,0)} - reads the value from column 1 from user1.csv file for 1st thread (for 2nd thread it will be user2.csv file, etc)
${__CSVRead(user${__threadNum}.csv,1)} - reads the value from column 2
.....
${__CSVRead(user${__threadNum}.csv,next)} - proceeds to the next row
More information: How to Pick Different CSV Files at JMeter Runtime

Jmeter functional test validation with sql and csv file

Currently I am trying to use Jmeter for functional tests, but I am currently stuck on how to best implement flexible test validation.
The ultimate goal would be to have a csv file for data input and validation, so it is easy for other people to add or remove test cases.
Case:
Login
Execute bulk job (involving a variable nr of objects and creating a variable nr of objects)
Validate the result via datase sql statements. (multiple SQL requests and response assertions)
Logout
Some statements I would like to execute:
Nr of invoiced BI (per contract ID)
Nr of distinct invoice ID's for BI with invoice ID (per contract ID)
*Get list of Invoice ID's to use in following SQL statement:
For list of invoice ID's invoice header must be equal to....
For list of invoice ID's invoice lines must be equal to....
For each sql I would use a response assertion to validate the sql result. Response assertion with for example 10 lines with a variable inside each line and OR statement to match/equal at least one of the lines.
Data is generated, so ID's can be different each run, I am only sure that the data for an object should match one of x cases.
Everything is very dynamic and the nr of check varies for each test case that is being executed from the csv file.
So I imagine I would need a foreach controller for each sql statement/check/assertion
CSV file would look something like this:
Bulk Job / Contracts / Contract Validation / Invoice header validation /
1234 / 12345 / 2 / 456
1234 / 12435 / 5 / 968
4256 / 89754 / 1 / 987465
4256 / 78597 / 4 / 654
4256 / 87596 / 2 / 852
Or like this:
Bulk Job / Contracts / Contract Validation / Invoice header validation /
1234 , 12345:12435 , 2:5 , 456:968
4256 , 89754:78597:87596 , 1:4:2 , 987465:654:852
What would be the best way to store and setup something like this? CSV file or xml or ...?
Maybe use multiple csv files and try to keep everything aligned?
Consider using scripting-based option i.e. JSR223 Assertion
If you provide Result variable name in the JDBC Request sampler:
You will be able to get the Result Set as a single object:
Which is basically an ArrayList:
So you will be able to iterate it in a single simple function
So you should be able to perform dynamic assertions in one shot.
Check out Debugging JDBC Sampler Results in JMeter article for more information if needed.

how to run particular http request to multiple times in jmeter?

I've multiple http samples in Test Plan but i want to run only one request for multiple times based on csv data set config and remaining http requests will run once particular sample is complete all the iteration based on csv data set config.
In above image i've 5 http samples and i've csv data set for first request,once first request is run for entire csv data set test data then another samples should run,please provide solution how to perform this type of operation in jmeter.
you can use Loop Control and provide the number of hits you needed.
To go to Loop Control:
Right click on the Thread/ThreadGroup
Click on Add
select the Logic controller
Select the Loop Controller
According to the problem, there is a need to execute a particular request to execute in a loop. The loop could be organized in the following way.
-> Thread Group
-> Loop Controller
-->Particular Request
-> Other Request
The CSV Dataset could be found in Config Element and should contain a path to a particular file with data (e.g. accounts.csv).
Both elements could be located in
Loop controller: Add ->Logic Controller -> Loop Controller
CSV Data Set : Add -> Config Elements -> CSV Data Set Config.
The loop can run for the exact amount of records in a file if
Loop Count is equal to a number of strings in the accounts.csv
Forever, it could be stopped by Test Duration automatically or by Stop button.
The CSV Data Set config should have a path to a file with data.
If a file contains headers, then Variables will be assigned based on column names from first string, otherwise, it is necessary to provide variables names in configuration.
ANSWER: If you use 9 variables and all of them are set as header names in a file, then don't provide them in CSV Data Set Config. They will be created automatically, so you can use all 9 variables through names in your file.
If headers are not provided, set 9 all in a Variable Names field, using comma as separator.
Configure your CSV Data Set Config like:
Reference name: foo
Recycle on EOF: false
Stop thread on EOF: false
Put the CSV Data Set Config under the While Controller and put ${__javaScript("${foo}" != "<EOF>",)} into "Condition" input
Add If Controller under the While Controller and put "${foo}" != "<EOF>" into the "Condition" input
Put your first request as a child of the If Controller
Replace foo with your actual JMeter Variable reference name everywhere in the script.
This way JMeter will loop until there are entries in the CSV file and will proceed with the remaining requests when the end of CSV file will be reached.
See Reading all Values from the CSV and Continue chapter of the Using the While Controller in JMeter article for more detailed information on configuring JMeter for your scenario.
You can verify with only one variable and Rest variable you don't required in If and while controller.

Running a thread group multiple times for all the values in a csv file

I have recorded a series of 5 HTTP requests in a thread group (say TG). The response value of a request has to be sent as a parameter in next request, and so on till the last request is made.
To send the parameter in first request, I have created a csv file with unique values (say 1,2,3,4,5).
Now I want this TG to run for all the values read from the csv file (In above case, TG should start running for value 1, then value 2, till 5).
How do I do this?
Given your CSV file looks like:
1
2
3
4
5
In the Thread Group set Loop Count to "Forever"
Add CSV Data Set Config element under the Thread Group and configure it as follows:
Filename: if file is in JMeter's bin folder - file name only. If in the other location - full path to CSV file
Variable Names: anything meaningful, i.e. parameter
Recycle on EOF - false
Stop thread on OEF - true
Sharing mode - according to your scenario
You'll get something like:
See Using CSV DATA SET CONFIG guide for more detailed explanation.
Another option is using __CSVRead() function
This method of creating individual request for each record will not be scalable for multiple records. There is another scalable solution here - Jmeter multiple executions for each record from CSV

nested loop with file1.csv and file2.csv in jmeter

I am using Apache JMeter and I need to run function call in 2 nested loops driven by csv datafiles. There is similar Q&A at How to implement nested loop in jmeter? but it's not based on datafiles.
I have 2 files:
long.csv:
1
2
3
...
100.000
and short.csv:
a
b
c
I need to run nested loop test with data from those files
foreach x from long.csv
foreach y from short.cvs
call(x,y)
and I want the calls look like this:
call(1,a)
call(1,b)
call(1,c)
call(2,a)
call(2,b)
call(2,c)
call(3,a)
call(3,b)
call(3,c)
...
call(100000,a)
call(100000,b)
call(100000,c)
The calls may be reordered, but I need unique call on every combination of inputs.
Suggestions?
If you are looking for detailed steps, please check here.
http://www.testautomationguru.com/jmeter-looping-2-csv-files/
I tried & it seems to work - Please check below snapshot for details.
CSV Data set Config 1 reads a csv file - the var ref name is 'vara'.
it has 10 rows , 1-10
CSV Data set Config 2 reads another csv file , contains 3 rows a, b c - and the var ref name is 'varb'. 'Allow ReCycle on EOF?' is set to True.
Thread Loop Count is for CSV Data set Config 1
Inner Loop Controller's loop count is for CSV Data set Config 2