user1226162
user1226162

Reputation: 2042

How to clear browser cache in Selenium test

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

Upvotes: 13

Views: 46634

Answers (3)

Tosyneno
Tosyneno

Reputation: 41

I have used this lines of code in python to do that and it seems to clear the cache every time(Internet Explorer)

capab = DesiredCapabilities.INTERNETEXPLORER

capab.clear()

Upvotes: 0

Jonathan McIntire
Jonathan McIntire

Reputation: 2675

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:

  1. Clear the IE cache from the command line
  2. Disable the FF cache using a custom profile

HTH

Upvotes: 14

David
David

Reputation: 1709

DT_IE_AGENT_ACTIVE=true activates the Add-On so that it collects data from the current browser session

Hope it help

Upvotes: 0

Related Questions