Facebook

Course Name Start Date Time Duration Registration Link
No Training Programs Scheduled ClickHere to Contact
Please mail To sudhakar@qtpsudhakar.com to Register for any training

Thursday, May 17, 2012

All about Validation of Editbox – Part-2 - Character Acceptance

This article is the continuation of my previous post All about Validation of Editbox – Part-1. This will discuss about edit box character acceptance.
Usually there are 3 text character types used to enter in edit box. Sometimes it can be a combination from these three types.
  1. Alphabetic
  2. Numeric
  3. Special characters
When you check the character acceptance for an edit box using QTP, the edit box will always accept all the values which are coming from QTP. Even though if that edit box is developed to enter only alphabetic or only numeric or only special characters. But when any user enters the value it accepts only the values for which it is developed. As I said before Automation Testing is Not like Automating the Application Functionalities. Its should Replicate the Exact Manual Actions”. So to replicate exact manual actions we have to use SendKeys method in WSH.
The below function is useful in such conditions

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="SudhakarKakunuri1234@!#$"
 
'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="SudhakarKakunuri" 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="SudhakarKakunuri1234" 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
 
'Calling the Function
Set oEditObject=Browser("").Page("").WebEdit("")
ValidateCharacterAcceptance oEditObject,"alphanumericspecial"

2 comments :