在Firefox和Chrome浏览器中保留缓存 - Selenium WebDriver

Mut*_*thu 13 firefox selenium caching google-chrome

目前,我们的Web应用程序需要大约3分钟才能完全加载而不需要缓存,10秒使用缓存.当我通过WebDriver打开应用程序时,需要大约3分钟来加载,即不使用缓存.我在Firefox和Chrome浏览器上观察到了这一点.不确定如何启用驱动程序使用缓存,而不是每次打开应用程序时从服务器加载每个文件.

这是我尝试过的东西.1.在浏览器设置中禁用浏览器退出时清除缓存.2.将'applicationCacheEnabled'设置为'true'

DesiredCapabilities cap = DesiredCapabilities.firefox();

cap.setCapability("applicationCacheEnabled", "true");

WebDriver d = new FirefoxDriver(cap)
Run Code Online (Sandbox Code Playgroud)

但似乎没有任何效果.请让我知道如何使webdriver使用缓存.

Tho*_*ben 8

问题是,selenium会将每个启动创建一个新的(firefox/chrome)配置文件复制到temp目录,并使用它启动firefox/chrome.但是,可以始终为测试实例使用相同的配置文件.我认为这样你可以让它更快地运作.

对于firefox,您只需要执行以下步骤:
1.将您的webapp加载到selenium firefox实例中,之后不要关闭它(不是driver.close();).
2.然后转到帮助 - >疑难解答信息并打开" 配置文件 "文件夹下的文件夹.
3.将其内容复制到测试代码附近的新文件夹中.
4.在测试代码中加载保存的配置文件.你可以这样做:

FirefoxProfile profile = new FirefoxProfile(new File("profile/folder/path"));                  
WebDriver driver = new FirefoxDriver(profile); 
Run Code Online (Sandbox Code Playgroud)

我认为你可以用类似的铬做到这一点.