This is a migrated thread and some comments may be shown as answers.

Generate text input

6 Answers 181 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mathias
Top achievements
Rank 1
Mathias asked on 12 Feb 2013, 10:26 AM
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.

6 Answers, 1 is accepted

Sort by
0
Accepted
Plamen
Telerik team
answered on 13 Feb 2013, 04:55 PM
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
0
Mathias
Top achievements
Rank 1
answered on 14 Feb 2013, 11:23 AM
Hi Plamen

Many thanks - this solved my problem!

Regards

Mathias
0
Matthew
Top achievements
Rank 1
answered on 02 Jun 2016, 05:15 PM

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?

0
Ivaylo
Telerik team
answered on 07 Jun 2016, 11:44 AM
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!
0
Matthew
Top achievements
Rank 1
answered on 07 Jun 2016, 12:27 PM
Great, thank you Ivaylo!
0
Ivaylo
Telerik team
answered on 09 Jun 2016, 08:24 AM
Hello,

You are most welcome.

Regards,
Ivaylo
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Mathias
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Mathias
Top achievements
Rank 1
Matthew
Top achievements
Rank 1
Ivaylo
Telerik team
Share this question
or