Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

retaining cache in firefox and chrome browser - Selenium WebDriver

Currently our web application takes around 3 mins to load completely without caching and 10 secs with caching. When I open the app through WebDriver its taking around 3 mins to load i.e. caching is not used. I observed this on Firefox and Chrome browser. Not sure how to enabled the driver to use cache instead of loading each file from server every time I open the app.

Here are the things I tried. 1. disabled clearing cache on browser exit in browser setting. 2. set 'applicationCacheEnabled' desiredcapabilitiy to 'true'

DesiredCapabilities cap = DesiredCapabilities.firefox();

cap.setCapability("applicationCacheEnabled", "true");

WebDriver d = new FirefoxDriver(cap)

But nothing seems to work. Please let me know how can I make webdriver to use caching.

like image 439
Muthu Avatar asked Mar 27 '14 11:03

Muthu


People also ask

Does selenium clear cache?

Selenium does not provide a way to delete cache, here are some workarounds. There are a few ways in which cache can be deleted using Selenium Webdriver for regular Chrome browsers. For instance, here they explain how selenium can be used to clear cache like a real user i.e., by navigating to chrome settings.

Do browsers share cache?

The browsers do not share a cache, but plugins might. Like Adobe Flash keeps cross-browser history and "local shared objects", which can be used in a cookie-like way. Clearing a cache in a browser usually does not remove the information stored by such plugin.

Does selenium Webdriver store cookies?

When the code is executed, webdriver will store the cookie information using FileWriter Class to write streams of characters and BufferedWriter to write the text into a file named “Cookiefile. data“. The file stores cookie information – “Name, Value, Domain, Path”.


1 Answers

The problem is, that selenium copies every startup a new (firefox/chrome) profile to the temp directory and starts firefox/chrome with it. However, it is possible to always use the same profile for your test instances. I think this way you can get it working faster.

For firefox you just need to do these steps:
1. Load your webapp in a selenium firefox instance and don't close it afterwards (not driver.close();).
2. Then go to Help->Troubleshooting Information and open the folder under Profile folder.
3. Copy its content to a new folder near your test code.
4. Load the saved Profile in your test code. You can do it this way:

FirefoxProfile profile = new FirefoxProfile(new File("profile/folder/path"));                  
WebDriver driver = new FirefoxDriver(profile); 

I think you can do this in chrome analogous.

like image 147
Thorben Avatar answered Oct 11 '22 14:10

Thorben