Scripting Exercise: Unique Usernames
Imagine that you have to create a script for the “Create New User Account” business process. There are several constraints that will make your job difficult…
The username field has the following properties:
- valid characters are a-z, A-Z, 0-9
- usernames are not case sensitive. “Stuart” is the same as “stuart”.
- usernames must start with a letter, not a number.
- usernames may be a maximum of 8 characters long.
- username must not be a duplicate
Some other information about your testing:
- It is unclear when the database in the test environment will be refreshed, but it should happen at least yearly. It will definitely not be refreshed for every test run, and it will not be possible to delete any of the user accounts that you have created.
- The business process takes a minimum of 1 minute to run from start to finish.
- There will be a maximum of 99 virtual users executing the business process in the scenario.
- It is possible that virtual users will execute the business process at exactly the same time.
How do you create usernames that meet all of the above criteria without creating any duplicates? Create a script or provide a descriptive solution.
See the comments section for my solution…
October 17th, 2006 at 1:50 pm
The quickest and easiest solution to this problem would be to create a big list of unique usernames and keep track of which ones have been used. This is going to be painful if you have do months of testing before the database is refreshed, so it is good if you can find a code-based solution.
Note that I would be overjoyed if someone can provide a better solution than the one that I have provided.
October 24th, 2006 at 7:50 am
I usually create them ahead of time using Excel.
October 26th, 2006 at 11:41 am
I agree that creating usernames outside of LoadRunner (using Excel or whatever) is quick and easy when you’ve only got a few tests to run.
I would argue that having to keep track of which usernames have been used becomes increasingly painful the more tests you have to run.
Also, I hate having to update values in a data table every time I need to run a script.
Spending 30 minutes writing some code that will save you having to manually manage a list of usernames seems like a good trade-off to me.
Cheers,
Stuart.
February 7th, 2007 at 8:20 am
I came across this problem years ago for a functional testing project, I used the time stamp and added a routine to convert numbers to alphas. Used Winrunner
May 15th, 2007 at 8:59 pm
The fastest and easiest way is just record and replaying the “Create New User Account” flow for 100 iteration with different user name.
Note: Just parameterize the name with a list of values dragged from an excel.
Cheers,
Senthil
January 16th, 2008 at 5:38 am
Well, Senthil, how you get the values into excel ? Wasn’t that the question ?
Raju
January 21st, 2008 at 3:49 pm
I agree with Stuart’s solution to create unique names. I also used this way in the past and it works.
Alternatively, you can also do the following:
Define year, month, day,hour, and seconds array with pre-defined charactors.
eg.
char arrayYY[8][1]=”{”a”,”b”,”c”,”d”,”e”,”f”,”g”,”h”};
char arrayMM[12][1]=”{”a”,”b”……..”}
.
.
.
char arraySeconds[60][2]={”AA”,”AB”,…..”};// 60 of them
Then, read out the real time value of dates and select the characters from the array.
eg.
yy=atoi(lr_eval_string(”{TimeYear}”) // defined parameter
yy=yy-7 // can be randomised
.
.
.
sec = atoi(lr_eval_string(”{TimeSecond}”);
Next part of concatenating will be similar to Stuart’s solutions.
eg.
strncat(SecondName, arraySeconds[sec],2)
.
.
lr_save_string(SecondName,”SecondNameParam”);
likewise
strncat(FirstName, arraryMM[mm], 1);
lr_save_string(FirstName,”FirstNameParam”);
…..
Anyway, this alternative solution I hinted out may be a bit longer in code.
One of the main advantage of using this as I found is to use the pre-defined characters by yourself.
Cheers
Mohan