Step 1 :- If the user want to generate random number or word use the following code and save in "Test.js" and save it in on the disk
Selenium.prototype.doRandomString = function( options, varName ) {
var length = 8;
var type = 'alphanumeric';
var o = options.split( '|' );
for ( var i = 0 ; i < 2 ; i ++ ) {
if ( o[i] && o[i].match( /^\d+$/ ) )
length = o[i];
if ( o[i] && o[i].match( /^(?:alpha)?(?:numeric)?$/ ) )
type = o[i];
}
switch( type ) {
case 'alpha' : storedVars[ varName ] = randomAlpha( length ); break;
case 'numeric' : storedVars[ varName ] = randomNumeric( length ); break;
case 'alphanumeric' : storedVars[ varName ] = randomAlphaNumeric( length ); break;
default : storedVars[ varName ] = randomAlphaNumeric( length );
};
};
function randomNumeric ( length ) {
return generateRandomString( length, '0123456789'.split( '' ) );
}
function randomAlpha ( length ) {
var alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split( '' );
return generateRandomString( length, alpha );
}
function randomAlphaNumeric ( length ) {
var alphanumeric = '01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split( '' );
return generateRandomString( length, alphanumeric );
}
function generateRandomString( length, chars ) {
var string = '';
for ( var i = 0 ; i < length ; i++ )
string += chars[ Math.floor( Math.random() * chars.length ) ];
return string;
}
Step 2 :- Open Selenium IDE from mozilla Firefox
Step 3 :- Goto Option and click on options and add your javascript path in user-extension section and submit it
Step 4 :- Close the Selenium IDE and restart the selenium IDE
Step 5 :- Now use the following code
RandomString||8|alphanumeric||Variable_name
Step 6 :- if you want to write in text box that value use the following code
Type||element_name||${Variable_name}
note: if you modify javascript while selenium IDE is open please close and restart the IDE to get the effect
if any query please mail it to
Akshah2688@gmail.com
Just an fyi when using this, it seems Selenium IDE is now case specific on functions, so you have to use:
ReplyDeleterandomString||8|alphanumeric||Variable_name
vs
RandomString||8|alphanumeric||Variable_name
Beautiful...Using it well now..Thanks a lot..
ReplyDelete