On 18/08/2009, sudheer reddy <[email protected]> wrote:
> 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.

The following sample code can be used by a BSH Pre-processor to set a
variable called VARNAME:

String value="abcd";
vars.put("VARNAME",value);

The variable can then be referenced in the sampler using the sytnax:

${VARNAME}

I suggest you start with that simple example and once that is working,
you can amend the BeanShell code to generate a more useful string.

I still think you would be better off creating a file with the random
data in it.

>
>  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]
>  >
>  >
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to