For any corporate training requirements Please mail To sudhakar@qtpsudhakar.com
New Schedule in MindQ Systems, Madhapur By SUDHAKAR
Course Name Date Time Duration Type Branch
UFT + UFTPro 20th September 2017 7.30 AM - 9.00 AM IST 25Days Classroom + Online Hitech City
Selenium+Appium 4th October 2017 4.30 PM - 6.00 PM IST 40Days Online -

A book "Cracking the QTP interview" authored by Sudhakar.Read More. Buy From FlipKart

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")
    oEditObject.Set ""
    wsh.SendKeys oMaxStr
    If len(iValue)=oMaxLen then
        Reporter.ReportEvent micPass,"Textbox Max Length Validation","Textbox support a Maximum of "& oMaxLength&" Characters"
        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


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


UnregisterUserFunc "WebEdit","ValidateTextboxMaxLength"

Part2-- Characters Acceptance Validation
Please send your Suggestions and Doubts to my yahoo group http://in.groups.yahoo.com/group/qtpsudhakar


  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..:)

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

  3. too good man !!!

  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.

    Veeranki Naveen.

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

    ValidateTextboxMaxLength EditObj , MaxLen