如何在Selenium测试中清除浏览器缓存 [英] How to clear browser cache in Selenium test

查看:804
本文介绍了如何在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:


  1. 从命令中清除IE缓存

  2. 停用FF缓存使用自定义配置文件

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

HTH

这篇关于如何在Selenium测试中清除浏览器缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆