Friday, 11 July 2014

Functionality which will check for a Dialog Box

Check an alert dialog box and the text from it

Hi guys, in this post I will try to describe step by step how to create a functionality which will check for a dialog box and will also click on button within it:




Firstly we will create a class which will be called on our need:
‘ creating the generic function
Public Function DialogBox
Set DialogBox = New QTPDialogBox
End Function


‘ defining the class
Class QTPDialogBox
Public Function CheckDialogBox (obj_DialogWindowId, obj_DialogWindowStyle, obj_StaticWindowId, obj_StaticText)
‘ defining the Dialog object’s properties
Set obj_Dialog = Description.Create  
obj_Dialog (“micclass”).value = “Dialog”
obj_Dialog (“nativeclass”).value = “#32770″
obj_Dialog (“text”).value= “Microsoft Internet Explorer”
obj_Dialog (“window id”).value= obj_DialogWindowId
obj_Dialog (“windowstyle”).value= obj_DialogWindowStyle
‘ defining the Static object’s properties
Set obj_Static = Description.Create  
obj_Static (“micclass”).value = “Static”
obj_Static (“window id”).value= obj_StaticWindowId
obj_Static (“text”).value= obj_StaticText
With Browser(“URL:=” & Environment.Value(“baseUrl”))
     .Sync
‘check if the dialog box exists
If .Dialog(obj_Dialog).Static(obj_Static).exist Then
‘ set a variable for the property  “text” of Static object to being compared with the inserted by user text  value
DialogMessage = .Dialog(obj_Dialog).Static(obj_Static).GetRoproperty(“text”)
Dim Comparison
If Comparison = StrComp(Trim(obj_StaticText), Trim(DialogMessage), 0)  Then
Reporter.ReportEvent micPass, “PASS”, “The Dialog box is present on the screen, and the text from it is: ‘” & DialogMessage & “‘, it is the same as: ‘”  & obj_StaticText & “‘”
‘ click OK in dialog box
.Dialog(obj_Dialog).WinButton(“text:=OK”, “regexpwndclass:=Button”, “window id:=2″).Click
Else
Reporter.ReportEvent micFail, “Fail”, “The Dialog box is present on the screen, and the text from it is: ‘” & DialogMessage & “‘, it is not the same as: ‘” & obj_StaticText “‘”
End If
Else
Reporter.ReportEvent micFail, “FAIL”, “There is no Dialog box present on the screen!”
End If
End with
End Function
End Class

[Notes]
Environment.Value(“baseUrl”) = it’s your URL, which is defined into a XML config file, for e.g.: http://google.com/.*; see the XML variable below:

<Variable>
<Name>baseUrl</Name>
<Value>http://google.com/.*</Value>
<Description>This variable  is used to identify the browser’s URL</Description>
</Variable>
In this XML file, we can also have the user name, password, and a lot of general data which can be also called when it need.
To create the descriptions for Static and Dialog objects, use the Object Repository Manager.

Now we can call this Function within our test as in the next sample:
‘ check if text is the right one in dialog box, and clikc on OK button
DialogBox.CheckDialogBox “0″, “-1798831675″, “65535″, “Functionality not implemented in this release”
‘ (obj_DialogWindowId, obj_DialogWindowStyle, obj_StaticWindowId, obj_StaticText)  — those are the properties added using Object Repository Manager

No comments:

Post a Comment