Hi sebb
not able to run the code  in beanshell preprocessor  and pass the result to
the request .

can u pls help me how to include this below code in beanshell preprocessor
and how to pass this variable to the request it will help me a lot.

import static java.lang.Math.round;
>  import static java.lang.Math.random;
>  import static java.lang.Math.pow;
>  import static java.lang.Math.abs;
>  import static java.lang.Math.min;
>  import static org.apache.commons.lang.StringUtils.leftPad;
>  import java.util.*;
>
>  public class RandomAlphaNum {
>
>  static Random rnd = new Random();
>   public static String gen(int length) {
>     StringBuffer sb = new StringBuffer();
>     for (int i = length; i > 0; i -= 12) {
>       int n = min(12, abs(i));
>       sb.append(leftPad(Long.toString(round(random() * pow(36, n)), 36),
n,
>  '0'));
>     }
>     return sb.toString();
>   }
>
>  public static void main(String ar[])
>  {
>   String str = RandomAlphaNum.gen(2);
>   System.out.println(str);
>
>  }

Remove main() entirely.

vars.put("VARNAME",RandomAlphaNum.gen(2));



thanks & regards


On 8/17/09, sebb <[email protected]> wrote:
>
> On 17/08/2009, sudheer reddy <[email protected]> wrote:
> > Hi All
> >
> >   I am trying to generate alphanumeric characters IN Jmeter and pass this
> to
> >  a http request in my test .
> >
> >  I have created a HTTP request and added beanshell preprocessor as a
> child to
> >  thiis .
>
> It would be a lot more efficient to generate the strings before
> running the test; store them in a file and use CVS Dataset to read
> them.
>
> >  Can anyone assist me how to  work with the below code in beanshell
> >  preprocessor  and  send the value from the code to http request.
>
> It would probably be easiest to have the Pre-Processor code set some
> variables that are used in the sampler. It's a lot harder setting the
> sampler directly.
>
> >  For this i have wriiten a code in  Java   and the code is as follows
> >
> >
> >  import static java.lang.Math.round;
> >  import static java.lang.Math.random;
> >  import static java.lang.Math.pow;
> >  import static java.lang.Math.abs;
> >  import static java.lang.Math.min;
> >  import static org.apache.commons.lang.StringUtils.leftPad;
> >  import java.util.*;
> >
> >  public class RandomAlphaNum {
> >
> >  static Random rnd = new Random();
> >   public static String gen(int length) {
> >     StringBuffer sb = new StringBuffer();
> >     for (int i = length; i > 0; i -= 12) {
> >       int n = min(12, abs(i));
> >       sb.append(leftPad(Long.toString(round(random() * pow(36, n)), 36),
> n,
> >  '0'));
> >     }
> >     return sb.toString();
> >   }
> >
> >  public static void main(String ar[])
> >  {
> >   String str = RandomAlphaNum.gen(2);
> >   System.out.println(str);
> >
> >  }
>
> Remove main() entirely.
>
> vars.put("VARNAME",RandomAlphaNum.gen(2));
>
> >  }
> >   Thanks in advance
> >
> >  rgds
> >
> > Sudheer
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to