JMeter – BeanShell Assertion

JMeter - BeanShell Assertion

BeanShell Assertion is a scripting-based Assertion element of JMeter. It means that you need to implement the assertion logic by yourself using one of the supported scripting languages. Usually, it is helpful when you need to define assertion or validation logic based on your requirement and want to write some unique algorithm which is not currently provided by JMeter. You can create your own implementation of the algorithm using BeanShell Assertion.

How to add ‘BeanShell Assertion’?

You can follow the below steps:

  1. Select the ‘Sampler’ element whose response needs to be validated
  2. Right-click on the sampler element
  3. Hover the cursor on ‘Add’
  4. Hover the cursor on ‘Assertions’
  5. Click ‘BeanShell Assertion’
JMeter - BeanShell Assertion
Figure 01: JMeter BeanShell Assertion

Input Fields:

‘BeanShell Assertion’ has the following input fields:

  1. Name: To provide the name of the timer
  2. Comments: To provide arbitrary comments (if any)
  3. Reset bsh.Interpreter before each call: Interpreter will be recreated by selecting the value of this option as ‘Yes’. 
  4. Parameters: Parameters to pass to the BeanShell script. This is an optional attribute.  
  5. Script file: A file containing the BeanShell script to run. The return value is used as an assertion output generated by BeanShell script.
  6. Script: The BeanShell script which contains the assertion logic.

Leave a Reply

Your email address will not be published. Required fields are marked *