Monday, November 30, 2009

Check if a particuar text is present on page or not.

In few of scenarios we have to check that text is present on a page or not.

The following function will return True in case if text exists else function will return False.

'Create Page object
set objpage = Browser(“Browser Prop”).Page(“Page Prop”)

'Calling the function
msgbox VerifyTextOnPage(objParent ,”Test” )

Function VerifyTextOnPage(byval objpage , byval Textvalue )
On error resume next
Set oDesc= Description.Create()
oDesc(“micclass”).value=”WebElement”
oDesc(“html tag”).value=”.*[A-Za-z0-9].*”
oDesc(“outertext”).value =”.*[A-Za-z0-9].*”

'Create ALL child object
set collItems= objpage.ChildObjects(oDesc)

'Get all text from web page and store in a variable

For i=1 to collItems.count
OutPutText= OutPutText & collItems.Item(i).GetROProperty(“outertext”)
Next

'compare the text

If instr(1,lcase(OutPutText),lcase(Textvalue)) > 0 Then

' return true if found

VerifyTextOnPage= True
Else
rem return true if not found
VerifyTextOnPage= False
End If
On Error GoTo 0
End Function

Tuesday, November 24, 2009

Get Mouse Over Color of a Link

Using ReplayType setting to Mouse Events while firing an onMouseOver event on the link.

You will see that the hover event is triggered with the ReplayType set to Mouse Events:

Setting.WebPackage("ReplayType") = 2
Browser("xyz").page("xyz").Link("xyz").FireEvent "onMouseOver"
MsgBox Browser("xyz").page("xyz").Link("xyz").Object.currentStyle.color
Setting.WebPackage("ReplayType") = 1


Or

Function GetoverColor(oLink)
Setting.WebPackage("ReplayType") = 2
oLink.FireEvent "onMouseOver"
GetoverColor = oLink.Object.currentStyle.color
Setting.WebPackage("ReplayType") = 1
End Function

Wednesday, December 17, 2008

How to capture error screen-shot in Result Viewer

How to capture error screen-shot in Result Viewer

Dim path_error_file
path_error_file = "C:\Documents and Settings\Desktop\error.bmp"
Browser("Browser").CaptureBitmap path_error_file,True

Reporter.ReportEvent micFail, Object_snap,
"&"

How to capture a tool tip text of a link in QTP?

How to capture a tool tip text of a link in QTP?

This QTP tutorial shows and explains How to get tool tip in QuickTest Professional.

Actually, this is not a difficult task. The steps are:
1.Place mouse cursor over the link
2.Wait for tool tip
3.Get text of shown tool tip
This QTP script captures a text of a tool tip:
' Place mouse cursor over the link

Browser("Yahoo!").Page("Yahoo!").WebElement("text:=My Yahoo!").FireEvent "onmouseover"
wait 1
' Grab tooltip
ToolTip = Window("nativeclass:=tooltips_class32").GetROProperty("text")

Register User Function.

Register User Function

Suppose that the FindFlights Web page contained a Country edit box, and by default, the box contained the value USA. The following example registers the Set method to use the MySet function in order to report the default value of the edit box to the test results before the new value is entered. The UnRegisterUserFunc method is then used to return the Set functionality to the standard QuickTest functionality.
Function MySet (obj, x)
dim y
y = obj.GetROProperty("value")
Reporter.ReportEvent micDone, "previous value", y
MySet=obj.Set(x)
End Function
RegisterUserFunc "WebEdit", "Set", "MySet"
Browser("MercuryTours").Page("FindFlights").WebEdit("Country").Set "Canada"
UnRegisterUserFunc "WebEdit", "Set"