FirefoxDriver始终在“firstrun”页面上启动,打破所有测试脚本

时间:2015-12-03 15:00:52

标签: firefox selenium

刚刚从昨晚开始,FirefoxDriver一直在此页面上打开:https://www.mozilla.org/en-US/firefox/42.0/firstrun/learnmore/。我尝试更改默认配置文件设置但没有取得任何成功。

以下问题http://stackoverflow.com/questions/33937067/firefox-webdriver-opens-first-run-page-all-the-time是类似的,但是我没有看到在哪里实现这四行代码,而我个人试图将它放入我的脚本中的尝试被证明是徒劳的。

这个问题昨晚完全出乎问题。我今天要做演示,我无法让任何脚本工作。

像这样实例化我的WebDriver实例会导致NoSuchMethodError:

                FirefoxProfile profile = new FirefoxProfile();
                profile.setPreference("browser.startup.homepage", "about:blank");
                profile.setPreference("startup.homepage_welcome_url", "about:blank");
                profile.setPreference("startup.homepage_welcome_url.additional", "about:blank");
                driver = new FirefoxDriver(profile);
                driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

但是在profile中摆脱FirefoxDriver会将其带回上面提到的第一页。

4 个答案:

答案 0 :(得分:11)

当使用Selenium Webdriver和Poltergeist以及Firefox作为Rails应用程序的浏览器运行RSpec / Capybara测试时,我遇到了这个问题。尝试以各种方式重新配置Firefox无济于事,但通过简单地更新我的Gemfile(gem 'selenium-webdriver')中的selenium-webdriver gem来设法修复:

bundle update selenium-webdriver

归功于@lucetzer

答案 1 :(得分:3)

第一次运行页面遇到了同样的问题,经过一些搜索我发现这对我有用(我使用WebDriver 2.53.0和FF 45.0.1):

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.startup.homepage_override.mstone", "ignore");
profile.setPreference("startup.homepage_welcome_url", "about:blank");
profile.setPreference("startup.homepage_welcome_url.additional","about:blank");
profile.setPreference("browser.startup.homepage","about:blank");
WebDriver driver = new FirefoxDriver(profile);

答案 2 :(得分:2)

使用“Firefox.exe - p”

转到个人资料管理器

您将拥有多个个人资料。请选择默认配置文件并将其设置为默认值。

不应该打开该页面。我测试过,它工作正常。

您可以尝试使用此代码。我很确定它会起作用。

    ProfilesIni profile = new ProfilesIni();
    FirefoxProfile ffprofile = profile.getProfile("default");
    WebDriver driver = new FirefoxDriver(ffprofile);
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

答案 3 :(得分:0)

Mozilla主页的第一次运行启动画面中的证书存在问题。我在Bugzilla中为此提交了一张票:https://bugzilla.mozilla.org/show_bug.cgi?id=1269500

要在Selenium / Capybara / Cucumber中解决此问题,我们需要将新配置文件的默认主页更改为空白或其他页面。为此,请在配置中注册firefox / selenium驱动程序:

Capybara.register_driver :firefox do |app|
  profile = Selenium::WebDriver::Firefox::Profile.new
  profile['browser.startup.homepage_override.mstone'] = 'ignore'
  profile['startup.homepage_welcome_url.additional'] = 'about:blank'

  Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)
end