Ask a Question

LoadNinja - JavaScript Validations Example - Registration Users and Passwords

melgage
Staff

LoadNinja - JavaScript Validations Example - Registration Users and Passwords

LoadNinja offers users different types of validations to use in their load test scripts. The most powerful of those validations is the JavaScript Validation. From our documentation on JavaScript Validations:

Script validations use JavaScript to perform complex checks, such as:

  • Check the presence or absence of specific elements on the page.

  • Check an element’s attributes, such as class or color.

  • Verify the contents of multiple elements at the same time.

  • And more — you can check anything that is in the page’s Document Object Model (DOM).

Script validations look as follows. The code must be inside a function, and this function must return true if the validation passes or false if it fails. The assertion name you specified in LoadNinja becomes the function name.

 

I recently had a customer ask how they could test their registration site with LoadNinja with random usernames and a set password. This can easily be accomplished using a JavaScript Validation. This validation generates a random "20 character"@gmail.com username and drives the same password for each of those users. It's important to remember that LoadNinja activity DOES affect those systems under load test with real world data. My sample script is below and would have to be tailored to the elements as defined on your particular site; "j_idt72:login" for example. I'm populating the username and password fields, and then using the script to perform the click on my registration button as well.

 

function _UserPass() {
// Enter your assertion code below.
// Return true if the assertion passes
// and false otherwise.
// You can acccess documents element normally:
// i.e.: document.getElementsByName("fname");
// Enter your assertion code below.
// Return true if the assertion passes
// and false otherwise.
// You can acccess documents element normally:
// i.e.: document.getElementsByName("fname");
var login = document.getElementsByName("j_idt72:login")[0];
var email = '@gmail.com';
var prefix = '';
var possible = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
var string_length = 20;
for( var i=0; i < string_length; i++ ) prefix = prefix + possible.charAt(Math.floor(Math.random() * possible.length));;
email = prefix + email;
login.value=email;
// Populate the password.
var password = document.getElementsByName("j_idt72:password")[0];
password.value = "password";
//
// Submit the form by "clicking the Sign In" button.
document.getElementById("j_idt72").submit();
return true;
}
// DO NOT CHANGE BEYOND THIS POINT -
return _UserPass();

 

 

For additional information on LoadNinja, visit our support page: LoadNinja Support Page 

Happy Testing!

Mel Gage | Solutions Engineer - Collaborator, LoadNinja
e: Mel.Gage@SmartBear.com
0 REPLIES 0
cancel
Showing results for 
Search instead for 
Did you mean: