Sunday 18 January 2015

UFT - QTP - How to check for presence of string on a web page


                                        Link to Mandatory QTP /UFT Interview Questions to read before Interview

Function WebElement_CheckStringExistance(byval objPageName, byval InpPropertyname, byval InpPropertyvalue,byval outPropertyName, byval Index, byval strValueToverify)
  WebElement_CheckStringExistance = 0
  Set ObjPage= objPageName
   If Index ="" Then
    If ObjPage.WebElement(InpPropertyname & ":="& InpPropertyvalue).exist(10) then
    ObjPage.WebElement(InpPropertyname &":="& Inppropertyvalue).highlight ' comment later
    strvalue=ObjPage.WebElement(InpPropertyName &":="& Inppropertyvalue).GetROProperty(outPropertyName)
    Reporter.ReportEvent 4"WebElement_CheckStringExistance""Checking for string value "& strValueToverify
    Reporter.ReportEvent micPass,"WebElement_CheckStringExistance","Webelement  with Property " & InpPropertyName & "Property Value " & InpPropertyvalue & "Found"
    If instr(1,strvalue, strValueToverify) > 0Then
     Reporter.ReportEvent micPass,"WebElement_CheckStringExistance","String with value " & strValueToverify &"Found in webelement"
     WebElement_CheckStringExistance =0
    else
     Reporter.ReportEvent micfail,"WebElement_CheckStringExistance","String with value " & strValueToverify &"not found in webelement"
     WebElement_CheckStringExistance =1
    End If
   Else
    Reporter.ReportEvent 4"WebElement_CheckStringExistance""Checking for string value "& strValueToverify
    Reporter.ReportEvent micfail,"WebElement_CheckStringExistance","Webelement  with Property " & InpPropertyName & "Property Value " & InpPropertyvalue & "Found"
    WebElement_CheckStringExistance = 1
  End if
 else
  If ObjPage.WebElement(InpPropertyname & ":="& InpPropertyvalue , "Index:=" & Index).exist(10) then
    ObjPage.WebElement(InpPropertyname &":="& Inppropertyvalue,  "Index:=" & Index).highlight ' comment later
    strvalue=ObjPage.WebElement(InpPropertyName &":="& Inppropertyvalue,  "Index:=" & Index).GetROProperty(outPropertyName)
    Reporter.ReportEvent 4"WebElement_CheckStringExistance""Checking for string value "& InpPropertyvalue
    Reporter.ReportEvent micPass,"WebElement_CheckStringExistance","Webelement  with Property " & InpPropertyName & "Property Value " & InpPropertyvalue & "Found"
    If instr(1,strvalue, strValueToverify) > 0Then
     Reporter.ReportEvent micPass,"WebElement_CheckStringExistance","String with value " & strValueToverify &"Found in webelement"
     WebElement_CheckStringExistance =0
    else
     Reporter.ReportEvent micfail,"WebElement_CheckStringExistance","String with value " & strValueToverify &"not found in webelement"
     WebElement_CheckStringExistance =1
    End If
   Else
    Reporter.ReportEvent 4"WebElement_CheckStringExistance""Checking for string value "& strValueToverify
    Reporter.ReportEvent micfail,"WebElement_CheckStringExistance","Webelement  with Property " & InpPropertyName & "Property Value " & InpPropertyvalue & "Found"
    WebElement_CheckStringExistance = 1
  End if
 End if
End Function

                                        Link to Mandatory QTP /UFT Interview Questions to read before Interview
 

2 comments: