Text check point

Text check point is used for checking the text present in the specified object.
Navigation :
Keep the tool under record mode ->Insert menu -> Check point -> Text check point -> select the desired object with handler pointer -> click OK -> select any option like Match, Ignore spaces, Exact Match, Text not displayed -> Click OK

Coding the Text check point:

We have to do the following for implementing text check point via code.

1.    Specify the text to be checked.
2.    Get the text visible on the application
3.    Check whether the expected text exists in the captured text.
4.    Report to QTP results.

Script: Verify “version 4.0’ text is displaying in Help

Option Explicit
Dim expText=”version 4.0”
Dim getText, txtPos
expText="Version 4.0"
getText= window("Flight Reservation").Dialog("About Flight Reservation").GetVisibleText()

txtPos=Instr(getText,expText)
If txtPos<>0 Then
    Reporter.ReportEvent micPass,"Text should be found","Text is found"
Else
    Reporter.ReportEvent micFail," Text should be found","Text is not found"
End If
   
    GetVisibleText() method: It returns the text that is visible on the object during runtime.
    InStr() function: It compare the actual text with expected text and returns the position.

    Script: Write a Script to count number of occurrences for a given string in actual string.

    Method 1
    Option Explicit
    Dim actualTxt,exptxt,indx,instCnt
actualTxt=”My name is James there is not pre-requisite for learning qtp”
    expTxt=”qtp”
    indx=0
    instCnt=0
    Do
        Indx=InStr(indx+1,actualTxt,expTxt)
        If indx > 0 Then
            instCnt=instCnt + 1
        Else
            Exit Do
        End If
    Loop While (True)
   
Method 2

Option Explicit
    Dim actualTxt,exptxt
actualTxt=”My name is James there is not pre-requisite for learning qtp”
    expTxt=”qtp”
msgbox (len(actualTxt)-len(Replace(actualTxt,expTxt,””)))/len(expTxt)


Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com