1

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.

V.Bhanderi
  • 47
  • 8
  • Does this answer your question? [BeanShell script error: bsh.ParseException: Parse error at line 126, column 23. Encountered: ,](https://stackoverflow.com/questions/66775728/beanshell-script-error-bsh-parseexception-parse-error-at-line-126-column-23) – Ori Marko Jun 09 '21 at 15:09

2 Answers2

1

It looks like you are forgetting to end all of your statements with semicolons from line 12 on. Add semicolons and let me know how that works!

Carter W
  • 55
  • 8
1
  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

Dmitri T
  • 159,985
  • 5
  • 83
  • 133