How to generate random test data?

1 Star2 Stars3 Stars4 Stars5 Stars (5 votes
Loading ... Loading ...

At times it is required that we use unique test data for every single run of an automation script. For Ex – for testing a user registration page we would need a username which already does not exists in the database. Though there are various ways to overcome this unique username issue but we will see one which is the simplest one. The idea behind this is to use current date and time to generate a no. which we know would be unique. The function given below can be used to convert date and time into the random number we need

'Author: Tarun Lalwani
'Website: www.KnowledgeInbox.com
'Description: Generate random number using date
Function GetRandomNumberByDate()
	Dim curDate
	'Get the current date
	curDate = Now
	GetRandomNumberByDate = Hour(curDate) & _
				Minute(curDate) & _
				Second(curDate) & _
				Day(curDate) & _
				Month(curDate) & _
				Year(curDate)
End Function
 
'Usage
'Msgbox GetRandomNumberByDate()

Note: The function can still generate same random numbers in case used on multiple machines where time is not in sync or both scripts get the time using Now function at the same time (slimmest possible chance of that happening)

Have questions related to this article? Want to request a new article? Use our forums to post your questions


Viewed 488 times
Free Advertising

Related posts:


    Support KnowledgeInbox (Why donate?)




    Your Email Address:



  1. Most Viewed


  2. Earn $$ with WidgetBucks!
  3. Sitemap

    open all | close all
  4. Most Downloaded

    • Screen Capture and Comparion API - Version 1.1.1 (425.5 KiB, 5,581 hits)
      You need to be a registered user to download this file.
    • QTP Clean uninstaller (26.4 KiB, 5,003 hits)
      You need to be a registered user to download this file.
    • VB to QTP API Converter (37.2 KiB, 4,389 hits)
      You need to be a registered user to download this file.
    • IE Helper setup (3.5 MiB, 4,131 hits)
      You need to be a registered user to download this file.
    • Dynamic Action Call Demo - Part 1 (40 KiB, 3,639 hits)
      You need to be a registered user to download this file.
  5. Most Rated

  6. Translator

    English flagItalian flagKorean flagChinese (Simplified) flagPortuguese flagGerman flagFrench flagSpanish flagJapanese flagArabic flagRussian flagGreek flagDutch flagBulgarian flagCzech flag
    Croat flagDanish flagFinnish flagHindi flagPolish flagRumanian flagSwedish flagNorwegian flagCatalan flagFilipino flagHebrew flagIndonesian flagLatvian flagLithuanian flagSerbian flag
    Slovak flagSlovenian flagUkrainian flagVietnamese flag           
    By N2H
  7. Last searched terms

    Visitors Online



Your Ad Here