Hello Everyone,
In this blog the user will generate current system date using javascript as
Store || javascript{ ((new Date()).getMonth()+1)+'/'+(new Date()).getDate()+'/'+(new Date()).getFullYear()} || Variable_name
will generate the date as MM/DD/YYYY format
you can check it using following code of selenium
echo || ${Variable_name} ||
Following is the screen shot of how to implement the above code
I hope this will help you in automation
If any query please mail it to Akshah2688@gmail.com
Selenium IDE
Monday, December 27, 2010
Friday, December 24, 2010
Random Number Generator Using Selenium IDE
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
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
Subscribe to:
Posts (Atom)