Gaurav
Gaurav

Reputation: 43

clearing chromedriver cache - java

Is there a way to clear chromedriver cache using a selenium API or a javascript?

I have already tried the following:

ChromeOptions options = new ChromeOptions();
                options.addArguments("user-data-dir=" + pathOfChromeProfile);
                //options.addArguments("-incognito");
                options.addArguments("-disable-cache");

                DesiredCapabilities capabilities = DesiredCapabilities.chrome();
                capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
                capabilities.setCapability(ChromeOptions.CAPABILITY, options);
                capabilities.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE, false);

I have also tried the Java Script I have to interact with an extension that is not available in Incognito and therefore it is not an option.

I will appreciate a similar solution for SafariDriver as well.

Upvotes: 2

Views: 4407

Answers (1)

ddavison
ddavison

Reputation: 29042

Yes - by using a fresh profile each time.

Each test should have its own WebDriver instance. Don't "share browsers." If you share browsers, the cache does not clear. Conversely, having each test launch its own browser - starts automatically with a fresh cache.

Upvotes: 3

Related Questions