pranoti's avatar
pranoti
Frequent Visitor
2 years ago
Status:
New Idea

Ability to generate random values at runtime and pass it in as a parameter

Should have an ability to generate random unique values at runtime or append a random value to a variable like "TestUser_<random number / timestamp>", for scenarios such  as username in signup functionality. 

1 Comment

  • Hi pranoti,

     

    Thank you for submitting a feature request. In LoadNinja, it is possible to generate some values at runtime and append them, for example, to a string using JavaScript validations. We can, for example, use a JS validation to access an input field on a page, and fill it with a string generated at runtime. See sample JS validation code below:

    function _InputValue() {
    
      var element = document.getElementById("testInputId");
    
      const months = ["JAN", "FEB", "MAR", 
                      "APR", "MAY", "JUN", 
                      "JUL", "AUG", "SEP", 
                      "OCT", "NOV", "DEC"];
    
      const code = "PRG";
      var dateNow = new Date();
    
      var year = dateNow.getFullYear();
      var month = months[dateNow.getMonth()];
      var day = dateNow.getDate();
    
      var hours = dateNow.getHours();
      var minutes = dateNow.getMinutes();
      var seconds = dateNow.getSeconds();
      
      var miliseconds = dateNow.getMilliseconds();
    
      var textFieldValue = code + year + month + day + 
          hours + minutes + seconds + miliseconds;
    
      if (element){
    
        element.value = "";
        element.value = textFieldValue;
        return true;
      }
      return false;
    
    }
    // DO NOT CHANGE BEYOND THIS POINT -
    return _InputValue();

    This sample code is creating a unique string starting with "PRG" and contains a date generated at runtime. 

     

    See also: Documentation - JavaScript validations for more information.

     

    Best regards,

    Marcin,

    Customer Care Engineer