selenium / capybara-无法加载Firefox配置文件 [英] selenium / capybara - Firefox profile cannot be loaded

查看:109
本文介绍了selenium / capybara-无法加载Firefox配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用硒运行测试时,浏览器反复弹出,指出找不到Firefox配置文件。我已经准备好一个用于selenium的Firefox配置文件,只是不确定如何告诉selenium该配置文件所在的位置。

When I run tests using selenium the browsers repeatedly pops up stating that the firefox profile cannot be found. I have a prepared a Firefox profile for use with selenium I'm just not sure how to tell selenium where that profile located.

如何告诉Selenium哪个Firefox配置文件

How do I tell Selenium which firefox profile to use?

推荐答案

我遇到了同样的错误。对我来说,导致测试出现问题的原因是调用我的测试中的 save_and_open_page 。我删除了这些内容,并停止了Firefox配置文件错误。

I was getting this same error. For me it turned out that it was calls to save_and_open_page within my test that were causing the problem. I removed those and the Firefox profile errors stopped.

我还没有(只是)一个专门用于水豚/硒的特殊Firefox配置文件,但是,您的问题更加彻底,在尝试解决此问题时,我遇到了以下两种方法来为Firefox指定配置文件。

I haven't had any need (yet) for a special Firefox profile just for capybara/selenium, but, to answer your question more thoroughly, in trying to solve this problem I came across the following two methods to specify a profile for Firefox.

注意:这些方法实际上解决了我的配置文件错误问题,但自从您提出要求以来,无论如何我还是将它们包括在这里。

Note: Neither of these actually solved my problem with the profile errors but I'm including them here anyway, since you asked.

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

Method 1: (Requires each developer on project to setup special profile in Firefox.)

将以下内容添加到test_helper.rb

Add the following to your 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中设置特殊配置文件。)

Method 2: (Does not require each developer on project to setup special profile in Firefox.)

将以下内容添加到测试助手中。rb

Add the following to your test 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包括一个将拆卸任务设为<$ c的新驱动程序$ c> Capybara.use_default_driver ,如果您按照安装说明进行操作,则应该这样做。

Then, regardless of which above method you choose, set your default driver to the new driver, or selectively use the new driver by putting Capybara.current_driver = :my_firefox_driver at the beginning of your tests and ensuring that your test_helper.rb includes a teardown task to Capybara.use_default_driver which it should if you followed the setup instructions.

这篇关于selenium / capybara-无法加载Firefox配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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