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-1-Verify Maximum Length


Basic Editbox Testing Checklist:-
  1. Maximum Length
  2. Characters Acceptance

    • Alpha Characters Only
    • Numeric Characters Only
    • Alpha Numeric Characters Only
    • Alpha Numeric Custom Characters
  3. Clipboard Text Acceptance
  4. Enable / Disable
  5. Text Encryption
To understand this post the reader should already know about
  • String Function in VBScript
  • GetROProperty Method in QTP
  • SendKeys Method in WSH Scripting
 1. Maximum Length Validation
Identifying max length is possible by using a property called “max length”. But its a little tricky if we want to test by entering the maximum number of characters. Suppose a textbox support 7 characters. In this case we have to make a try, to enter 8 characters. If we try to enter using “set” method QTP pops up an error saying “The parameter is incorrect.”. In this case we have to for sendkeys method from wsh scripting. Using this we can replicate manual typing.
Automation Testing is Not like Automating the Application Functionalities. Its should replicate the exact Manual Actions.

'**********************************************************************************
Function ValidateTextboxMaxLength(oEditObject,oMaxLen)
 
Dim wsh
Dim oMaxStr
Dim iValue
 
    set wsh=CreateObject("wscript.shell")
 
    oMaxStr=string(oMaxLen+1,"s")
    oEditObject.Set ""
    oEditObject.Click
    wait(1)
    wsh.SendKeys oMaxStr
    iValue=oEditObject.GetROProperty("value")
 
    If len(iValue)=oMaxLen then
        Reporter.ReportEvent micPass,"Textbox Max Length Validation","Textbox support a Maximum of "& oMaxLength&" Characters"
        else
        Reporter.ReportEvent micFail,"Textbox Max Length Validation","Textbox support more than "& oMaxLength&"Characters"
    End If
    Set wsh= nothing
 
End Function
 
'**********************************************************************************

‘Calling the Function

set EditObj=Browser("").Page("").WebEdit("")
ValidateTextboxMaxLength EditObj

'OR

RegisterUserFunc "WebEdit","ValidateTextboxMaxLength”,"ValidateTextboxMaxLength”

Browser("").Page("").WebEdit("").ValidateTextboxMaxLength

UnregisterUserFunc "WebEdit","ValidateTextboxMaxLength"

Part2-- Characters Acceptance Validation
__________________________________________________________

8 comments :

  1. Osam logic..Thanks again for sharing knowledge..

    But code missing oMaxLen=Editobj.GetroProperty("max length")

    One more thing is thr but I think its intentionally..:)

    ReplyDelete
  2. u gotta pass the omaxlength value to the function k jitendra the code is correct

    ReplyDelete
  3. too good man !!!

    ReplyDelete
  4. Good Article Sudhakar,

    There is a small typo error I guess on the Reporter.Event line.

    Reporter.ReportEvent micFail,"Textbox Max Length Validation","Textbox support more than "& *************oMaxLength*************&"Characters"

    It should be oMaxLen which is typed as oMaxLength in the above line.

    Regards,
    Veeranki Naveen.

    ReplyDelete
  5. One more type error is on Line number 31 i.e one of the parameter is missed.

    ValidateTextboxMaxLength EditObj , MaxLen

    Regards,
    Veeranki

    ReplyDelete