Selenium IDE - Generating Random Alpha Numeric Or Numeric String

We already learnt about random number generation and concatenation of random number with other string like email id in Selenium IDE - Generating random number using javascript with example post. Now let me give you few examples for generating random alpha numeric string, generating only random numeric
string of specified length using javascript to use in your test case of your software which you test.

New Test
CommandTargetValue
storejavascript{Math.random().
toString(36).substring(2,12)}
10chrnnum
echo${10chrnnum}
storejavascript{Math.random().
toString(36).substring(2,7)}
5chrnnum
echo${5chrnnum}
storejavascript{Math.random().
toString(9).substring(2,12)}
onlynums
echo${onlynums}
store${10chrnnum}${5chrnnum}15chrnnum
echo${15chrnnum}

Use and run above script in your selenium IDE software window. After test case execution completion, view execution log or use Stored Variables Viewer plugin to see stored variable values.

Random Alpha Numeric String Generation Of 10 Char length
1st "store" command will store random alpha numeric (a to z and 0 to 9) string of 10 character length in variable '10chrnnum' using javascript = javascript{Math.random().toString(36).substring(2,12)}. 
Example : 'u44kvuudlk'

Generating Random Alpha Numeric String Of 5 Char length
In above example test case, 2nd "store" command will execute targeted "javascript{Math.random().toString(36).substring(2,7)}" and store 5 char length random alpha numeric (a to z and 1 to 9) string in variable '5chrnnum'.
Example : 'ow1k5'

Generate only Random Number String Of 10 Char length
3rd "store" command will generate only numeric(0 to 9) string of 10 char length and store in to variable 'onlynums'. Use 'javascript{Math.random().toString(9).substring(2,7)}' to generate 5 char number string. You can customize your string length by changing values in 'substring(2,12)'.
Example : '0467332347'

Generating 15 char length alpha numeric string
4th "store" command will concatenate values of variables '10chrnnum' and '5chrnnum' and store it in variable '15chrnnum'. This way you can create lengthy random alpha numeric or numeric strings if required.
Example : 'u44kvuudlkow1k5'

No comments:

Post a Comment