- hondaman
- Posts : 1
Join date : 2012-03-01
Need to randomly generate a DOB in SeleniumIDE
Thu Mar 01, 2012 6:32 pm
Morning all, im new to thr forum and in need of help,
For one reason or another i need to be able to generate a random, but realistic date of birth. so no more than 100 years old, no younger than 16 years old.
Is this possible to be able to do it in IDE ?
Any help would be apreciated.
Thanks
Blair
For one reason or another i need to be able to generate a random, but realistic date of birth. so no more than 100 years old, no younger than 16 years old.
Is this possible to be able to do it in IDE ?
Any help would be apreciated.
Thanks
Blair
- ccoxMaster
- Posts : 205
Join date : 2012-01-06
Age : 39
Location : Denver, CO
Re: Need to randomly generate a DOB in SeleniumIDE
Thu Mar 01, 2012 10:31 pm
Yes this is definitely doable with a custom function in your user-extension file. Basically you would create 3 random numbers, 1-12, 1-29(just in case you do get February), and 1912-1996. Then use the function to return those numbers with "/" between them.
- Tester Mark
- Posts : 6
Join date : 2012-03-10
Age : 110
Re: Need to randomly generate a DOB in SeleniumIDE
Sat Mar 10, 2012 2:16 am
hondaman wrote:Morning all, im new to thr forum and in need of help,
For one reason or another i need to be able to generate a random, but realistic date of birth. so no more than 100 years old, no younger than 16 years old.
Is this possible to be able to do it in IDE ?
Any help would be appreciated.
Thanks
Blair
You can generate your values using JavaScript. For example, your year of birth would be:
javascript{Math.floor(Math.random() * (1996 - 1912 + 1)) + 1912} will bring back a random value between 1912 and 1996 (ages 16 through 100).
For the month you can use (as long as you need a numeric value):
javascript{[Math.floor(Math.random() * (12 - 1 + 1)) + 1]}
And for the day:
javascript{[Math.floor(Math.random() * (28 - 1 + 1)) + 1]}
With this, it only returns dates from 1 through 28 (you'll have to figure out the 29th through 31st on your own to get around the issue with February).
To put them all together (with a "/" like ccox mentioned):
javascript{[Math.floor(Math.random() * (12 - 1 + 1)) + 1]+"/"+[Math.floor(Math.random() * (28 - 1 + 1)) + 1] + "/" + [Math.floor(Math.random() * (1980 - 1950 + 1)) + 1950]}
I'm no JavaScript whiz; it took me a while to piece this together, but it's been useful in some scripts that I've put together using the Selenium IDE. I hope that it helps (and 'Hello' from one forum newbie to another ).
Mark
Permissions in this forum:
You cannot reply to topics in this forum