Pages

Generate Random Alpha Numeric Characters in protractor

Protractor Generate Random Alpha Numeric Characters ?


In Protractor, we can generate random alpha numeric characters using Math.random().
We can also use for Javascript code.

describe('Generate Random Alpha Numeric Characters', function () {
it('Code script for Generate Random Alpha Numeric Characters', function () {
var randomAlphaNumericCharacters = getRandomAlphaNumericCharacters(10);
console.log("Generated alphaNumericCharacter=" + randomAlphaNumericCharacters);
});

function getRandomAlphaNumericCharacters(length) {
var result = '';
var characters = "ABCDEFghijklmnopqrstuvwxyz1234567890";
var charactersLenght = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLenght));
}
console.log("Random Alpha Numeric characters=" + result);
return result;
}
});
Here, we can generate characters by giving specific length as input to function getRandomAlphaNumericCharacters().
Output:
Protractor generate random alpha numeric characters


Please comment below to feedback or ask questions.

No comments:

Post a Comment

Please comment below to feedback or ask questions.