cancel
Showing results for 
Search instead for 
Did you mean: 

How to clear browser cache in firefox and chrome

Occasional Contributor

How to clear browser cache in firefox and chrome

Before I login to the application, I want the ability to clear the cache. This is because the passwords and urls etc are stored in cache and before I execute any tests, I need to ensure that the cache is cleared. I am writing in python script. Is it possible? If yes, how?

8 REPLIES 8
Community Hero

Re: How to clear browser cache in firefox and chrome

best thread for this would be https://community.smartbear.com/t5/TestComplete-Functional-Web/How-to-ClearCache-and-Cookies-from-In...


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”


Extension Available

Highlighted
Community Hero

Re: How to clear browser cache in firefox and chrome

Hi,

 

Besides the fantastic reply from @shankar_r (Shankar, thank you a lot for bringing this ages-old thread to the light!), there are recommended settings for web browsers (https://support.smartbear.com/testcomplete/docs/app-testing/web/general/preparing-browsers/index.htm...) and it is a good idea to have them been done on the test machines.

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Community Hero

Re: How to clear browser cache in firefox and chrome

@AlexKaras I am admiring wherever i see old threads there i see you in comments which insist me how much you are contributing for the peoples in the community to get away from automation headaches. Smiley Happy


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”


Extension Available

Occasional Contributor

Re: How to clear browser cache in firefox and chrome

Thanks a lot shankar_r. However this seems to be in a language I do not understand. Could you pls. convert it into python or give me some pointers. I tried googling it, but looks like I am making mistakes here and there.

 

Thanks,

Occasional Contributor

Re: How to clear browser cache in firefox and chrome

This is the code, I am trying to use:

 

def ClearAllChromeStoredInfo():

objFSO = CreateObject("Scripting.FileSystemObject")
strAppDataFolder = aqEnvironment.GetEnvironmentVariable(("LocalAppData") & "\Google\Chrome\User Data\Default")
FilesInFolder = objFSO.GetFolder(strAppDataFolder).Files
Log.Message(FilesInFolder)
FoldersInFolder = objFSO.GetFolder(strAppDataFolder).SubFolders
for Folder in FoldersInFolder:
if UCase(Folder.Name) = "EXTENSIONS" and LCase(Folder.Name) = "EXTENSION STATE"
Folder.Delete True
break
For File In range (FilesInFolder)
If Not UCase(File.Name) = "PREFERENCES"
File.Delete
break

 

The error I am getting is attached.

Community Hero

Re: How to clear browser cache in firefox and chrome

Hi,

 

I am not a Python expert. And not sure what line has #4, but maybe the slashes must be doubled? I.e.: "\\Google\\Chrome\\User Data\\Default" ?

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Visitor

Re: How to clear browser cache in firefox and chrome

Hi!

 

There is a workaround using Keys() method of browser Page object. Sorry, I'm not familiar with Python but in JScript it looks like following:

 

var browser = Sys.Find('ProcessName', 'chrome');

var page = browser.Page('http://yourpage.url/');

page.Keys("!^[Del]"); // Ctrl + Shift + Delete keys combination opens clear browser data dialog
SleepSeconds(2);

browser.Page('chrome://settings/clearBrowserData').Keys("[Enter]"); // hit Enter in clear browser data dialog
SleepSeconds(2);
browser.Page('chrome://settings/').Close(); // close settings page after clearing browsing data

page.Keys('[F5]');

Occasional Contributor

Re: How to clear browser cache in firefox and chrome

Aside the fact, that the question is a little bit older, here a solution in python for chrome I made for my tests. If you have some ideas to make it more elegant or effective or if you see errors, feel free to refactor it

 

Remark: on my system all the chrome stuff is in Roaming, so I use AppData instead of LocalAppData

 

def clear_stored_info_chrome():
    excluded_items = [item.upper() for item in [
                          r"Preferences",
                          r"Origin Bound",
                          r"Extension"
                        ] 
                      ]
    found_items = [item.upper() for item in glob.glob(
                      os.path.join(
                        aqEnvironment.GetEnvironmentVariable("AppData"),
                        r"Google\Chrome\User Data\Default\*"
                      )
                    )
                  ]
    for item in found_items:
      is_excluded = [True for tag in excluded_items if tag in item]
      if not is_excluded:
        try:
          if os.path.isdir(item):
             shutil.rmtree(item, ignore_errors=True)
          else:
              os.remove(item)
        except BaseException as e: # I ignore errors of any kind, just a remark to Log
          Log.Message("clear chrome stored info: {} - {}".format(item, e))
 

 

New Here?
Join us and watch the welcome video:
Watch the new Interview