在Firefox和Chrome浏览器中保留缓存 - Selenium WebDriver [英] retaining cache in firefox and chrome browser - Selenium WebDriver

查看:1990
本文介绍了在Firefox和Chrome浏览器中保留缓存 - Selenium WebDriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

  DesiredCapabilities cap = DesiredCapabilities.firefox(); 

cap.setCapability(applicationCacheEnabled,true);

WebDriver d = new FirefoxDriver(cap)

。请让我知道如何使webdriver使用缓存。解决方案问题是,硒复制每一个启动一个新的(())/ / firefox / chrome)配置文件到临时目录,并启动firefox / chrome。
但是,总是可以对您的测试实例使用相同的配置文件。
我认为这样你可以更快的工作。

对于firefox你只需要执行以下步骤:

1. Load你的webapp在一个selenium firefox实例中,不要关闭它(而不是 driver.close(); )。
2.然后转到 Help-> Troubleshooting信息并打开个人资料文件夹下的文件夹。

3.将其内容复制到您的测试代码附近的新文件夹。

4。在测试代​​码中加载保存的配置文件。您可以这样做:

  FirefoxProfile profile = new FirefoxProfile(new File(profile / folder / path)); 
WebDriver driver = new FirefoxDriver(profile);

我认为您可以在chrome中做到这一点。


Currently our web application takes around 3 mins to load completely without caching and 10 secs with caching. When I open the app through WebDriver its taking around 3 mins to load i.e. caching is not used. I observed this on Firefox and Chrome browser. Not sure how to enabled the driver to use cache instead of loading each file from server every time I open the app.

Here are the things I tried. 1. disabled clearing cache on browser exit in browser setting. 2. set 'applicationCacheEnabled' desiredcapabilitiy to 'true'

DesiredCapabilities cap = DesiredCapabilities.firefox();

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

WebDriver d = new FirefoxDriver(cap)

But nothing seems to work. Please let me know how can I make webdriver to use caching.

解决方案

The problem is, that selenium copies every startup a new (firefox/chrome) profile to the temp directory and starts firefox/chrome with it. However, it is possible to always use the same profile for your test instances. I think this way you can get it working faster.

For firefox you just need to do these steps:
1. Load your webapp in a selenium firefox instance and don't close it afterwards (not driver.close();).
2. Then go to Help->Troubleshooting Information and open the folder under Profile folder.
3. Copy its content to a new folder near your test code.
4. Load the saved Profile in your test code. You can do it this way:

FirefoxProfile profile = new FirefoxProfile(new File("profile/folder/path"));                  
WebDriver driver = new FirefoxDriver(profile); 

I think you can do this in chrome analogous.

这篇关于在Firefox和Chrome浏览器中保留缓存 - Selenium WebDriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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