当我使用Selenium运行测试时,浏览器反复弹出,指出找不到Firefox配置文件。我已经准备了一个用于Selenium的Firefox配置文件,但是我不确定如何告诉Selenium该配置文件在哪里。
我应该如何告诉Selenium使用哪个Firefox配置文件?
我应该如何告诉Selenium使用哪个Firefox配置文件?
save_and_open_page
导致的。我删除它们后,Firefox配置文件错误停止了。Capybara.register_driver :my_firefox_driver do |app|
Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => 'name_of_existing_profile')
end
方法二:(不需要项目中的每个开发人员在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包括一个tearDown任务以Capybara.use_default_driver
这应该是如果您按照设置说明操作的话。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
我也遇到了这个问题,最后发现与Firefox配置文件无关。在我的情况下,是因为Ghostdriver的版本与PhantomJS不兼容以及Selenium的版本与FirefoxDriver不兼容(我尝试设置我的代码以允许两者同时使用)导致了classpath不兼容性。移除Ghostdriver依赖项并注释掉PhantomJS代码可以解决此配置文件错误。实际上,如果我更仔细地阅读它给我的错误消息,我会发现配置文件错误的根本原因是由于类不兼容而导致的缺少方法。具体错误信息类似于:
NoSuchMethodError: org.openqa.selenium.os.CommandLine.waitFor(J)V