You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by rajan gupta <ra...@gmail.com> on 2012/01/26 04:45:48 UTC
Setting random string in a text field
Hi
I need to set a field with a random string. How can I tell JMeter to put
the random string in a field instead of a static value.
Please let me know.
I have a function which generates random string as shown below.
function randomString() {
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 8;
var randomstring = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
return randomstring;
}
Thanks
Rajan
Re: Setting random string in a text field
Posted by rajan gupta <ra...@gmail.com>.
This worked for me..
Thanks ZK
On Thu, Jan 26, 2012 at 2:43 AM, ZK <st...@gmail.com> wrote:
> Hi,
> you could use this JAVA code in a beanshell PreProcessor:
> //code start
> import java.util.Random;
>
> chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
> int string_length = 8;
> randomstring ="";
> for (int i=0; i<string_length; i++) {
> Random randomGenerator = new Random();
> int randomInt = randomGenerator.nextInt(chars.length());
> randomstring += chars.substring(randomInt,randomInt+1);
> }
>
> vars.put("yourValue",randomstring);
> //code end
>
>
>
>
> The above code creates a random string and outputs to the variable
> yourValue
> This can be accessed in the normal way by using:
> ${yourValue}
>
>
> HTH
> ZK
>
> --
> View this message in context:
> http://jmeter.512774.n5.nabble.com/Setting-random-string-in-a-text-field-tp5432039p5432410.html
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>
>
Re: Setting random string in a text field
Posted by Philippe Mouawad <ph...@gmail.com>.
Hello,
You probably didn't install correctly the nightly build.
Get it here:
https://builds.apache.org/job/JMeter-trunk/lastSuccessfulBuild/artifact/trunk/dist/
Then follow this:
http://jmeter.apache.org/nightly.html
Installing JMeter runtime Download the _bin and _lib files
Unpack the archives into the same directory structure
The other archives are not needed to run JMeter.
You must not mix and old with a new version
Regards
Philippe
On Thu, Jan 26, 2012 at 5:37 PM, rajan gupta <ra...@gmail.com>wrote:
> Hi Philippe
>
> Running nightly build gives me this exception:
> C:\apache-jmeter-r1196526\bin>jmeter
> java.lang.NoClassDefFoundError:
> com/thoughtworks/xstream/converters/ConversionEx
> ception
> at java.lang.Class.getDeclaredConstructors0(Native Method)
> at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
> at java.lang.Class.getConstructor0(Unknown Source)
> at java.lang.Class.newInstance0(Unknown Source)
> at java.lang.Class.newInstance(Unknown Source)
> at org.apache.jmeter.NewDriver.main(NewDriver.java:207)
> Caused by: java.lang.ClassNotFoundException:
> com.thoughtworks.xstream.converters
> .ConversionException
> at java.net.URLClassLoader$1.run(Unknown Source)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(Unknown Source)
> at java.lang.ClassLoader.loadClass(Unknown Source)
> at java.lang.ClassLoader.loadClass(Unknown Source)
> ... 6 more
> JMeter home directory was detected as: C:\apache-jmeter-r1196526
>
> Thanks
>
>
> On Thu, Jan 26, 2012 at 2:50 AM, Philippe Mouawad <
> philippe.mouawad@gmail.com> wrote:
>
> > Note that if you use latest nightly build that will be very close to next
> > 2.6 release , you have a new function __RandomString
> > with 3 parameters:
> > - String length
> > - Chars to use in generation
> > - Name of variable if you want to store result in a variable.
> >
> > Regards
> > Philippe
> >
> > On Thu, Jan 26, 2012 at 10:43 AM, ZK <st...@gmail.com> wrote:
> >
> > > Hi,
> > > you could use this JAVA code in a beanshell PreProcessor:
> > > //code start
> > > import java.util.Random;
> > >
> > > chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
> > > int string_length = 8;
> > > randomstring ="";
> > > for (int i=0; i<string_length; i++) {
> > > Random randomGenerator = new Random();
> > > int randomInt = randomGenerator.nextInt(chars.length());
> > > randomstring += chars.substring(randomInt,randomInt+1);
> > > }
> > >
> > > vars.put("yourValue",randomstring);
> > > //code end
> > >
> > >
> > >
> > >
> > > The above code creates a random string and outputs to the variable
> > > yourValue
> > > This can be accessed in the normal way by using:
> > > ${yourValue}
> > >
> > >
> > > HTH
> > > ZK
> > >
> > > --
> > > View this message in context:
> > >
> >
> http://jmeter.512774.n5.nabble.com/Setting-random-string-in-a-text-field-tp5432039p5432410.html
> > > Sent from the JMeter - User mailing list archive at Nabble.com.
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> > > For additional commands, e-mail: user-help@jmeter.apache.org
> > >
> > >
> >
> >
> > --
> > Cordialement.
> > Philippe Mouawad.
> >
>
--
Cordialement.
Philippe Mouawad.
Re: Setting random string in a text field
Posted by rajan gupta <ra...@gmail.com>.
Hi Philippe
Running nightly build gives me this exception:
C:\apache-jmeter-r1196526\bin>jmeter
java.lang.NoClassDefFoundError:
com/thoughtworks/xstream/converters/ConversionEx
ception
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.apache.jmeter.NewDriver.main(NewDriver.java:207)
Caused by: java.lang.ClassNotFoundException:
com.thoughtworks.xstream.converters
.ConversionException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
JMeter home directory was detected as: C:\apache-jmeter-r1196526
Thanks
On Thu, Jan 26, 2012 at 2:50 AM, Philippe Mouawad <
philippe.mouawad@gmail.com> wrote:
> Note that if you use latest nightly build that will be very close to next
> 2.6 release , you have a new function __RandomString
> with 3 parameters:
> - String length
> - Chars to use in generation
> - Name of variable if you want to store result in a variable.
>
> Regards
> Philippe
>
> On Thu, Jan 26, 2012 at 10:43 AM, ZK <st...@gmail.com> wrote:
>
> > Hi,
> > you could use this JAVA code in a beanshell PreProcessor:
> > //code start
> > import java.util.Random;
> >
> > chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
> > int string_length = 8;
> > randomstring ="";
> > for (int i=0; i<string_length; i++) {
> > Random randomGenerator = new Random();
> > int randomInt = randomGenerator.nextInt(chars.length());
> > randomstring += chars.substring(randomInt,randomInt+1);
> > }
> >
> > vars.put("yourValue",randomstring);
> > //code end
> >
> >
> >
> >
> > The above code creates a random string and outputs to the variable
> > yourValue
> > This can be accessed in the normal way by using:
> > ${yourValue}
> >
> >
> > HTH
> > ZK
> >
> > --
> > View this message in context:
> >
> http://jmeter.512774.n5.nabble.com/Setting-random-string-in-a-text-field-tp5432039p5432410.html
> > Sent from the JMeter - User mailing list archive at Nabble.com.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> > For additional commands, e-mail: user-help@jmeter.apache.org
> >
> >
>
>
> --
> Cordialement.
> Philippe Mouawad.
>
Re: Setting random string in a text field
Posted by Philippe Mouawad <ph...@gmail.com>.
Note that if you use latest nightly build that will be very close to next
2.6 release , you have a new function __RandomString
with 3 parameters:
- String length
- Chars to use in generation
- Name of variable if you want to store result in a variable.
Regards
Philippe
On Thu, Jan 26, 2012 at 10:43 AM, ZK <st...@gmail.com> wrote:
> Hi,
> you could use this JAVA code in a beanshell PreProcessor:
> //code start
> import java.util.Random;
>
> chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
> int string_length = 8;
> randomstring ="";
> for (int i=0; i<string_length; i++) {
> Random randomGenerator = new Random();
> int randomInt = randomGenerator.nextInt(chars.length());
> randomstring += chars.substring(randomInt,randomInt+1);
> }
>
> vars.put("yourValue",randomstring);
> //code end
>
>
>
>
> The above code creates a random string and outputs to the variable
> yourValue
> This can be accessed in the normal way by using:
> ${yourValue}
>
>
> HTH
> ZK
>
> --
> View this message in context:
> http://jmeter.512774.n5.nabble.com/Setting-random-string-in-a-text-field-tp5432039p5432410.html
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>
>
--
Cordialement.
Philippe Mouawad.
Re: Setting random string in a text field
Posted by ZK <st...@gmail.com>.
Hi,
you could use this JAVA code in a beanshell PreProcessor:
//code start
import java.util.Random;
chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
int string_length = 8;
randomstring ="";
for (int i=0; i<string_length; i++) {
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(chars.length());
randomstring += chars.substring(randomInt,randomInt+1);
}
vars.put("yourValue",randomstring);
//code end
The above code creates a random string and outputs to the variable yourValue
This can be accessed in the normal way by using:
${yourValue}
HTH
ZK
--
View this message in context: http://jmeter.512774.n5.nabble.com/Setting-random-string-in-a-text-field-tp5432039p5432410.html
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org