How to Set random unique string and/or integer in webedit

144 views
Skip to first unread message

george p

unread,
Nov 17, 2013, 12:41:53 PM11/17/13
to mercu...@googlegroups.com

Hi,
i have web app that creates forms.
I need to enter text in the form title, name and description fields and save the form.
Form title and name is unique and I was thinking to set random unique string and/or integer.
How can I do this in Descriptive programing, i am not using OR at all.

I would like to do thi 4-5 times to create multiple forms.

Browser("title:=.*").Page("title:=.*").webEdit("name:=dataElementForm.title").Set "some title"
Browser("title:=.*").Page("title:=.*").webEdit("name:=dataElementForm.name").Set "some Name"
Browser("title:=.*").Page("title:=.*").webEdit("name:=dataElementForm.shortDescription").Set "descriptions"


suman ch

unread,
Nov 18, 2013, 12:53:10 AM11/18/13
to mercu...@googlegroups.com
Hi,

Append the TEXT that you want to insert with NOW() function, so that you will get random values or you can use the random() function in QTP.

Regards,
Suman CH


--
--
You received this message because you are subscribed to the Google
"QTP - HP Quick Test Professional - Automated Software Testing"
group.
To post to this group, send email to Mercu...@googlegroups.com
To unsubscribe from this group, send email to
MercuryQTP+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/MercuryQTP?hl=en
 
---
You received this message because you are subscribed to the Google Groups "QTP - HP Quick Test Professional - Automated Software Testing" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mercuryqtp+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Wayne Hirata

unread,
Nov 18, 2013, 11:46:28 AM11/18/13
to mercu...@googlegroups.com
Chr(65 + Int(26 * Rnd())) & Chr(97 + Int(26 * Rnd())) & Chr(48 + Int(10 * Rnd()))

That's one upper case letter and one lower case letter and one digit. 

Here is a random length string that has 3 to 7 upper case letters.
For i = 1 To 3 + Int(5 * Rnd())
a = a & Chr(65 + Int(26 * Rnd()))
Next
Message has been deleted

george p

unread,
Nov 18, 2013, 4:35:53 PM11/18/13
to mercu...@googlegroups.com
Great, thanks.
Can you also share how entire script would look like?

Wayne Hirata

unread,
Nov 19, 2013, 1:50:46 AM11/19/13
to mercu...@googlegroups.com
Randomize

Browser("title:=.*").Page("title:=.*").webEdit("name:=dataElementForm.title").Set Trim(Mid("Mr  Ms  MissDr  Capt",1+4*Int(5*Rnd()),4))


--
--
You received this message because you are subscribed to the Google
"QTP - HP Quick Test Professional - Automated Software Testing"
group.
To post to this group, send email to Mercu...@googlegroups.com
To unsubscribe from this group, send email to
MercuryQTP+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/MercuryQTP?hl=en
 
---
You received this message because you are subscribed to a topic in the Google Groups "QTP - HP Quick Test Professional - Automated Software Testing" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mercuryqtp/cawASIZTUbA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mercuryqtp+...@googlegroups.com.

George Popkhadze

unread,
Nov 19, 2013, 10:10:20 AM11/19/13
to mercu...@googlegroups.com
Thanks Wayne,
I kind a got an idea what this script does.
How to eliminate spaces in the string, i cant have spaces, only underscores is allowed

Thanks

Wayne Hirata

unread,
Nov 19, 2013, 11:38:35 AM11/19/13
to mercu...@googlegroups.com
My sample used the TRIM function. The TRIM function trims off spaces.

And don't forget the RANDOMIZE statement. 

QTP comes with a VBSCRIPT help file, script.chm, or something like that.

Ganesh muralidharan

unread,
Nov 19, 2013, 12:11:58 PM11/19/13
to mercuryqtp
George, if the space is within the string then trim will not work better to use Replace and replace space with underscore.


You received this message because you are subscribed to the Google Groups "QTP - HP Quick Test Professional - Automated Software Testing" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mercuryqtp+...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
Regards,


Ganesh Muralidharan
'God Never Forgets'

George Popkhadze

unread,
Nov 19, 2013, 1:30:27 PM11/19/13
to mercu...@googlegroups.com
Wayne,
Everytime I run this script, I get the "Dr" as a title


Browser("title:=.*").Page("title:=.*").webEdit("name:=dataElementForm.title").Set Trim(Mid("Mr  Ms  MissDr  Capt",1+4*Int(5*Rnd()),4))

I am confused why its only come as 2 letters


Wayne Hirata

unread,
Nov 19, 2013, 10:57:34 PM11/19/13
to mercu...@googlegroups.com
Add the RANDOMIZE statement to the beginning of your script before you execute any other code. Don't forget the RANDOMIZE statement.

george p

unread,
Nov 21, 2013, 8:34:52 PM11/21/13
to mercu...@googlegroups.com
Thanks for all your help..
It does randomize however spaces are Not Trimmed. I need underscores not space between the string

Wayne Hirata

unread,
Nov 21, 2013, 11:46:35 PM11/21/13
to mercu...@googlegroups.com
As Ganesh said, wrap everything in a REPLACE function and replace space with underscore.


On Thu, Nov 21, 2013 at 3:34 PM, george p <geom...@gmail.com> wrote:
Thanks for all your help..
It does randomize however spaces are Not Trimmed. I need underscores not space between the string

george p

unread,
Nov 22, 2013, 2:25:24 PM11/22/13
to mercu...@googlegroups.com
Garnesh, I want to try that, where the replace will go in the code.

Browser("title:=.*").Page("title:=.*").webEdit("name:=dataElementForm.title").Set Replace(Mid("abc_def_ghijklm_nopqrstuv",1+4*Int(5*Rnd()),4))

I did try replacing Trim with Replace, but its giving wrong argument error.

Ganesh muralidharan

unread,
Nov 22, 2013, 2:35:29 PM11/22/13
to mercuryqtp
Syntax and example from qtp below :
Replace(expression, find, replacewith[, start[, count[, compare]]])
MyString = Replace("XXpXXPXXp", "p", "Y")

Wayne Hirata

unread,
Nov 27, 2013, 12:55:39 AM11/27/13
to mercu...@googlegroups.com
Randomize

x(1) = "Miss"
x(2) = "Dr."
x(3) = "Capt."
x(4) = "Mr."

s = x(  1 +  Int(  Rnd() * UBound(x)  )  )

print s

uma mahesh

unread,
Nov 27, 2013, 6:20:12 AM11/27/13
to mercu...@googlegroups.com
Why dont you use date and time as a string.


george

unread,
Dec 4, 2013, 4:43:10 PM12/4/13
to mercu...@googlegroups.com
OK, thanks for all your responses.

I was able to randomize it properly.

i have another question which I will create  new topic.

thanks again
Reply all
Reply to author
Forward
0 new messages