Thursday, April 21, 2011

QTP : Example of Compare Text using InStr

Example of Compare Text for InStr
' Returns position 6
MsgBox InStr(1,"Moni Ajith Kumar","Ajith")

' Returns position 0 -
MsgBox InStr(7,"Moni Ajith Kumar","Ajith")

QTP : InStr with vbTextCompare vbBinaryCompare

Example Set 2: - String -"Todays India" Find the value "in"
' Position Value is 8 for "in"
MsgBox "Position of ""in"" is "& Instr(1,"Todays India","in",vbTextCompare)

' Returns Position Value 8
MsgBox "Position of ""In"" is "& Instr(1,"Todays India","In",vbTextCompare)

' Returns Position Value 0
MsgBox "Position of ""in"" is "& Instr(1,"Todays India","in",vbBinaryCompare)

' Returns Position Value 8
MsgBox "Position of ""In"" is "& Instr(1,"Todays India","In",vbBinaryCompare)

Example Set 2: Change Start position of Compare Text
' Returns 6
MsgBox InStr(1,"Moni Ajith Kumar","Ajith")
' Returns 0 -
MsgBox InStr(7,"Moni Ajith Kumar","Ajith")

QTP Find the Position of a String

'Find Position of the String "is" in a sentence

v_input_string="The Request is 123456"
v_text_to_find="is"

' Store the position
v_pos=InStr(1,v_input_string,v_text_to_find)

MsgBox "Position of the String ""is"" is : "&v_pos

MsgBox "Position of ""in"" is"& Instr(1,"Todays Developing India","In")


OutPut:

Position of the String "is" is 13
Position of "in" is 19

Wednesday, April 20, 2011

QTP Count the number of links in a page

' Get The Object
Set htmlObjCol_l=Browser("Oracle Applications Home").Page("Login").Object.links

' Count
Dim i
i=0

For each  element in htmlObjCol_l
    ' HTML Anchor element
    'MsgBox typename(element)
    'MsgBox typename(element.toString())
    MsgBox element
    'MsgBox element.toString()
     'MsgBox element.Name
    'Print to the Report
    Reporter.ReportEvent micPass,"Link : "&i,""&element.toString()&vbCrLf&vbCrLF&element.Name
    i=i+1   
Next
MsgBox "No of Links "&i

QTP Count the Number of Open Browser Sessions

QTP Count the Number of Open Browser Sessions

' Create a Description Object

Dim iDesc

Set iDesc = Description.Create

' Assign the micclass Property
iDesc("micclass").value="browser"

'Get the child objects using getChildObjects
Set iObj = Desktop.ChildObjects(iDesc)

'Displays the count
MsgBox iObj.Count