Home > Selenium > Generates a random alphanumeric string using JavaScript Selenium IDE

Generates a random alphanumeric string using JavaScript Selenium IDE

Selenium.prototype.doRandomAlphaNumeric = function( length, varName ) {
var valida = “abcdefghijklmnopqrstuvwxyz”;
var validn = “0123456789”;
var npwd = “”;
var pick = 0;
for ( var i = 0 ; i < length ; i++)
{
/* this is to pick alpha or number 0=a 1=n*/
if(Math.floor(2*Math.random()))
{
/* this is to pick a random character */
pick = Math.floor(26*Math.random());
if(Math.floor(2*Math.random()))
npwd = npwd + valida.substring(pick,pick+1).toUpperCase();
else
npwd = npwd + valida.substring(pick,pick+1);
}
else
{
/* this is to pick a random number */
pick = Math.floor(10*Math.random());
npwd = npwd + validn.substring(pick,pick+1);
}
}
storedVars[ varName ] =  npwd;
};
Advertisements
Categories: Selenium
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: