There is a QTP Util method to delete browser cookies, but that works only for IE.
Deleting the cookies for firefox programatically is a little tricky, specially if there are multiple profiles that you are using, but here is a function to do just that.
Function funcDeleteCookies()
''Ignoring any errors that may arise during file deletion
On Error Resume Next
''This function will work best when firefox is closed
Call funcTerminateProcess("firefox.exe")
''Defining the list of files that need to be deleted to clear the cache
'' arrFileToDel = Array("compatibility.ini","cookies.sqlite","cookies.sqlite-shm","cookies.sqlite-wal","extensions.ini","extensions.sqlite","formhistory.sqlite","key3.db","localstore.rdf","permissions.sqlite","places.sqlite","places.sqlite-shm","places.sqlite-wal","prefs.js","sessionstore.bak","sessionstore.js","urlclassifierkey3.txt","webappsstore.sqlite")
arrFileToDel = Array("cookies.sqlite","cookies.sqlite-shm","cookies.sqlite-wal","formhistory.sqlite","places.sqlite","places.sqlite-shm","places.sqlite-wal","sessionstore.bak","sessionstore.js","localstore.rdf","formhistory.sqlite","key3.db")
''Getting the current logged in user, because the path is user specific
sUserName = Environment("UserName")
''Location of the firefox profile folder
sProfileFolderFox = "C:\Users\" & sUserName & "\AppData\Roaming\Mozilla\Firefox\Profiles"
Set oFolderFSO = CreateObject("Scripting.FileSystemObject")
If Not oFolderFSO.FolderExists(sProfileFolderFox) Then
Call funcLogger(micWarning, "The firefox cache folder could not be located", "Cache not cleared. " & sProfileFolderFox)
Else
''Getting all the sub folders
Set oChildFolders = oFolderFSO.GetFolder(sProfileFolderFox).SubFolders
''Looping for each of the sub folders
For Each oFolder In oChildFolders
sCurrFolderName = oFolder.Name
''Generally its enough to clear the cache from the default folder, which is what we are checking below
If InStr(1,LCase(sCurrFolderName),".default",1) Then
''Deleting the files
For i = 0 To UBound(arrFileToDel) - 1
oFolderFSO.DeleteFile(sProfileFolderFox & "\" & sCurrFolderName & "\" & arrFileToDel(i))
Next
End If
Next
End If
''Enabling errors again
On Error GoTo 0
End Function
Deleting the cookies for firefox programatically is a little tricky, specially if there are multiple profiles that you are using, but here is a function to do just that.
Function funcDeleteCookies()
''Ignoring any errors that may arise during file deletion
On Error Resume Next
''This function will work best when firefox is closed
Call funcTerminateProcess("firefox.exe")
''Defining the list of files that need to be deleted to clear the cache
'' arrFileToDel = Array("compatibility.ini","cookies.sqlite","cookies.sqlite-shm","cookies.sqlite-wal","extensions.ini","extensions.sqlite","formhistory.sqlite","key3.db","localstore.rdf","permissions.sqlite","places.sqlite","places.sqlite-shm","places.sqlite-wal","prefs.js","sessionstore.bak","sessionstore.js","urlclassifierkey3.txt","webappsstore.sqlite")
arrFileToDel = Array("cookies.sqlite","cookies.sqlite-shm","cookies.sqlite-wal","formhistory.sqlite","places.sqlite","places.sqlite-shm","places.sqlite-wal","sessionstore.bak","sessionstore.js","localstore.rdf","formhistory.sqlite","key3.db")
''Getting the current logged in user, because the path is user specific
sUserName = Environment("UserName")
''Location of the firefox profile folder
sProfileFolderFox = "C:\Users\" & sUserName & "\AppData\Roaming\Mozilla\Firefox\Profiles"
Set oFolderFSO = CreateObject("Scripting.FileSystemObject")
If Not oFolderFSO.FolderExists(sProfileFolderFox) Then
Call funcLogger(micWarning, "The firefox cache folder could not be located", "Cache not cleared. " & sProfileFolderFox)
Else
''Getting all the sub folders
Set oChildFolders = oFolderFSO.GetFolder(sProfileFolderFox).SubFolders
''Looping for each of the sub folders
For Each oFolder In oChildFolders
sCurrFolderName = oFolder.Name
''Generally its enough to clear the cache from the default folder, which is what we are checking below
If InStr(1,LCase(sCurrFolderName),".default",1) Then
''Deleting the files
For i = 0 To UBound(arrFileToDel) - 1
oFolderFSO.DeleteFile(sProfileFolderFox & "\" & sCurrFolderName & "\" & arrFileToDel(i))
Next
End If
Next
End If
''Enabling errors again
On Error GoTo 0
End Function
No comments:
Post a Comment