JMeter BeanShell Listener All Results - jmeter

I'm writing a BeanShell script in JMeter to process the results of the HTTP Requests. I'm able to use the Post-processor to capture these results and process individually however it means adding a Post-processor to every Request.
Is it possible in the BeanShell listener to access all results rather than just the last one which is accessible via the sampleResult, prev variables?

The BeanShell listener fires per request response so by writing the script for it i was able to run it for each http request. Had tried using the Listener before and it didn't work so I tried the post-processor. However it appears it was an issue in my script causing the problem.

Related

Can I call one thread sampler from another thread in Jmeter WebDriver Sampler?

I have just started using Jmeter WebDriver Sampler for automating performance of an application. I'm curious to know that can i call one webdriver sampler from another sampler?.Is it possible in Jmeter. Because I need to login and logout in every sampler.
Theoretically it is possible via JMeter API and JSR223 bridge however it will be too complicated and in general you ain't gonna need it.
There are 2 main points which you might not know:
JMeter executes Samplers upside down so if you have the following structure:
Login Sampler
Logout Sampler
Jmeter first will execute Login than Logout. Browser instance will be shared across the samplers
There is a mechanism in JMeter which helps avoiding code duplication so if you have Logout sampler(s) somewhere in your test plan and would like to re-use it in several places instead of copying and pasting it each time you can call it using Module Controller

Jmeter: Replace data in current sampler from JSR223 pre processor

I need to sign my request xml and add a token to it before hitting the application. For that I am using a JSR223 preprocessor which gets the data from current sampler, makes the necessary changes and puts the data back to sampler. This approach works fine with a single thread group. When multiple thread groups are used data between the samplers(in different thread groups) gets interchanged and it results in incorrect requests for the thread group. Below is the code in my preprocessor:
import jmeter_plugin.*;
String body = sampler.getXmlData();
log.info(body);
Utils utils=new Utils();
String request=utils.getResponse( body,"url/to/fetch/token");
log.info(request);
sampler.setXmlData(request);
Tried by having a single preprocessors for the entire test plan and also separate pre processors for each thread group. Both approaches did not work.
Your approach should work fine no matter how many Thread Groups do you have. Pre-Processors are executed before each sampler in its scope and should modify only the current sampler.
Quick checklist:
Make sure you're using Groovy as JSR223 PreProcessor language
Make sure you have Cache compiled script if available box ticked
Remove these log.info lines as they create unnecessary Disk IO overhead
Make sure your Utils class don't use methods which are not Thread Safe
Looking into sampler.getXmlData() it appears you're using JMeter 3.1 or below as SOAP/XML-RPC Request has been removed in JMeter 3.2 and users are encouraged to use HTTP Request sampler instead.
If your "sign" algorithms is not very exotic if might be easier to use WS Security for SOAP JMeter Plugin which can be installed using JMeter Plugins Manager

Jmeter retry services on failure

I have recorded some services in jmeter. When I run the jmeter, one of the services sometimes receives the parameters from another service(through Json Path Postprocessor) and sometimes it does not. When it does not receive the parameters, it fails. I want my jmeter to retry all the services if a service fails, beginning from start.(Through my research I found that Jmeter retry has been stopped since Jmeter 2.1 and I am using jmeter 3.1).How can I achieve that?
You can run your "services" (whatever it is) in an endless loop via While Controller and exit the loop if all the requests are successful.
There's plugin Retry Post-Processor you can add in your request(s) scope
JMeter plugin provides a Post-Processor that retries failed samples.
Minimum JMeter version 5.0

my jmeter script is running inspite of the application server being shut down

I created a jmeter script for an MSTR application. The server on which this application is hosted was shut down by the Development team but my script is still running successfully.
Why is the script not giving errors??
In case of HTTP Requests JMeter automatically treats all HTTP Status Codes which are less than 400 as successful.
You can consider adding i.e. Response Assertion to ensure that the test is doing what it needs to do and, expected information is present at the page, not expected information is not present, etc. You can also set maximum response time via Duration Assertion, check response for being HTML/XHTML/XML-compliant via HTML Assertion, etc.
See How to Use JMeter Assertions in Three Easy Steps guide for comprehensive information on conditionally failing JMeter samplers using assertions
You are getting an impression that the script is running successfully based on the response code you are receiving. For correctness of the tests, it is advised that you add response assertions to your scripts and add certain text as a pattern which is expected as result of successful response for respective request.
In this case you also need to make sure that you don't add response assertion for each and every request as it can make the JMeter script heavy to execute and JMeter may run out of memory if appropriate memory is not allocated.
Add a response assertion and re-run the test and make practice to use it to validate the correctness of your script.

JMeter - Generating a Summary Report

I've implemented a BeanShell listener in my Jmeter test plan which I use to run a script that sends information after each request into Splunk. However, I'd now like to be able to generate a similar message at the end of each Thread run, regardless of whether or not there was an error in its execution.
At present when an error occurs I start the next thread. I'd like at this stage to be run another BeanShell script where I can collect and send summary inforation for that thread into Splunk before it starts the next Thread. Is this possible?
Your option is to code a class implementing ThreadListener:
http://jmeter.apache.org/api/org/apache/jmeter/testelement/ThreadListener.html
See also this:
http://jmeter.apache.org/extending/jmeter_tutorial.pdf

Resources