加载配置文件时,Selenium 测试需要几分钟才能启动

问题描述 投票:0回答:2

我只是想弄清楚是否有其他人看到他们的 Selenium 测试在将配置文件加载到 FirefoxDriver 时运行速度明显变慢(需要 2 分钟以上才能启动),如下所示: Selenium 是 Firefox 的默认配置文件

上述帖子的问题发起者在评论中提到了这个问题,但从未更新他是否修复了这个缓慢问题。

在某些时候,我的测试停止一起运行,我开始收到错误

org.openqa.selenium.WebDriverException: java.io.Exception: unexpected end of stream on Connection. 

如果我从 FirefoxDriver 调用中删除配置文件选项,则测试将在选择“RUN”后 5 秒内运行,但测试失败,因为 Selenium 使用的默认配置文件没有我访问站点所需的证书。

还有其他人有同样的情况或知道如何解决这个问题吗?如何调整配置文件中保存的信息量?

  • 火狐版本:60.3.0
  • 硒版本:3.14.0
  • Gecko驱动程序版本:0.23.0
  • 操作系统:Linux Redhat 6
  • Eclipse 版本:Neon

代码:

WebDriver browser;
System.setProperty("webdriver.gecko.driver", "/path/to/geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.get("SeleniumUser");
FirefoxOptions options = new FirefoxOptions().setProfile(ffprofile);
browser = new FirefoxDriver(options); // takes a long time and eventually fails here
browser.get("site.url");

如果您从新的 FirefoxDriver() 调用中取出 {options} 参数,测试将在大约 5 秒内开始。 保留选项会导致错误“org.openqa.selenium.WebDriverException:java.io.Exception:连接上的流意外结束”,如上所述。

java selenium firefox geckodriver firefox-profile
2个回答
2
投票

当您启动通过

GeckoDriver
加载新/现有 FirefoxProfile 的过程时,底层框架包括:

  • 驱动程序(Selenium 绑定)
  • 服务器(GeckoDriver)
  • 客户端(Firefox 浏览器)

需要对内部不同模块进行初始化和互通。

您可以在

无法解析构造函数 FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile)
中找到有关如何通过 GeckoDriver 访问 FirefoxProfile

的详细讨论

另外保存的:

  • 书签
  • 密码
  • 用户偏好
当现有

FirefoxProfile

 加载时,也会加载 
。因此需要一些额外的时间。

您可以在 webdriver.FirefoxProfile() 中找到详细讨论:Is it possible to use a profile without make a copy of it?


0
投票

清理浏览数据将大大提高启动速度,但也会删除cookie和打开的会话,这是我不想要的。

我的解决方案是在 Selenium 启动期间开始复制配置文件之前以编程方式删除配置文件的缓存文件夹。

我已包含示例 C# 代码来执行此操作。

© www.soinside.com 2019 - 2024. All rights reserved.