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.
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
0
Accepted
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:
See this short video demonstrating the above code in action.
All the best,
Plamen
the Telerik team
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
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
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
Hello Matthew,
Yes, you can use get/set extracted variable as shown in this article.
Regards,
Ivaylo
Telerik
Yes, you can use get/set extracted variable as shown in this article.
Regards,
Ivaylo
Telerik
0
Matthew
Top achievements
Rank 1
answered on 07 Jun 2016, 12:27 PM
Great, thank you Ivaylo!
0
Hello,
You are most welcome.
Regards,
Ivaylo
Telerik
You are most welcome.
Regards,
Ivaylo
Telerik