Generate text input

7 posts, 1 answers
  1. Mathias
    Mathias avatar
    3 posts
    Member since:
    Feb 2013

    Posted 12 Feb 2013 Link to this post

    I am testing an application where users have to enter unique names for entities they create. How can I generate text inputs using timestamps or GUIDs or some other random element to ensure that every automated test creates a new entity with a unique name.

    I have tried binding my tests to a spreadsheet using simple formulas (concatenate predefined text with timestamp). However, these formulas do not seem to get updated when the test is executed and the spreadsheet is read.
  2. Answer
    Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 13 Feb 2013 Link to this post

    Hi Mathias,

    You can generate random strings using the code provided in this article. You can also append these random strings to an already existing strings to make them unique.

    Another option is to use the DateTime.Now property which gets the current date and time, and append it to a value from your database. Then set the new value as an Extracted Value to be used later in the test by a Data Bound enter text step. Here's a sample coded step:
    public void WebTest1_CodedStep()
    {
    SetExtractedValue("UniqueName", Data["Col1"].ToString() + " " + System.DateTime.Now.ToString());
    }

    See this short video demonstrating the above code in action.

    All the best,
    Plamen
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  3. Mathias
    Mathias avatar
    3 posts
    Member since:
    Feb 2013

    Posted 14 Feb 2013 Link to this post

    Hi Plamen

    Many thanks - this solved my problem!

    Regards

    Mathias
  4. Matthew
    Matthew avatar
    10 posts
    Member since:
    Oct 2015

    Posted 02 Jun in reply to Plamen Link to this post

    This is great, thank you! 

    Is there a way I can store that value for reference in a future test step?.  E.g. if I'm creating an item that requires a unique name using a generated SystemDateTime.Now.ToString()  appended and in a later verification step I want to find that name?

  5. Ivaylo
    Admin
    Ivaylo avatar
    750 posts

    Posted 07 Jun Link to this post

    Hello Matthew,

    Yes, you can use get/set extracted variable as shown in this article.

    Regards,
    Ivaylo
    Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  6. Matthew
    Matthew avatar
    10 posts
    Member since:
    Oct 2015

    Posted 07 Jun in reply to Ivaylo Link to this post

    Great, thank you Ivaylo!
  7. Ivaylo
    Admin
    Ivaylo avatar
    750 posts

    Posted 09 Jun Link to this post

    Hello,

    You are most welcome.

    Regards,
    Ivaylo
    Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
Back to Top