How to access data inside foreach controller using JSR223 sampler with index value. For example
data_1 = something
data_2 = something
etc.
Whenever I tried using counter, it gives only data_1 for every count but in treeview I see that counter is working properly. How can I access every item in foreach controller.
What "data" do you want to access?
If you configure ForEach Controller like:
then you will be able to get the current value of foo variable as:
vars.get('foo')
Current iteration of the ForEach Controller can be accessed as:
vars.get('__jm__your-foreach-controller-name-here__idx')
if you haven't changed the default name it would be:
vars.get('__jm__ForEach Controller__idx')
Where vars is a shorthand for JMeterVariables class instance, see Top 8 JMeter Java Classes You Should Be Using with Groovy article for more details on this and other JMeter API shorthands.
Jus for you reference, I have completed my task as mentioned in below URL (which is my question) using approach 2.
Foreach controller not working for Json data
Now I am able to get every each json object inside the json array using foreach controller. Now here is the issue, when I log.info(json), I get the same data very time but there are other data as well which can only be seen in treeview.
I dont understand that how do I access all the data.
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},)}
I have written a regular expression inorder to get all the values. Now i have all the values. I want to use the extracted values in a sampler under a loop controller and every hit it has to pic dynamic value.
This will have the dynamic values around 78
I want to Iterate 78 times
Every hit this has to pic unique data
Please help me as i am stuck here to complete the script.
The most suitable test element is ForEach Controller
Given the following variables defined:
Just add a ForEach Controller and configure it as follows:
That's it, you should be able to access each and every match as ${someVar} where required
check out Using Regular Expressions in JMeter article for example use case
If you want to keep the current setup with the Loop Controller - you can refer each and every variable using __V() and __intSum() functions combination like:
${__V(_Webp_${__intSum(${__jm__Loop Controller__idx},1,)},)}
Usecase :- I have one thread group. Inside this i have one loop controller. In loop controller i have 120 transaction controller. During debugging of the script it creates confusion to find the failed steps. I want to put some variable for dynamic number generation. I did it by using Beanshell Sampler as following:
After this i used beanshell function ${__BeanShell(Integer.parseInt(vars.get("POC_Step_Number"))+1,POC_Step_Number)} inside the name of transaction controller. It works for me.
I want to use variable name in place of Beanshell function ${__BeanShell(Integer.parseInt(vars.get("POC_Step_Number"))+1,POC_Step_Number)} function. How can i do that?
You can use loop controller index (add +1 if you want to start with 1)
${__groovy(${__jm__Loop Controller__idx}+1)}
JMeter will expose the looping index as a variable named jm__idx. So for example, if your Loop Controller is named LC, then you can access the looping index through ${__jm__LC__idx}. Index starts at 0
Looping test occurrence based on the data count retrieved from the JDBC request and also as input data for the HTTP request
I have test scenario where i need to use the DB output as the input criteria for the HTTP request. Based on the DB output count( from the first request) i need to loop the HTTP request and it data accordingly
I tried the logical Loop Count by passing the count variable from run time as ${TEST_ID_#}, still its not working.
I tried the logical Loop Count by passing the count variable from run time as ${TEST_ID_#}, still its not working.
Debug Sampler Output
You can extract the counter using Post Processor [either Regular Expression Extractor or JSON Extractor etc.]
Once you have extracted that count, now place a Loop controller as a parent of HTTP request.
For example. I am using User Defined Variable for loop Count:
Any reason for using ${TEST_ID_#} variable? If your Debug Sampler screenshot is full and correct you should be using ${KEY_ID_#} instead.
Also it might be a better idea to use ForEach Controller instead of the Loop Controller, the relevant configuration would be something like:
References:
How to Use ForEach Controller in JMeter
Using Regular Expressions in JMeter
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