selenium / capybara – 无法加载Firefox个人资料

当我使用selenium运行测试时,浏览器会反复弹出声明无法找到firefox配置文件。 我准备了一个与selenium一起使用的Firefox配置文件我只是不确定如何告诉selenium该配置文件所在的位置。

如何告诉Selenium使用哪个firefox配置文件?

我得到了同样的错误。 对我来说,事实certificate,在我的测试中调用了save_and_open_page导致问题。 我删除了那些,Firefox配置文件错误停止了。

我还没有任何需要(仅)for capybara / selenium的特殊Firefox配置文件,但是,为了更彻底地回答你的问题,在尝试解决这个问题时,我遇到了以下两种方法来为Firefox指定配置文件。

注意:这些都没有解决我的配置文件错误的问题,但我还是把它们包括在这里,因为你问过。

方法1 🙁要求项目中的每个开发人员在Firefox中设置特殊配置文件。)

将以下内容添加到test_helper.rb中

 Capybara.register_driver :my_firefox_driver do |app| Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => 'name_of_existing_profile') end 

方法2 🙁不要求项目中的每个开发人员在Firefox中设置特殊配置文件。)

将以下内容添加到测试helper.rb中

 require 'selenium-webdriver' ... Capybara.register_driver :my_firefox_driver do |app| profile = Selenium::WebDriver::Firefox::Profile.new Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile) end 

然后,无论您选择上述哪种方法,都可以将默认驱动程序设置为新驱动程序,或者在测试开始时将Capybara.current_driver = :my_firefox_driver并确保test_helper.rb包含拆卸任务,从而有选择地使用新驱动程序到Capybara.use_default_driver它应该遵循设置说明。

要在Ruby中执行此操作需要大量调查,但我得到了它的工作。

首先,使用-p标志启动Firefox以选择配置文件。 创建新的配置文件并将其存储在项目中的某个位置。 在我的情况下,在“firefox_profile”目录中。 之后你需要给Selenium一个提示,找到这个配置文件的位置,为此你可以修补layout_on_disk方法:

 module Selenium module WebDriver module Firefox class Profile def layout_on_disk firefox_profile = File.expand_path(File.join(File.dirname(__FILE__),'firefox_profile')) profile_dir = create_tmp_copy(firefox_profile) FileReaper << profile_dir install_extensions(profile_dir) delete_lock_files(profile_dir) delete_extensions_cache(profile_dir) update_user_prefs_in(profile_dir) puts "Using temporary Firefox profile in: #{profile_dir} from #{firefox_profile}" profile_dir end end end end end 

作为Gist在这里

我也遇到了这个问题,结果certificate它与Firefox配置文件无关。 在我的例子中,我用于PhantomJS的Ghostdriver版本和我用于FirefoxDriver的Selenium版本之间的类路径不兼容(我试图设置我的代码以允许两者)。 删除Ghostdriver依赖项并注释掉PhantomJS代码会使此配置文件错误消失。 真的,如果我已经阅读了它给我更密切的错误消息,我会看到由于类不兼容而导致配置文件错误的根本原因是缺少方法。 具体错误是这样的:

NoSuchMethodError:org.openqa.selenium.os.CommandLine.waitFor(J)V

我在Firefox更新后遇到此错误。

我手动打开Firefox,允许它应用更新,然后测试工作。