Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Direct function or method
#1
Solved: 11 Years, 4 Months ago
hi all,

a string in edit box how to conform whether the string is alphabets or numeric or special characters..

regards,
raaj.
Reply
#2
Solved: 11 Years, 4 Months ago
you can try with IsNumeric to check numbers, If you want to check some combination of 'string, numbers and special chars' go for Regular Expression.
Reply
#3
Solved: 11 Years, 4 Months ago
hi,

thank you
can u pls give me the detailed script for all possible combinations.

regards,
raaj.
Reply
#4
Solved: 11 Years, 4 Months ago
Code:
'vStr = "test"
'vStr = "@#$"
vStr = "12345"
Set oReg = New RegExp
oReg.Pattern = ".*\W.*"
Set Matches = oReg.Execute(vStr)

If Matches.count > 0 Then
    print "Input has Special character"
Else
    print "Input has no Special character"
End If

If IsNumeric(vstr) Then
    print "Input has Numeric character"
Else
    print "Input has no Numeric character"
End If

Please refer QTP Help file for Regular Expression Patterns
Reply
#5
Solved: 11 Years, 4 Months ago
Code:
Function ValidateCharacterAcceptance(oEditObject,oTypeofEditBox)  
  
'Variable Declaration  
Dim wsh  
Dim oTypingText  
Dim oVisibleText  
  
'Assign a text value to the variable which is having all value types  
oTypingText="tester1234@!#$"  
  
'clear the values of edit box and focus on it by clicking  
oEditObject.Set ""  
oEditObject.Click  
'Wait is to clear some disturbance  
wait(1)  
  
'Create wscript object  
set wsh=CreateObject("wscript.shell")  
  
'Send text using sendkeys method  
wsh.SendKeys oTypingText  
  
'Wait is to clear some disturbance  
wait(1)  
  
'Get the visible text of the edit box  
oVisibleText=oEditObject.GetROProperty("value")  
  
'User can enter any type of text. But editbox accepts only the text which it is meant for.  
'The below condition check the visible text based on the text type.  
'If the type of visible text doesnot match the type of the edit box then the condition fails  
  
Select Case lcase(oTypeofEditBox)  
  
Case "alphabetic"  
  
If oVisibleText="tester" then  
Reporter.ReportEvent micPass,"Check Alphabetic Character Acceptance", "Typed Text: "& oTypingText &vbnewline& "Visible Text: "& oVisibleText  
Else  
Reporter.ReportEvent micFail,"Check Alphabetic Character Acceptance", "Typed Text: "& oTypingText &vbnewline& "Visible Text: "& oVisibleText  
End If  
  
Case "numeric"  
  
If oVisibleText="1234" then  
Reporter.ReportEvent micPass,"Check Numeric Character Acceptance", "Typed Text: "& oTypingText &vbnewline& "Visible Text: "& oVisibleText  
Else  
Reporter.ReportEvent micFail,"Check Numeric Character Acceptance", "Typed Text: "& oTypingText &vbnewline& "Visible Text: "& oVisibleText  
End If  
Case "alphanumeric"  
  
If oVisibleText="tester1234" then  
Reporter.ReportEvent micPass,"Check AlphaNumeric Character Acceptance", "Typed Text: "& oTypingText &vbnewline& "Visible Text: "& oVisibleText  
Else  
Reporter.ReportEvent micFail,"Check AlphaNumeric Character Acceptance", "Typed Text: "& oTypingText &vbnewline& "Visible Text: "& oVisibleText  
End If  
  
Case "alphanumericspecial"  
  
If oVisibleText=oTypingText then  
Reporter.ReportEvent micPass,"Check AlphaNumericSpecial Character Acceptance", "Typed Text: "& oTypingText &vbnewline& "Visible Text: "& oVisibleText  
Else  
Reporter.ReportEvent micFail,"Check AlphaNumericSpecial Character Acceptance", "Typed Text: "& oTypingText &vbnewline& "Visible Text: "& oVisibleText  
End If  
End Select  
  
Set wsh= nothing  
End Function  
SystemUtil.Run "iexplore.exe","http://192.168.1.210:8081"
Browser("name:=FMS - Login").Page("title:=FMS - Login").WebEdit("name:=UserName").Set "admin1"
Browser("name:=FMS - Login").Page("title:=FMS - Login").WebEdit("name:= Password").Set "admin1"
Browser("name:=FMS - Login").Page("title:=FMS - Login").webbutton("class:=loginbtn").Click
Browser("name:=FMS - Home Page").Navigate "http://test.com/Home/Index#url=%2FPerson%2FCreate"
Set oEditObject=Browser("name:=FMS - User Create").Page("title:=FMS - User Create").WebEdit("name:=Person.Phone")
ValidateCharacterAcceptance oEditObject,"alphanumericspecial"
Reply
#6
Solved: 11 Years, 4 Months ago
Hi,
I use Array.

Code:
MyArray(2)
MyArray(0)="lkjdñlaskdjas"
MyArray(1)="123456"
MyArray(2)="$%&$"

for i=0 to ubound(MyArray)
  
Windows("some").Dialog("some").WinEdit("some").Type MyArray(i)
  'valid message o invalid message
  reporter.reportevent micPass .... or reporter.reportevent micFail...
next

You need know the valid value for the object control.

Regards.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Calling a function in a Test Script from a function library anupam4j 3 6,131 06-26-2015, 12:31 AM
Last Post: babu123
  How to find built-in method/function in QTP ytramu 1 6,467 11-08-2010, 03:56 PM
Last Post: KavitaPriyaCR
  What is a Method in QTP and how many types are method r there in QTP? vidyabr 1 4,478 07-28-2008, 02:14 PM
Last Post: surya_7mar

Forum Jump:


Users browsing this thread: 1 Guest(s)