Jmeter - Inline evaluation error in Beanshell Assertion

V.Bhanderi

I am getting this error, and cannot figure out what wrong I am doing:

Error invoking bsh method: eval In file: inline evaluation of: ``import java.util.Set; import java.util.Map; import java.util.List;  try { //   Map . . . '' Encountered "String" at line 17, column 9.

This is the code that I am using:

import java.util.Set;
import java.util.Map;
import java.util.List;

try
{
//  Map<String,List<String>> map = new HashMap<String,List<String>>();

//  map = vars.getObject("headerMap");
    boolean isHeaderValid = false;
    
//  String apiKeySent = "${x_api_key}"
//  String clientIdSent = "${X_IBM_Client_id}"
//  String clientSecretSent = "${X_IBM_Client_Secret}"

    String apiKeySent = vars.get("x_api_key")
    String clientIdSent = vars.get("X_Client_id")
    String clientSecretSent = vars.get("X_Client_Secret")

    log.info("apiKeySent: " + vars.get("x_api_key"))
    log.info("clientIdSent: " + vars.get("X_Client_id"))
    log.info("clientSecretSent: " + vars.get("X_Client_Secret"))
    
    if(apiKeySent != "")
    {
        apiKeyRec = vars.get("apiKeyRec")
        isHeaderValid = apiKeySent.equals(apiKeyRec)
    }
    Failure = isHeaderValid
}
catch(Exception e)
{
    log.debug("Error in verification: ",e)
}

Could anyone please help me in figuring this out? Have been stuck at this for ages.

Dmitri T
  1. You need to add semicolons like this

    import java.util.Set;
    import java.util.Map;
    import java.util.List;
    
    try
    {
    //  Map<String,List<String>> map = new HashMap<String,List<String>>();
    
    //  map = vars.getObject("headerMap");
        boolean isHeaderValid = false;
    
    //  String apiKeySent = "${x_api_key}"
    //  String clientIdSent = "${X_IBM_Client_id}"
    //  String clientSecretSent = "${X_IBM_Client_Secret}"
    
        String apiKeySent = vars.get("x_api_key");
        String clientIdSent = vars.get("X_Client_id");
        String clientSecretSent = vars.get("X_Client_Secret");
    
        log.info("apiKeySent: " + vars.get("x_api_key"));
        log.info("clientIdSent: " + vars.get("X_Client_id"));
        log.info("clientSecretSent: " + vars.get("X_Client_Secret"));
    
        if(apiKeySent != "")
        {
            apiKeyRec = vars.get("apiKeyRec");
            isHeaderValid = apiKeySent.equals(apiKeyRec);
        }
        Failure = isHeaderValid;
    }
    catch(Exception e)
    {
        log.debug("Error in verification: ",e);
    }
    
  2. Since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language for scripting so consider migrating to JSR223 Assertion and Groovy

  3. Your script can be simplified to

    AssertionResult.setFailure(vars.get('x_api_key') == vars.get('apiKeyRec'))
    
  4. And you don't even need any scripting for comparing 2 variables, it can be done using "normal" Response Assertion

    enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

JMeter BeanShell Assertion: Getting error when convert String to Long

Beanshell type of variable assertion on Jmeter

JMeter Beanshell Integer Error

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

Unable to append to next line in a file through beanshell assertion sampler in Jmeter

Jmeter BeanShell assertion parsing and comparing UTC datetime from json

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

Error in Beanshell Sampler JMeter for parsing RegularExpressionExtractor

Error on accessing Output Variable in beanshell preprocessor in Jmeter

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

JMeter Assertion : Error when comparing variables

JMeter / Beanshell "Error invoking bsh method: eval Sourced file:"

Jmeter and global Beanshell variables

Update Jmeter variables with beanshell

Jmeter. BeanShell PostProcessor

Jmeter beanshell Post Processor

JMeter simple BeanShell PreProcessor

JMeter BeanShell - integer to string

Jmeter beanshell Encounter ";"

Calling class in Jmeter Beanshell

jmeter beanshell pre processor

XPath JMeter Assertion : Error "prefix must resolve to a namespace"

: Error invoking bsh method: eval Sourced file: inline evaluation of: ``

JMeter BeanShell - Loop through values

Jmeter: Where beanshell result is printed

Use of Beanshell Preprocessor for Parameterization in JMeter

JMeter beanshell string comparison issue

JMeter Beanshell share class definitions

Stop JMeter test in Beanshell PreProcessor