Jmeter : Error when I try to get data from Database using beanshell assertion

Adithya Balaji

I am trying to extract the results from my JBDC Request sampler using Bean shell assertion

I added a beanshell assertion to my sampler to extract the results and I got an error while running it. The Code in question is :

if (!ResponseCode.equals("200") || vars.getObject("dataFromDB").size() == 0) {

FailureMessage = "!!!!!!!!!!! No connection to the database or data not 
received !!!!!!!!!!!";
Failure = true; 
prev.setStopThread(true):

}    

Where dataFromDB is the result variable name of my JBDC Request Sampler

The Error is : Assertion failure message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval

Dmitri T

There are at least 2 problems with your code:

  1. FailureMessage definition should be at one line or you should concatenate 2 strings on 2 lines
  2. prev.setStopThread(true); should end with the semicolon

Additionally:

  1. Ensure that your vars.getObject("dataFromDB") expression doesn't produce null
  2. Surround your code in try block so if anything goes wrong - you will see the relevant message in jmeter.log file

Assuming all above the suggested fixes would look like:

try {
    if (!ResponseCode.equals("200") || vars.getObject("dataFromDB").size() == 0) {
        FailureMessage = "!!!!!!!!!!! No connection to the database or data notreceived !!!!!!!!!!!";
        Failure = true;
        prev.setStopThread(true);
    }
} catch (Exception ex) {
    log.error("Script failure", ex);
}

Be aware that since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for any form of scripting so consider migrating to JSR223 Assertion, the required code amendments would look like:

if (!prev.getResponseCode().equals("200") || vars.getObject("dataFromDB").size() == 0) {
    AssertionResult.setFailure(true);
    AssertionResult.setFailureMessage("!!!!!!!!!!! No connection to the database or data notreceived !!!!!!!!!!!");
} 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

I am using @PathVariable from springframework. When I try to return view page name from controller, I get 404 error

How to get value from property in BeanShell (jmeter)

When trying to retrieve data from the database I get an error "InvalidOperationException was unhandled"

When I try to echo data from database using php my html page breaked

PHP undefined variable when I try to extract data from database

Jmeter BeanShell assertion parsing and comparing UTC datetime from json

C# datagrid duplicate the columns when I try to get the data from database table

ViewModel return clear object when i try to get data from it

PHP error message when I try to check a value from database

Why do I get an error (Notice: Undefined index) when I try to echo a value from my database?

error when try to insert data into database

I get this error when I try to install

when i want to insert data into mysql using JdbcOdbc Bridge driver, i get no database selected error,

JMeter Beanshell Integer Error

JMeter BeanShell Assertion: Getting error when convert String to Long

error when try to get data from json angular

How to get Sampler Body data from beanshell Pre-Processor - JMeter

i'm getting error whenEver i try to get data from my db using this function(i'm using kotlin with android studio)

When inserting data into the database I get an error

Encountered "=" error in Jmeter when List is used in jmeter beanshell code

Jmeter - Inline evaluation error in Beanshell Assertion

404 ERROR when I try to GET data from google spreadsheet

JMeter: Count comparison of value fetched from Beanshell Postprocessor, using the Beanshell assertion

Beanshell type of variable assertion on Jmeter

Getting an error when I try to parse data to get values from JSON

KOTLIN/FIREBASE Error when I try get data from firebase database - Client is offline

When i try to get data from data for edit page it's showing me error

I try getting data from eBay from sold and auction items using webscraping but for some reason i get a NoneType error

Project freezes when I try to get data from api

TOP Ranking

HotTag

Archive