---
title: "Selenium WebDriver 获取 existing Cache？"
author: "guiven"
date: "2011-11-22T17:01:24Z"
tags: []
categories: ["互联网"]
slug: "selenium-webdriver-existing-cache"
draft: false
lastmod: "2011-11-22T17:01:24Z"
id: 1272995
url: "https://guiven.iteye.com/blog/1272995"
---

采用Selenium2 作为Web前段测试工具，跑测试脚本的时候遇到的问题是这样的：

 

比如进行10遍browser测试，在每次测试完成后，driver.quit()，关闭浏览器再重新开启后，对于IE，Cache会继续存在。所以对于需要Cache的测试，这样的Situation是满足的。

 

然而换成了Firefox后，FirefoxDriver目前采取的策略默认是新建profile。

即使将其设置为customer profile

 

```
	FirefoxProfile profile = new ProfilesIni().getProfile("MySelenium"); 
        DesiredCapabilities cap = DesiredCapabilities.firefox(); 
        cap.setCapability(FirefoxDriver.PROFILE, profile); 
        WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), cap); 
```

 FirefoxDriver也是依旧拷贝一份，这样可以使用该profile的cookie等，但却依然无法使用Cache。这就对测试造成了困扰，暂时不知如何解决。

 

还有一个问题就是对于run多次的脚本（脚本包含多个Transaction），如果在前几次运行，如出现Web Element的问题，我希望在后几次的脚本运行时可注释掉这些有问题的transaction（可将这些行为记入log），不知如何实现。或者也可采用其他方式。十分大家能够不吝赐教。