I am running my Selenium tests with WebDriver. I am repeating the tests with some loop so now I want to Clear the cache before starting new test in JAVA.
@Test
public void ffAndIe() throws InterruptedException {
int i = 0;
while(i < 5000){
driver.get("http://dit-map.appspot.com/");
Thread.sleep(15000);
driver.get("http://dit- map.appspot.com/#home:zoom=7&lat=37.04&lng=25.05&display=weather");
Thread.sleep(15000);
driver.get("http://dit-map.appspot.com/#home:zoom=9&lat=37.55&lng=23.83&display=weather,wind");
Thread.sleep(10000);
driver.get("http://dit-map.appspot.com/#home:zoom=9&lat=37.84&lng=23.22&display=weather,wind,cloud");
Thread.sleep(10000);
driver.get("http://dit-map.appspot.com/?lang=en#home:zoom=10&lat=38.13&lng=22.59&display=weather,wind,meteogram");
Thread.sleep(10000);
i++;
}
}
with in this while loop the first thing I want to do is to CLEAR my CACHE (IE, MOZILLA & CHROME)
any idea how can I achieve this?
Thanks
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.
clear( ) predefined method of Selenium 'WebDriver' Class is used to clear the text entered or displayed in the text fields. Now lets clear the text inside the Text Area field using the clear( ) predefined method of Selenium 'WebDriver' class.
We can reset or clear an edit box in Selenium with the help of clear() method. Code Implementation with clear().
We can delete cookies on all domains with Selenium. The method deleteAllCookies is used to delete all cookies from the present domain.
Currently, there is no way to clear the cache through the web driver API. However, if you can start a new instance of the browser each time, the cache should be cleared in FF and Chrome because a new profile is created on each launch.
The comments for issue #40 (Clear cache) in the Selenium issue tracker list two potential solutions to your problem if creating a new browser instance isn't possible:
HTH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With