如何在Selenium测试中清除浏览器缓存
我正在使用WebDriver运行我的Selenium测试。我正在用一些循环重复测试,所以现在我想在JAVA中开始新的测试之前清除缓存。
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++;
}
}
在这个while循环中我想要的第一件事做的是清除我的CACHE(IE,MOZILLA& CHROME)
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?
谢谢
目前,无法通过Web驱动程序API清除缓存。但是,如果您每次都可以启动浏览器的新实例,则应在 FF中清除缓存和 Chrome ,因为每次发布都会创建新的个人资料。
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.
问题#40的评论(如果无法创建新的浏览器实例,Selenium问题跟踪器中的清除缓存)列出了两个潜在的解决方案:
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:
- 从命令中清除IE缓存
- 停用FF缓存使用自定义配置文件
- Clear the IE cache from the command line
- Disable the FF cache using a custom profile
HTH