Internet Explorer Operations used in QTP
The Below code illustrate the Internet Explorer Operations
‘$Filename: clsIE.vbs
‘$Description: class consists various IE browser operations
‘$Author: Deep Routhu
Class clsIE
‘@HELP
‘@description : This class provides methods for dealing with all possible operations on Internet Explorer.
‘@classvar: intCreationTime : It holds the Creationtime of the browser.
‘@classvar: blnLaunch : It holds boolean value to say whether browser is launched or not.
‘@classvar: strURL : It holds Browser URL.
‘@classvar: strVersion : It holds version of the IE browser.
‘@classvar: objBrowser : Description object for a browser.
‘@classvar: objPage : Descript object holds Page Object.
‘@END
Private intCreationTime
Private blnLaunch
Private strURL
Private strVersion
Private objBrowser
Private objPage
‘========================================================================================================================================================
Public Sub Class_Initialize()
‘ @HELP
‘ @class: clsIE
‘ @Constructor: Class_Initialize()
‘ @notes: This constructor will get invoked automatically and creates the discription objects for Browser, Page.
‘ @END
Set objBrowser = Description.Create()
objBrowser(“micclass”).Value = “Browser”
Set objPage = Description.Create ()
objPage(“micclass”).Value = “Page”
End Sub
‘========================================================================================================================================================
Public Property Get Launch()
‘@HELP
‘@class: clsIE
‘@method: Launch()
‘@returns: True/False
‘@notes: This function Launches browser at first and verifies whether it is launched or not.
‘@END
SystemUtil.Run “iexplore.exe”,WEB_URL
wait(WAIT_FOR_3)
If Browser(objBrowser,”creationtime:=”&intCreationTime).Dialog(“regexpwndtitle:=Security Alert”).Exist(WAIT_FOR_1) Then
Browser(objBrowser,”creationtime:=”&intCreationTime).Dialog(“regexpwndtitle:=Security Alert”).WinButton(“regexpwndtitle:=&Yes”).Click
wait(WAIT_FOR_3)
End If
If Browser(objBrowser,”Creationtime:=”&intCreationTime).Exist(WAIT_FOR_1 ) Then
blnLaunch = “True”
Else
blnLaunch = “False”
End If
Launch = blnLaunch
End Property
‘========================================================================================================================================================
Public Property Let SetCreationTime(intSession)
‘@HELP
‘@class: clsIE
‘@method: Launch(intSession)
‘@returns: None
‘@parameter: intSession: Creationtime of the browser
‘@notes: This property assigns creation time value to class variable i.e., intCreationTime
‘@END
intCreationTime=intSession
End Property
‘========================================================================================================================================================
Public Property Get Version()
‘@HELP
‘@class: clsIE
‘@method: Version()
‘@returns: Version of Internet Explorer
‘@notes: This function return the version of IE.
‘@END
Dim strComputer
Dim strKeyPath
Dim strValueName
Dim objReg
Dim strValue
Const HKLM=&H80000002
strComputer= “.”
strKeyPath=”SOFTWARE\Microsoft\Internet Explorer”
strValueName=”Version”
Set objReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\”&strComputer&”\root\default:StdRegProv”)
objReg.GetStringValue HKLM,strKeyPath,strValueName,strValue
strVersion = strValue
Version = strVersion
End Property
‘========================================================================================================================================================
Public Sub Refresh(intCreationTime)
‘@HELP
‘@class: clsIE
‘@method: Refresh(intCreationTime)
‘@returns: None
‘@parameter:intCreationTime: Creationtime of the IE
‘@notes: This function refresh the browser and clicks on ok button from popup window if exists.
‘@END
Browser(objBrowser,”creationtime:=”&intCreationTime).Refresh
If Browser(objBrowser,”creationtime:=”&intCreationTime).Dialog(“text:=Microsoft Internet Explorer”).Exist(WAIT_FOR_2) Then
Browser(objBrowser,”creationtime:=”&intCreationTime).Dialog(“text:=Microsoft Internet Explorer”).Winbutton(“regexpwndtitle:=&Retry”).click
Wait(WAIT_FOR_3)
End If
End Sub
‘========================================================================================================================================================
Public Sub DeleteTemporaryInternetFiles()
‘@HELP
‘@class: clsIE
‘@method: DeleteTemporaryInternetFiles()
‘@returns: None
‘@notes: This function Deletes Temporary Internet Files.
‘@END
Dim objShell
Dim strSuccess
SystemUtil.Run “Control.exe”,”inetcpl.cpl”
Set objShell = CreateObject(“Wscript.Shell”)
Do Until strSuccess = True
strSuccess = objShell.AppActivate(“Internet Properties”)
Wait(WAIT_FOR_1)
Loop
objShell.Sendkeys “%f”
Wait(WAIT_FOR_1)
objShell.Sendkeys “d”
Wait(WAIT_FOR_2)
objShell.Sendkeys “{ENTER}”
Wait(WAIT_FOR_3)
objShell.Sendkeys “{ENTER}”
Wait(WAIT_FOR_3)
Set objShell=Nothing
End Sub
‘========================================================================================================================================================
Public Sub Deletecookies()
‘@HELP
‘@class: clsIE
‘@method: Deletecookies()
‘@returns: None
‘@notes: This function deletes cookies
‘@END
Webutil.DeleteCookies
End Sub
‘========================================================================================================================================================
Public Sub Back(intCreationTime)
‘@HELP
‘@class: clsIE
‘@method: Back(intCreationTime)
‘@returns: None
‘@parameter:intCreationTime: Creationtime of the IE
‘@notes: This function clicks the back Button on Browser.
‘@END
Browser(objBrowser,”creationtime:=”&intCreationTime).Back
End Sub
‘========================================================================================================================================================
Public Property Get GetURL()
‘@HELP
‘@class: clsIE
‘@method: GetURL()
‘@returns: URL
‘@notes: This function returns the Application URL
‘@END
strURL=Browser(objBrowser,”creationtime:=”&intCreationTime).Page(objPage).GetROProperty(“url”)
GetURL=strURL
End Property
‘========================================================================================================================================================
Public Sub CloseAllBrowsersBeforeLogin(strBrowserName)
‘@HELP
‘@class: clsIE
‘@method: CloseAllBrowsersBeforeLogin()
‘@returns: None
‘@notes: This function closes all the Browsers expect QC browser
‘@END
Dim objDesc
Dim objBrColl
Dim intBrCount
Dim objBrowser
Dim strBrText
Set objDesc = Description.Create()
objDesc(“micclass”).value=”Browser”
Set objBrColl = Desktop.ChildObjects(objDesc)
intBrCount=objBrColl.Count()
For i=0 To intBrCount – 1
Set objBrowser=objBrColl.Item(i)
‘objBrowser.Highlight
strBrText=objBrowser.GetRoProperty(“text”)
Select Case strBrowserName
Case “IE”
If (Instr(1,strBrText,”Microsoft Internet Explorer”,1)) > 0 Then
If Not (Instr(1,strBrText,”Mercury Quality Center”,1)) > 0 Then
objBrowser.close
End If
End If
Case “FF”
If (Instr(1,strBrText,”Mozilla Firefox”,1)) > 0 Then
If Not (Instr(1,strBrText,”Mercury Quality Center”,1)) > 0 Then
objBrowser.close
End If
End If
End Select
Set objBrowser=Nothing
Next
Set objDesc=Nothing
Set objBrColl=Nothing
End Sub
‘========================================================================================================================================================
Public Sub Allowpopups ( )
‘@HELP
‘@class: clsIE
‘@method: Allowpopups()
‘@returns: None
‘@notes: This procedure allows popup blocker
‘@END
Dim objWshshell
Set objWshshell=CreateObject(“Wscript.shell”)
objWshshell.RegWrite “HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\New Windows\PopupMgr”,”yes”
Set objwshshell=Nothing
End Sub
‘========================================================================================================================================================
Public Sub Blockpopups ( )
‘@HELP
‘@class: clsIE
‘@method: Blockpopups ( )
‘@returns: None
‘@notes: This procedure block popup blocker
‘@END
Dim objWshshell
Set objWshshell = createobject(“Wscript.shell”)
objWshshell.RegWrite “HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\New Windows\PopupMgr”,”no”
Set objWshshell = Nothing
End Sub
‘========================================================================================================================================================
Public Sub CloseBrowser(intCreationTime)
‘@HELP
‘@class: clsIE
‘@method: CloseBrowser(intCreationTime)
‘@returns: None
‘@parameter: intCreationTime: Creationtime of the IE
‘@notes: This procedure closes IE browser
‘@END
Browser(objBrowser,”creationtime:=”&intCreationTime).close
End Sub
‘========================================================================================================================================================
Public Sub Quit(intCreationTime)
‘@HELP
‘@class: clsIE
‘@method: Quit(intCreationTime)
‘@returns: None
‘@parameter:intCreationTime: Creationtime of the IE
‘@notes: This function Quits from Browser
‘@END
Browser(objBrowser,”creationtime:=”&intCreationTime).WinToolbar(“regexpwndclass:=ToolbarWindow32″,”location:=0”).Press “&File”
Browser(objBrowser,”creationtime:=”&intCreationTime).WinMenu(“menuobjtype:=3”).Select “Close”
End Sub
‘=========================================================================================================================================================
Public Sub Class_Terminate()
‘ @HELP
‘ @class: clsIE
‘ @Constructor: Class_Terminate
‘ @notes: This Destructor will release description objects.
‘ @END
Set objBrowser = Nothing
Set objPage = Nothing
End Sub
‘=========================================================================================================================================================
End Class
‘Dim objclsIE
‘Set objclsIE=New clsIE