【问题标题】:Creating Firefox profile and switching off the marionette创建 Firefox 配置文件并关闭木偶
【发布时间】:2018-05-04 09:21:03
【问题描述】:

我来自Ruby背景,我知道如何在Ruby Selenium Binding中做到这一点,但我不知道如何做到Java Selenium Binding,

我有这个代码来创建 Firefox 配置文件

 FirefoxProfile firefoxProfile = new FirefoxProfile(pathToProfile);
 WebDriver driver=new FirefoxDriver(firefoxProfile);

它在 selenium 2.53 中有效,但在最近的 selenium 绑定 3.11.0 中抛出错误,谁能告诉我有什么替代方案?

我还想关闭木偶以连接到旧版 Firefox 驱动程序,我可以使用以下代码完成此操作

DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", false);
WebDriver driver=new FirefoxDriver(capabilities);

但如果我使用上面的行,那么它会给出 FirefoxDriver 已被弃用。谁能指导我如何创建个人资料以及如何关闭木偶?

【问题讨论】:

  • 如果您愿意考虑其他答案,请告诉我。
  • @DebanjanB 当然,请继续!

标签: java selenium selenium-webdriver


【解决方案1】:

是的 FirefoxDriver(desiredCapabilities) 已弃用。

替代方法是使用 options

FirefoxOptions foptions =  new FirefoxOptions(capabilities);
WebDriver driver=new FirefoxDriver(foptions);  

更新:[按顺序]

FirefoxOptions foptions =  new FirefoxOptions();
FirefoxProfile firefoxProfile = new FirefoxProfile(pathToProfile);
foptions.setProfile(firefoxProfile);
foptions.setCapability("marionette", false);
foptions.setBinary("C:\\Program Files\\Mozilla Firefox 52\\firefox.exe"); 
WebDriver driver = new FirefoxDriver(foptions);

【讨论】:

  • 现在如何传递profile参数?第一个问题。
  • 如何将两者结合起来?需要传递 Firefox 配置文件和 foptions(您的示例变量)?
  • 您可以选择并设置功能!
  • 你能订线吗?
  • 你想要的顺序是什么?
【解决方案2】:

要将现有的 Firefox 配置文件 用于您的 测试执行,首先您必须按照 Creating a new Firefox profile on Windows 的说明手动创建 Firefox 配置文件 .现在您必须将 Firefox 配置文件 传递给 FirefoxOptions 类对象。此外,您将使用 旧版 Firefox 浏览器 您必须通过 DesiredCapabilities 类对象将 ma​​rionatte 设置为 false,您需要将 merge() 设置为 FirefoxOptions 类对象如下:

System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile testprofile = profile.getProfile("debanjan");
FirefoxOptions options = new FirefoxOptions();
options.setProfile(testprofile);
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("marionatte", false);
options.merge(dc);
WebDriver driver = new FirefoxDriver(options);
driver.get("https://www.google.com");

更新

我不确定您的用例以及您为什么要使用旧版 Firefox 驱动程序。但根据 GitHub 讨论 Unable to Start Firefox Using the Legacy Driver on a 3.5.3 Grid@jimevans 明确提到:

旧版 Firefox 驱动程序不适用于 Firefox 53 左右。您可能会启动浏览器,但语言绑定将完全无法与驱动程序通信(因为 Firefox 将拒绝加载作为旧版 Firefox 驱动程序的浏览器扩展)。

@barancev 还提到:

绑定不应在“功能”块中传递符合 W3C 的有效负载部分中的 OSS 功能。仅允许在“desiredCapabilities”块中使用它们。也许,Mozilla 在发布通道中破坏了 Firefox 48 中的 Selenium 兼容性,但在 esr 通道中的版本 52 中恢复了它。这是出乎意料的,但这是真的。

您可以做出明智的决定。

【讨论】:

  • 第一行不是必须的,对吧?因为我们使用的是旧版驱动程序?
  • 但是如果必须使用 Legacy 驱动,那么第一行不是必须的,嗯?
  • @Rajagopalan Legacy Driver 不需要第一行,但如果没有 GeckoDriver 我不确定是否 Legacy Driver 将与 Selenium 3.11.0 和功能兼容,例如merge()。请更新我的状态。
  • 我一直在使用 WATIR,它正在使用最近的 Ruby Selenium Binding,它对我来说很好。
  • @Rajagopalan 不会评论 watirimplementation。我添加了来自 Selenium FactorySelenium Committers 的 cmets 的更新。让我了解最新状态。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多