Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Random Number generator and verification problem
#1
Solved: 11 Years, 4 Months, 3 Weeks ago
In one of the fileds data needs to be between 10-99 and unique.
For now I am trying the following codes

Code:
Dim upperbound, lowerbound
upperbound=99  
lowerbound =10
For i=10 to 99  
CatEventCode=Int((upperbound - lowerbound + 1) * Rnd + lowerbound)  
Next[/b][/color]

[color=#800000][b]If Browser("...").Page("...").WebEdit("...").GetROProperty("value")=CatEventCode Then
    Reporter.ReportEvent micPass,"2 digits value is entered in <CAT/EvenetCode> field",""
    Call Logger(1," 2 digits value is entered in <CAT/EvenetCode> field")
    else
    Reporter.ReportEvent micFail,"2 digits value is not entered in <CAT/EvenetCode> field",""
    Call Logger(2,"2 digits value is not entered in <CAT/EvenetCode> field")
End If


Why does verification fail?

Any other idea for generating 2 digits unique number?
Reply
#2
Solved: 11 Years, 4 Months, 3 Weeks ago
Jinnah,

Can you explain why are you using For loop. There is absolutely no need of this loop. You need to use randomize keyword before creating the random number.

You can try any of the below options.
Code:
1.
intMaxValue=99
intMinValue=10

Randomize  'This will generate a unique number every time
            
intRndVariable= Int((intMaxValue-intMinValue+ 1) * Rnd +intMinValue)

2. Use RandomNumber function

intRandomNumber=RandomNumber(intLoweLimit,Upperlimit)

e.g., a=RandomNumber(10,99)

Regards,
Ankesh
Reply
#3
Solved: 11 Years, 4 Months, 3 Weeks ago
Hi Anikesh I see you are the best one in this forum. I think you already know my qtp skill. I have started learning it and using in my job at the same time. I just googled it and used it(For loop). Anyway, I will use your one as those are more Logical.

Anyway, Anyidea how to verify if radom number is entered in the webedit box?
Reply
#4
Solved: 11 Years, 4 Months, 3 Weeks ago
I see the comparison code by you is fine, it requires a slight modification though.

Code:
If Browser("...").Page("...").WebEdit("...").GetROProperty("value")=CatEventCode Then

lets talk abt the above line.

CatEventCode : This the random number generated. This is in integer format.

Browser("...").Page("...").WebEdit("...").GetROProperty("value")= This will return the value in string format.

so if you directly compare the value, result will be fail. You need to do the typecasting.

correct code will be

Code:
strDisplayedValue=Browser("...").Page("...").WebEdit("...").GetROProperty("value") 'get the value
'convert it to integer for comparision
intConvertedValue=Cint(strDisplayedValue)
'now do the comparision
if intConvertedValue=CatEventCode Then
'Pass
Else
'Fail
End IF

Regards,
Ankesh
Reply
#5
Solved: 11 Years, 4 Months, 3 Weeks ago
Waooo Man! I see I am learning. I don't know how long you will support me in thsi way. I am already in love of this site and ofcourse you!! Ha haa. Yes, I had problem with verification. I used same method you taught me for Reg Ex verification. I did.
-----------------------------------------------------------
Code:
upperbound=99  
lowerbound =10
CatEventCode=Int((upperbound - lowerbound + 1) * Rnd + lowerbound)  

        Browser("ClaimCenter_Br").Page("ClaimCenter_Pg").WebEdit("Cat/EvenetCode").Set CatEventCode
CatastrophyEventCode=Browser("ClaimCenter_Br").Page("ClaimCenter_Pg").WebEdit("Cat/EvenetCode").GetROProperty("value")

Set RegEx=CreateObject("VBScript.RegExp")
RegEx.Pattern="[0-9]+"
BllnResult=RegEx.Test(CatastrophyEventCode)

If BllnResult=True Then
    Reporter.ReportEvent micPass,"2 digits value is entered in <CAT/EvenetCode> field",""
    Call Logger(1," 2 digits value is entered in <CAT/EvenetCode> field")
    else
    Reporter.ReportEvent micFail,"2 digits value is not entered in <CAT/EvenetCode> field",""
    Call Logger(2,"2 digits value is not entered in <CAT/EvenetCode> field")
End If
Set RegEx=Nothing
------------------------------------------------------------

But I am going to replace these with your new codes.It is more logical and I ve just learned a new thing. Great buddy. Thanks again.


Hi, I am sorry as my reply goes on top of yours. I think I need to reply from Quick Reply section.

So to covert string to Intiger Cint is used. What about Intiger to string? Sorry for dumb question.

Yes bro! I have just changhed my previous codes. IT works fine. Thanks again

Here it is

Code:
upperbound=99  
lowerbound =10
CatEventCode=Int((upperbound - lowerbound + 1) * Rnd + lowerbound)  

        Browser("ClaimCenter_Br").Page("ClaimCenter_Pg").WebEdit("Cat/EvenetCode").Set CatEventCode
StrCatEventCode=Browser("ClaimCenter_Br").Page("ClaimCenter_Pg").WebEdit("Cat/EvenetCode").GetROProperty("value")

needs to be coverted to Intiger
IntCatEventCode=Cint(StrCatEventCode)
If  IntCatEventCode=CatEventCode Then
    Reporter.ReportEvent micPass,"2 digits value is entered in <CAT/EvenetCode> field",""
    Call Logger(1," 2 digits value is entered in <CAT/EvenetCode> field")
    else
    Reporter.ReportEvent micFail,"2 digits value is not entered in <CAT/EvenetCode> field",""
    Call Logger(2,"2 digits value is not entered in <CAT/EvenetCode> field")
End If
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create a random number starting with an alphabet QTPmate 4 4,282 07-31-2014, 09:29 AM
Last Post: QTPmate
  Random Values from Drop-Down profqa 5 6,099 12-06-2013, 09:01 AM
Last Post: basanth27
  Creating Random String SomeIntern 0 5,110 08-21-2013, 09:10 PM
Last Post: SomeIntern
  Export verification QAVA 1 2,673 11-05-2012, 10:25 AM
Last Post: sshukla12
  How to choose a random no from list alwarselvam 0 3,176 12-24-2011, 08:28 AM
Last Post: alwarselvam

Forum Jump:


Users browsing this thread: 1 Guest(s)