0
votes

Is it possible to loop through a array and select a character from the passwd using the ord[i] value? Code

             String ordinal = vars.get("ordinal");
             String[] ord = ordinal.split(",");
             log.info(ord[0]);

             String passwd = vars.get("password");
             requiredOrd = new ArrayList();
             for(int i=0; i< ord.length; i++)
             {

                    requiredOrd.add((passwd.charAt(ord[i])));

              }

          log.info(requiredOrd[0]); 

Returns error message as follows:

2017-10-23 10:23:26,270 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: String ordinal = vars.get("ordinal"); String[] ord = ordinal.split(","); log.inf . . . '' : Error in method invocation: Method charAt( java.lang.String ) not found in class'java.lang.String' 2017-10-23 10:23:26,270 WARN o.a.j.e.BeanShellPostProcessor: Problem in BeanShell script: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of:String ordinal = vars.get("ordinal"); String[] ord = ordinal.split(","); log.inf . . . '' : Error in method invocation: Method charAt( java.lang.String ) not found in class'java.lang.String'

3
Modified original code and and now include error message - Nobody

3 Answers

0
votes

With Beanshell you can use String method charAt which return character per index.

Index in array start with 0 so change to i = 0 and passwd.length() call:

for(int i=0;i<passwd.length(); i++) {
  log.info(passwd.charAt(i))
0
votes

Since JMeter 3.1 it is recommended to use JSR223 Test Elements and Groovy language for any form of scripting in JMeter so kindly consider switching to Groovy language as:

The relevant code to iterate the String would be something like:

def password = 'foo'
for (char c : password.toCharArray()) {
    log.info('Current char: ' + c)
}

JMeter Groovy Iterate String

0
votes

id_ALL="fbe9ca5c-942b-48d8-9ffd-5f92ae64437a", "4f90ef0f-c317-47ea-9013-53729477c379", "98fe94ae-7e1b-42bb-8c2f-cae0f31105a0", "b3f8ed32-e273-41d8-8caf-2024feeccd8c"

StatusMFP_ALL="true","true","false","false"

StatusIwb_ALL= "true", "false", "false", "true"


String[] ids = {${id_ALL}};

String[] StatusM = {${StatusMFP_ALL}};

String[] StatusI = {${StatusIwb_ALL}};

//To get array length

int count = Integer.parseInt(vars.get("id_matchNr"));
log.info( "countest" + vars.get("id_matchNr"));

ArrayList c = new ArrayList();

    for (int i = 0; i <=count-1; i++)
       {
         String M=StatusM[i];
         String I=StatusI[i];
              if(M=="true" || I=="true" )      
                {                  
                    String x=ids[i];                
                    c.add(x);                                                                                                         
                }      
      }            
        for (int i = 0; i < c.size(); i++) 
        {
              log.info(c.get(i));           
        }
        log.info(c.get(0));