Sometimes we need to create the test data randomly in the form of strings (numerical, alphanumerical and alphabetical) at run time. I have created one function that will give you random strings.
'to get only alphabetical strings, pass 1 as input
print getRandomString(1)
'to get only alphanumerical strings , pass 2 as input
print getRandomString(2)
'to get only numerical strings , pass 3 as input
print getRandomString(3)
Function getRandomString(byval intType)
stamp = replace(replace(formatdatetime(now),":","-"),"/","")
stamp = replace(stamp,"-","")
stamp = replace(stamp," ","")
If intType = 1 Then
'only alphbetical
For i=1 to 8
Randomize
x = x & chr( Int((90-65+1)*Rnd+65))
Next
elseIf intType = 2 Then
' alphanumeric
x = "AN" + stamp
elseIf intType = 3 Then
' only digits
x = stamp
End If
getRandomString = x
End Function
All the strings will be unique as they are based on time stamp.
Some of the testing scenarios where you will need such function are given below.
Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts. You can write to me at reply2sagar@gmail.com
'to get only alphabetical strings, pass 1 as input
print getRandomString(1)
'to get only alphanumerical strings , pass 2 as input
print getRandomString(2)
'to get only numerical strings , pass 3 as input
print getRandomString(3)
Function getRandomString(byval intType)
stamp = replace(replace(formatdatetime(now),":","-"),"/","")
stamp = replace(stamp,"-","")
stamp = replace(stamp," ","")
If intType = 1 Then
'only alphbetical
For i=1 to 8
Randomize
x = x & chr( Int((90-65+1)*Rnd+65))
Next
elseIf intType = 2 Then
' alphanumeric
x = "AN" + stamp
elseIf intType = 3 Then
' only digits
x = stamp
End If
getRandomString = x
End Function
All the strings will be unique as they are based on time stamp.
Some of the testing scenarios where you will need such function are given below.
- Some times users are allowed to save the profile settings which can be loaded later on. In this case, we need to create such profile names that are unique.
- Some times we need to create the entity names which are unique. For example - creating the group Ids, User Ids etc.
Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts. You can write to me at reply2sagar@gmail.com
No comments:
Post a Comment
Please Leave your reply. We value your feedback and inputs