How to pass multiple values one by one in Jmeter - jmeter

In Jmeter I need to test a particular scenario with different customer. I am able to do that using CSV data set config and it's working fine but in my maven java project I want to pass the customerId as -DcustomerId=123456,123457.. something like that.
Is there anyway in Jmeter where I can extract the value of customerId and pass that customerId one by one to test my scenario.

Add JSR223 Sampler to your Thread Group
Put the following code into "Script" area:
props.get('customerId').trim().split(',').eachWithIndex { customerId, index ->
vars.put('customerId_' + ++index, customerId.trim())
}
where props stands for an instance of Properties class instance and vars is a shorthand for JMeterVariables. Check out Top 8 JMeter Java Classes You Should Be Using with Groovy for more information on above and other JMeter API shortcuts available for the JSR223 Test Elements.
Add ForEach Controller after the JSR223 Sampler and configure it as follows:
That's it, each JMeter thread (virtual user) will iterate all the customer IDs via the ForEach Controller:

Related

JMeter ForController not seeing Variables

I'm trying to iterate through a User Defined Array using a ForEach Controller. I'm looping through the array and for each node, creating a new variable with the iteration count appended to the name. However, the ForEach Controller doesn't ever fire.
I can see that the values are created by logging them, but the ForEach Controller doesn't ever make it's HttpRequests. Please note that this is a prototype, our actual use case will have 1000-5000 nodes in the array and will do more then just an HttpRequest. Thanks for your help.
The variables must exist prior a thread (virtual user) reaches the ForEach Controller
PreProcessors are executed before Samplers and are not executed without Samplers, so your PreProcessor gets executed only before "HTTP Request Not In ForEach"
So the options are in:
Replace ForEach Controller with the HTTP Request Not In ForEach so the latter one would appear earlier in the Test Plan
Convert JSR223 PostProcessor to JSR223 Sampler, Samplers are executed consecutively and upside down. If you don't want it to generate a result add SampleResult.setIgnore() line somewhere in your script. See The Groovy Templates Cheat Sheet for JMeter for more Groovy-related tips and tricks
PreProcessor is executed before samplers in its scope, so that's why you don't enter the ForEach Controller.
You can change it to JSR223 Sampler, or add Sampler before the For ForEach Controller

JMeter use variable array values individually

I am struggling a bit to make use of a variable created using the Json extractor, I have extracted all the ID's from a response and want to cycle through them individually across the threads.
Thread 1 would use id_1 and thread 2 would use id_2 etc.
I have tried using a ForEach controller but it's cycling through the whole set for each thread.
Test runs like this:
Generate access token
Get parameters - Extract the list of ID's here.
Update parameter - Pass the ID individually here per thread.
Is there a way to achieve this?
You won't be able to do this because as per documentation:
Properties are not the same as variables. Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function.
So if you want to perform extraction using one thread and then hit everything using multiple threads you can either convert all the variables which start with id_ to JMeter Properties using the following Groovy code snippet:
vars.entrySet().each { variable ->
if (variable.getKey().startsWith('id_')) {
props.put(variable.getKey(), variable.getValue())
}
}
and then you will be able to access the properties using __P() function like:
${__P(id_${__threadNum},)}

Passing one api parameters value to another api

In JMeter I have two Api , one api generate filename and id then these parameters pass to another api here I used plugin path extractor and also use csv data set config to extract , save and pass parameters and its value to another api but problem is when multiple user it generate multiple filename and id but how to pass those file name and id to every httprequest to another api.
You don't need any CSV Data Set Config, it will be sufficient to
Add a suitable Post-Processor to extract the generated file name
The Post-Processor will store the generated name into a JMeter Variable
You should be able to use the variable in the "2nd API"
As per JMeter Documentation Variables are local to a thread so each thread (virtual user) you define in the Thread Group will have its own value.
Demo:
More information on JMeter Correlation concept: Advanced Load Testing Scenarios with JMeter: Part 1 - Correlations

how can i pass dynamic values to url in jmeter

I have to give dynamic values to url which takes number of users and their age , which can be selected though web page. but I want to give it in Jmeter using BeanShell PostProcessor.
Help me in this,since I'm new to Jmeter.
This is the path:
/destinations/packages?airports%5B%5D=LGW&units%5B%5D=000577%3ADESTINATION&when=29-05-2016&until=&flexibility=true&flexibleDays=3&noOfAdults=2&noOfSeniors=0&noOfChildren=1&childrenAge=3&duration=7114&first=0&searchType=search&searchRequestType=ins&sp=true&multiSelect=true
from what I've got looks like you can use CSV Data Set Config.
Create .txt file with the data you want to feed your test with;
Place the above .txt file to the folder where your .jmx file lies;
In your Test plan: Under your request sampler - place CSV Data set Config;
Then if you need to use your dynamic values within one threadgroup => refer these data as ${quanity}, ${age} in you url.
If you need to pass these values across the threadgroups => add BeanShell Assertion
Then (in the other Tread group) refer those as ${__property(_quantity)},${__property(_age)}.
Hope, it helps.
First of all you need Beanshell PreProcessor, not Beanshell PostProcessor.
All this parameters are basically name/value pairs which can be defined via HTTPSamplerBase class. HTTPSamplerBase class instance is available to Beanshell PreProcessor as sampler pre-defined variable so if you add the following code into the Beanshell PreProcessor "Script" area
sampler.addEncodedArgument("airports[]","LGW");
sampler.addEncodedArgument("units[]","000577:DESTINATION");
sampler.addEncodedArgument("when","29-05-2016");
sampler.addEncodedArgument("until","");
sampler.addEncodedArgument("flexibility", "true");
sampler.addEncodedArgument("flexibleDays","3");
sampler.addEncodedArgument("noOfAdults","2");
//etc
Your HTTP request will be populated with the values, you set via Beanshell.
JMeter Variables can be accessed via vars shorthand which stands for JMeterVariables class instance.
String airport = vars.get("airport");
sampler.addEncodedArgument("airports[]", airport);
//etc
See How to Use BeanShell: JMeter's Favorite Built-in Component article for comprehensive information on how to use Beanshell Test Elements in Jmeter.
Remember that it is recommended to avoid scripting where possible so if there is another way of implementing your task - go for it.

Apache jMeter : Perform load test and delay verification

I would like to perform a load test on a SOAP webservice.
There are two requests :
createDocument. Input: name, size, date. Output: id's document newly created
getDocument. Input: document id. Output: id, name, size, date
I would like to perform a load test on the createDocument method. Not rocket science, I use the SOAP sampler, very simple.
But in a second step, after the load test (for performance reason) I would to check if the document are really created by calling getDocument with the id.
My idea :
Create a Thread Group for the SOAP sampler
On the Thread Group, add a postprocessor Beanshell
in the postprocessor, store the document id in a Java list
Create an other Thread Group for the verification
In the Test Plan, check "Run Thread Groups consecutively"
In the verification Thread find a way to loop the Java list
For each id, perform a SOAP call
I don't know how to loop over a Java list and call a SOAP sampler for each iteration. Any idea ?
Or generally, do you have a solution more jMeter compliant ?
Thank you
In the second thread group:
Add a Beanshell Sampler which will iterate through the list with document IDs and store them into JMeter Variables, something like:
List IDs = bsh.shared.IDs;
int counter = 1;
for (String ID : IDs){
vars.put("ID_" + counter,ID);
counter++;
}
This will result in variables like:
ID_1=somedocumentid
ID_2=someotherdocumentid
....
etc.
Add a ForEach Controller and configure it as follows:
Input Variable Prefix: ID
Output Variable Name: anything meaningful, i.e. CURRENT_ID
Make sure that "Add "_" before number" is checked
ForEach Controller will iterate through all defined variables with ID_ prefix and you will be able to refer the current value as ${CURRENT_ID}
Reference material:
Sharing Variables chapter of JMeter's User Manual Best Practices
How to use BeanShell: JMeter's favorite built-in component guide
ForEach Controller documentation entry

Resources