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
Related
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},)}
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
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:
My goal is to POST to some URL from every thread in my thread group, which will create an asset somewhere. If all goes right, the first request will create the asset, then subsequent requests will see that the asset is already created (or in the process of being created), and will reuse that same asset.
The test plan:
Create N threads
HTTP Request - POST to some URL
Regular Expression Extractor - extract part of the response (the assetId generated by the POST request)
Verify that every thread extracted the same string from the response
My question:
What I don't have a clue how to do is the last step - verify that the value extracted from each thread is the same. How can this be done in JMeter?
To achieve your requirement, we need to share the value among all the threads.
Properties:
We can use properties to share a value. Lets assume a prop 'shared' is created with default value as blank "". Add the below code in the beanshell assertion. If it is blank, then a thread will add the value extracted from the RegEx. All other threads will just compare the value and if it does not match, it will fail it.
if(props.get("shared")==""){
props.put("shared") = "extracted";
}else{
if(!props.get("shared").equals("extracted")){
Failure = true;
}
}
Bsh.shared:
We can use the bsh.shared shared namespace to share the value among the threads and compare if the all the threads have the same value.
1.setup threadgroup will contain beanshell code like this to create a hashset.
import java.util.*;
if (bsh.shared.hashSet == void){
bsh.shared.hashSet=new HashSet();
}
bsh.shared.hashSet.clear();
2.The regular thread group will contain the code for extracting the value. Once the value is extracted, add it to the hashset which stores only the unique values. Any duplicate values are simply ignored.
bsh.shared.hashSet.add("value extracted");
3.teardown threadgroup will group will check the hashset for the size. If the size is more than 1, then it failed.
log.info(String.valueOf(bsh.shared.hashSet.size()));
I guess you can use Response Assertion.
The test plan:
Create N threads
HTTP Request - POST to some URL
Verify that every request has the same string in the response with Response Assertion
When you place this assertion on the Test plan level it applies to all the threads.
I have to write load tests for web application using JMeter. The application has items available for booking, each item has a 'Book' button. If some user clicks this button for item, it becomes unavailable for other users. My question is:
Is it possible to make JMeter threads to book different items (to make different requests) and how to implement it?
You should be able to determine what parameter is being posted by different "Book" buttons and modify nested requests as needed. Test plan structure should be something like:
Open Booking Page - HTTP Request
Get all Booking IDs - Post Processor
Book - HTTP Request
Where "Post Processor" can be
Regular Expression Extractor
CSS/JQuery Extractor
XPath Extractor
In case of multiple matches Post Processor will return multiple variables like
BookindID_1=some value
BookindID_2=some other value
BookindID_3=some other value 2
....
BookindID_matchNr=10
There are at least 2 options on how to proceed with these values:
Iterate all the values using ForEach Controller
Stick to current virtual thread number via __threadNum function so thread #1 will take BookindID_1 variable, thread #2 - BookingID_2 variable value, etc.
It is also possible to take random value using __Random function but it may result in request failure if item is not available.
The correct way of 2 variables combination looks like:
${__V(VAR1${VAR2})}
So combining BookingID_N and __threadNum will look like
${__V(BookingID_${__threadNum})}
See How to use JMeter Functions post series for more on what can be done via functions.
yes, If every item has static(predefined) unique id,descriptor,identifier then that can be parameterized using a csv config file or random no. generator and selector
Random no generator and selector will work only for integers but csv config is better/standard practice. If you need more help please paste your test plan here with explaination of your need.