I have a folder where many files containing different SOAP requests. I want to run all of them. how ever this files count might vary when new requests are added and some are removed. So I want to set the loop count to the number of files in the folder. So that the user will not have to know the exact count. IS anyone has come across similar scenario and got a solution ?
Thank you in advance.
You can work it around with some scripting as:
Add a Beanshell Sampler to your test plan
Put the following code into the Beanshell Sampler's "Script" area:
File folder = new File("/path/to/your/folder");
File [] files = folder.listFiles();
int loops = files.length; =
vars.put("loops", String.valueOf(loops));
Add Loop Controller after the Beanshell Sampler
Put ${loops} into "Loop Count" input field
See How to use BeanShell: JMeter's favorite built-in component guide for comprehensive information on scripting in JMeter.
Related
I have a .csv data file with data like:
Row-1: A
Row-2: B
Row-3: C
When I run the script with 1 user 3 iterations, it is taking the same value A for all 3 iterations. What do I need to do if I would like to use value A for iteration-1 and value B for iteration-2 & etc.? It did not make any difference between placing the data file inside the thread group or outside the thread group.
Please could someone help?
Thanks,
N
In current form your question cannot be answered comprehensively, the missing bits are:
What test element/function do you use for reading the values from the CSV file. The recommended option is CSV Data Set Config
What controller is used for creating the "iterations"
CSV Data Set Config needs to be placed inside that controller
Sharing mode of the CSV Data Set Config needs to be set to "All Threads"
I am trying to create Jmeter script for Restful API which has two parameters. One is ID and other is CODE. I want to use four codes for a single ID. I have 180 different IDs and 3500 different codes for 1 hour load test.
Your requirements sounds something like this.
for( each ID )
{
for( each CODE )
{
//do something
}
}
If above my requirement is correct, It can be acheived by using 2 CSV files one for ID and one for CODE.
Take a look at this for detailed example, how it can be implemented. http://www.testautomationguru.com/jmeter-looping-2-csv-files/
I have a BeanShell PostProcessor under the setUp Thread Group.
It generates an ArrayList that I want to pass as a system property to the test Thread Groups in the Test Plan.
That array contains the number of threads in the test groups.
What is the syntax? How should I refer an element of that array in the Tread Group "Number of Threads (users)"?
This is what I have in the setUp Thread Group
ArrayList users = new ArrayList();
${__setProperty(users, ${users})};
This is what I put in the Number of Threads
${__P(users).get(0)}
It does not work.
Thanks
If you really need the "ArrayList" you can go it using bsh.shared namespace
In setUp Thread Group put the ArrayList into the "bsh.shared" namespace like:
ArrayList users = new ArrayList();
users.add(5);
bsh.shared.users=users;
In normal Thread Group you can read the value via __BeanShell function as:
${__BeanShell(bsh.shared.users.get(0),)}
However I feel that your test is badly designed and you could get rid of scripting or at least of using arrays.
My first thread group parses a file and stores all the lines in a List. The second thread group should retrieve objects from the List one by one and send HTTPS request. Now the problem, how to make the list of objects (not just a property value) between thread groups Appreciate any help.
You can use Beanshell Test Elements and bsh.shared namespace to share variables across thread groups
In first thread group after parsing:
bsh.shared.myList = myList;
In second (or whatever thread group)
List myList = bsh.shared.myList;
See How to use BeanShell: JMeter's favorite built-in component for more scripting options.
If you use different scripting language (not Beanshell) - it is still possible to use props pre-defined variable which stands for JMeterProperties instance. JMeterProperties is basically an instance of java.util.Properties so you can store any object in there like:
In first thread group:
List myList = new ArrayList();
//do what you need with the list
props.put("myList", myList);
In second thread group:
List myList = props.get("myList");
// do what you need with the list
I am primarily using JMeter -CSV_Data_Config element to bind csv data with a XML template as shown below.
This works beautifully when the data in the excel cells are static ie.. know set of columns. eg. 6 cols in csv file bind to 6 variables in XML file.
Lets say end user decides to have 15 cells of data in the csv file. Can i make the jMeter script dynamic to add new XML elements eg.Item with new attributes based on the number of cells in the csv file ?
I think a beanShell script might help if not ? not sure how .. any help -much appreciated !
Personally I would use the following approach for getting data from CSV file with unknown number of columns:
User Defined Variables (defined variable N with the value of 0)
While Controller
Counter (Start: 1, Increment: 1, Reference Name: N)
Samplers with data-driven logic
and use the following line as condition for the While Controller
${__javaScript("${__CSVRead(/path/to/your/file.csv,${N})}"!="",)}
See __CSVRead() function documentation for more details.