I have several samplers in a thread group, each retrieving a piece of information. I then need to validate the consistency of the results from two different samplers. In particular I need to assert whether a field in one sampler response equals a field in the JDBC response. What is the best way to do something like that?
I have thought about adding a beanshell postprocessor to each sampler in order to extract the field value from each sample and save it in two variables and then adding a beanshell assertion that accesses those variables, but I wonder if there is a more direct approach.
In the JMeter API documentation I could not see anything to access another sampler response other than the previous one.
I posted the same question on the Jmeter user mailing list and from the feedback I got it seems that indeed it is not possible to access the result of another sampler than the previous one.
The answer is then to save each sampler response in a variable via a postprocessor so that it can be used later.
Related
I am new to jMeter so hope you can help me out.
I have a thread group with several HTTP request samplers. I am sending an email every time any sampler fails. The thing is I would like to collect the names + response bodies of the several failed samplers to send in the email.
Can anybody please give an example of how to do it?
The best solution would be using Simple Data Writer listener configured to save only failed requests, there you can choose whatever metrics you need to store:
Another option is using JSR223 test elements and Groovy language to extract the "interesting" fields from the failed requests:
in the above example the sampler gets the label and the body from the previous result and stores them into ${requestName} and ${responseData} JMeter Variables which you can use wherever you want. More information on these prev, vars and other JMeter API shorthands: Top 8 JMeter Java Classes You Should Be Using with Groovy
I am trying to remove response time and samplers from my Jmeter results in summary report. I know we can do it with help of Filter Result options, but it just removes the label or samplers and it still shows the and adds up its response time. But suppose I have bunch of samplers in a transaction controller and I want to remove or ignore the response time of some of samplers (I can not disable them, I have send them I just don't want to consider their response time) then how should I do it? is there a way?
I don't believe there is an easy way of excluding Transaction Controller's children from the .jtl file.
You can visualize the results using i.e. BM.Sense analysis solution, in Composite Timeline Analysis panel you have the possibility to choose which sampler(s) to display so you can filter out the results you're not interested in
If your goal is to execute the request but not to display it in the results you can add a JSR223 PostProcessor as a child of the request you would like to omit and put the following code into "Script" area:
prev.setIgnore()
This way the sampler(s) in the JSR223 PostProcessor's scope will be excluded from any form of reports:
Here is my scenario:
I created a test fragment for a sampler which is being used in many thread groups present in different jmx scripts. I sometimes would like to extract few values of this sampler result using few post processors.
Question:
How do I group and make these post processors reusable? I do not want to include as part of the test fragment itself as I don't need/want to execute post processor action every time.
Here is what I have tried:
I am able to save those post processors as a separate test fragment and include it in my test script right after the test fragment with the sampler whenever I want to execute them. I can save the sampler result to a jmeter variable and use it inside my post processor test fragment.
Is this a good approach? Please guide me.
Having Post-Procesors at the same level as all other Samplers is not a very good idea as they will be executed for each Sampler in their scope
Saving response data into a variable each time is also an overhead as according to your question you need the value sometimes
I would recommend using JSR223 Sampler to copy previous sampler response data and apply necessary Post-Processor(s) to it as child(ren).
The relevant code to copy the previous sampler response data would be as simple as:
SampleResult.setResponseData(ctx.getPreviousResult().getResponseData())
Where:
SampleResult - stands for current SampleResult
ctx - stands for JMeterContext
Check out Apache Groovy - Why and How You Should Use It article to learn more about Groovy scripting in JMeter conctept
The JSR223 Sampler can be saved as a Test Fragment as well.
Adding to #Dmitri T answer, in JSR PostProcessor you can save similar code in script file and reuse it
Script file A file containing the script to run, if a relative file path is used, then it will be relative to directory referenced by "user.dir" System property
Use the same script file in several post processors for re-usability:
I have jmeter script contains five transactions of which one transaction contains more than one dynamic values. And I want to know how to decide which value to fetch in order to pass it to further transaction?
You need to fetch those values which are required.
Record your scenario 2 times
Inspect request details using View Results Tree listener
Find request parameters (they may be in the request headers as well) which are different between 2 recordings
These are the dynamic parameters you need to correlate (extract from the previous response and pass to the next request)
Alternatively you can use a cloud-based JMeter scripts recording solution which is capable of exporting recorded scripts in "SmartJMX" mode with automatic correlation of all dynamic parameters so you won't have to worry about it. Check out How to Cut Your JMeter Scripting Time by 80% guide for details.
My script structure looks like that:
Transaction Controller SEARCHING OFFERS Transaction
http request offers
http request offers details
Beanshell PostProcessor
Which BeanShell command let me to get name, response code, response time, test result and test time for whole transaction?
Where I should attach BeanShell PostProcessor?
Which code I should use, but in my opinion
String name = sampler.getName();
doesn't work correctly for me.
IMO you should be using BeanShell Listener instead of Beanshell PostProcessor. Listener can be at the same place where your current Beanshell PostProcessor is. That object has access to sampleResult, which would contain response code / response time / etc, for example:
sampleResult.getSampleLabel(); // the name, e.g. 'SEARCHING OFFERS Transaction'
Full list of SampleResult functions is here
If you only want to process transactions in this listener, you could filter them (e.g. by name).