Skip to main content

Random Alpha Numeric Characters

DevAssure provides a features called Advanced Code Blocks which allows users to write custom JavaScript code to generate dynamic data. This feature can be used to generate random alphanumeric strings that can be utilized in various scenarios such as creating unique usernames, passwords, or identifiers during test automation.

Learn more about Advanced Code Blocks

Here's the sample code to generate a random alphanumeric string of a specified length:

const chars = 'abcdefghijklmnopqrstuvwxyz1234567890';
const generateRandomString = (length) => {
return Array.from({ length }, () => chars[Math.floor(Math.random() * chars.length)]).join('');
};
const randomString = generateRandomString(countOfChars);

The variable randomString will contain a random alphanumeric string of the specified length (countOfChars). You can adjust the countOfChars variable to generate strings of different lengths as needed.

Here's a sample screenshot demonstrating the use of this code in DevAssure:

Generate a Random Alphanumeric String

Here's a sample screenshot of the generated random alphanumeric string being used in a DevAssure automation script:

Sample DevAssure Automation code