Need a snippet to create user name randomaly

Class library usage, coding and language questions.
itzikp
Posts: 3
Joined: Tue Apr 30, 2013 11:37 am

Need a snippet to create user name randomaly

Post by itzikp » Mon May 06, 2013 6:29 am

Hi

I'm trying to create a random user name in my tests in this format: tYYYYMMDDHHMM

I tried to do this with an external excel file that convert the "=NOW()" to this string and it works - only for the first time (even If I adding the excel file to the project).

I want to do this thing in the ranorex code but I don't know where to put it and how (how to write the code).

I will appreciate if someone can help me to do it.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3922
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Need a snippet to create user name randomaly

Post by odklizec » Mon May 06, 2013 6:55 am

Hi,

Try this...
string DateStr = DateTime.Now.ToString("yyyyMMddHHmmss");
Last edited by odklizec on Fri May 17, 2013 8:23 am, edited 1 time in total.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

itzikp
Posts: 3
Joined: Tue Apr 30, 2013 11:37 am

Re: Need a snippet to create user name randomaly

Post by itzikp » Mon May 06, 2013 7:10 am

odklizec wrote:Hi,

Try this...

Code: Select all

string DateStr = DateTime.Now.ToString("yyyyMMddHHmmss");

Thanks for your reply

As I'm green to ranorex and for C# or VB.... Where I put this snippet?

Thanks

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3922
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Need a snippet to create user name randomaly

Post by odklizec » Mon May 06, 2013 7:23 am

Don't worry, I'm a C# noob as well ;) As to where to place this code, it depends where and how you want to use it? You should place it somewhere before the code where you want to use the date string.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration