The function below retrieves visible text of the object, writes it into a Microsoft Word document and checks the spelling by accessing the Microsoft Word Document Object Model.
Note:
This function is not part of QuickTest Professional. It is not guaranteed to work and is not supported by Mercury technical Support. You are responsible for any and all modifications that may be required.
CheckSpelling(obj)
obj | Object or window to check spelling. |
Dim myText, objWD, SpellCollection, rngRange,ListOfAlternateWords,newWord, iword, suggWord,iword2, suggWords
'get all text from window
myText = obj.GetVisibleText
' Create the Word Object
Set objWD = CreateObject("Word.Application")
Set newDoc = objWD.Documents.Add
' Add text to the document
objWD.Selection.TypeText myText
' Save the document
objWD.ActiveDocument.SaveAs "c:\temp\mydoc.doc"
Set rngRange = objWD.ActiveDocument.Range
' get all spelling errors
Set SpellCollection = rngRange.SpellingErrors
For iword = 1 To SpellCollection.Count
newWord = SpellCollection.Item(iword).Text
' report misspelled word in Test Results
Reporter.ReportEvent 1, "Misspelled:", newWord
' get list of suggestions
Set ListOfAlternateWords = objWD.GetSpellingSuggestions(newWord)
suggWords = ""
For iword2 = 1 To ListOfAlternateWords.Count
suggWord = ListOfAlternateWords.Item(iword2).Name
suggWords = suggWords + suggWord + " "
Next
' report suggestions into Test Results
Reporter.ReportEvent 0, "Suggested variants:", suggWords
Next
' Quit Word
objWD.Quit
' Release the Word object
Set objWD = Nothing
End Function
Example:
' Register the CheckSpelling function for use with the window.
RegisterUserFunc "Window", "CheckSpelling","CheckSpelling"
' Execute the function
Window("Flight Reservation").CheckSpelling
No comments:
Post a Comment