Forum Discussion

ralyn_sg's avatar
ralyn_sg
Contributor
10 years ago
Solved

Creating a random value for a form that has to be automated

Hi.I am new to Test Complete and need to automate a web application.This application requires me to create a new user with a distinct name each time.In order to do this I have to create distinct and random names each time.Is there any way to do this via parameterization or adding variables in keyword tests?Please suggest.
  • Ralyn,

    To remove the ":" and "/", you can use this instead:

    KeywordTests.Test1.Variables.Var1=aqConvert.DateTimeToFormatStr(aqDateTime.Now(), "%m%d%Y %H%M");



    Also, this page lists the format specifiers so you can adjust it to suit your needs:

    http://support.smartbear.com/viewarticle/59311/

8 Replies

  • brk9394's avatar
    brk9394
    Occasional Contributor
    Ralyn,

    To remove the ":" and "/", you can use this instead:

    KeywordTests.Test1.Variables.Var1=aqConvert.DateTimeToFormatStr(aqDateTime.Now(), "%m%d%Y %H%M");



    Also, this page lists the format specifiers so you can adjust it to suit your needs:

    http://support.smartbear.com/viewarticle/59311/
  • brk9394's avatar
    brk9394
    Occasional Contributor
    If you don't mind having the username look like a timestamp, then you could use Run Code Snippet, and enter: KeywordTests.Test1.Variables.Var1=aqConvert.DateTimeToStr(aqDateTime.Now());



    Then every time the script runs, Var1 will contain a unique value that can be used as the username.
  • Why don't you try something like this:





    function makeRandom()


    {


        var text = "";


        var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";


     


        for( var i=0; i < 5; i++ )


            text += possible.charAt(Math.floor(Math.random() * possible.length));


        Log.Message(text);


            


      //return text;


    }



    If you want the function to return something, just comment out the last section.

     




  • Hi Tanya,



    I checked the link on data generators But I did not find data generator anywhere in my TestComplete tool.





  • Hi Brian,



    Thanks.This is what I was looking for.Giving time would create unique and distinct values but the field that requires unique and distinct values takes only alphanumeric values .When I entered the above date format I got the following value-"12/09/2014 12:18:30 PM".The / and  : are not valid here.Would there be any other option for this?
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)
    Hi Ralyn,

     


    As for Data Generator, you can add the toolbar item manually. For this:


     


    - right-click the Tools toolbar or select Tools | Customize Toolbar from TestComplete’s main menu;


     


    - in the ensuing Customize dialog, switch to the Commands tab;


     


    - on the Categories list, select the Tools category; on the Commands list, select the Generate Data command and drag it to the Tools toolbar or to the Test menu.