Print Page | Close Window

QTP and Word Spell Checker

Printed From: One Stop Testing
Category: Testing Tools @ OneStopTesting
Forum Name: QuickTest Pro @ OneStopTesting
Forum Discription: QuickTest Pro is a fresh approach to automated software and application testing that addresses testing needs of both business analysts and Quality Assurance professionals.
URL: http://forum.onestoptesting.com/forum_posts.asp?TID=7245
Printed Date: 01Jan2025 at 8:03pm


Topic: QTP and Word Spell Checker
Posted By: Mithi25
Subject: QTP and Word Spell Checker
Date Posted: 27Oct2009 at 11:55pm

The following code shows a function for checking the number of spelling and grammar errors in a string.

http://qtp9.blogspot.com/2007/11/using-microsoft-word-spell-check.html - The following code shows a function for checking the number of spelling and grammar errors in a string.

Function NumberOfSpellErrors(strText)

       Dim objMsWord

       Set objMsWord = CreateObject("Word.Application")

       objMsWord.WordBasic.FileNew

       objMsWord.WordBasic.Insert strText

       NumberOfSpellErrors = objMsWord.ActiveDocument.SpellingErrors.Count

       objMsWord.Documents.Close (False)

       objMsWord.Quit ' close the application

       Set objMsWord = Nothing' Clear object memory

End Function

' The following function uses the Spell errors function to check a specific property

' of all the objects with a given description which are under a given parent

Sub CheckAllObjects(ParentObj, ObjDesc, PropName)

       Dim ObjCol, idx, PropValue, OldReportMode

       OldReportMode = Reporter.Filter

       Reporter.Filter = 2 ' Report only errors

       If (IsNull(ParentObj)) Then

              Set ObjCol = Desktop.ChildObjects(ObjDesc)

       Else

              Set ObjCol = ParentObj.ChildObjects(ObjDesc)

       End If

       For idx=0 to ObjCol.count-1

              PropValue = ObjCol.Item(idx).GetROProperty(PropName)

              RetVal = NumberOfSpellErrors(PropValue) ' The actual spell check result

              If (RetVal > 0) Then

                     ReportText = "Object #" & idx+1 & ": The '" & PropName & "' Property has " & RetVal & " spell errors (" & PropValue & ")"

                     Reporter.ReportEvent 1, "Spell Check", ReportText

              End If

       Next

       Reporter.Filter = OldReportMode

End Sub

'''''''''''''''''''''''''''''''''''''

' An example of usage:

' Go over all the static objects in the Login window of the Flight Application

' and for each object check the text for spelling and grammatical errors

'''''''''''''''''''''''''''''''''''''

' Go over all the links in the page and report all the ones that fail the spellcheck

Set Desc = Description.Create()

Desc("nativeclass").Value = "Static"

Set Obj = Dialog("nativeclass:=#32770", "text:=Login")

' Invoke the Flight Application before calling the function

CheckAllObjects Obj, Desc, "text"

-------------
http://www.quick2sms.com - Send Unlimited FREE SMS to Any Mobile Anywhere in INDIA,
Click Here




Print Page | Close Window