【问题标题】:Capybara.javascript_driver = :poltergeist not showing browser during testingCapybara.javascript_driver = :poltergeist 在测试期间不显示浏览器
【发布时间】:2013-11-08 10:43:05
【问题描述】:

我正在尝试使用 poltergeist 进行测试,但运行测试时未显示浏览器。

这是我的spec_helper.rb:

# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'rspec/page-regression'

require 'capybara/rspec'
require 'capybara/rails'
require 'capybara/poltergeist'
Capybara.register_driver :poltergeist do |app|
  #Capybara::Poltergeist::Driver.new(app, {debug: true, :timeout => 90})
  Capybara::Poltergeist::Driver.new(app, {debug: false, :default_wait_time => 30, :timeout => 90})
end
Capybara.javascript_driver = :poltergeist

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
  # == Mock Framework
  #
  # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
  #
  # config.mock_with :mocha
  # config.mock_with :flexmock
  # config.mock_with :rr
  config.mock_with :rspec

  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
  config.fixture_path = "#{::Rails.root}/spec/fixtures"

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, remove the following line or assign false
  # instead of true.
  config.use_transactional_fixtures = true
  # config.use_transactional_fixtures = false
  # If true, the base class of anonymous controllers will be inferred
  # automatically. This will be the default behavior in future versions of
  # rspec-rails.
  config.infer_base_class_for_anonymous_controllers = false

  config.include Capybara::DSL
end

# from http://stackoverflow.com/questions/8524839/sending-rails-errors-to-rspec-output
# to output all errors to rspec output
ActionController::Base.class_eval do
  def rescue_action(exception)
    raise exception
  end
end

我不知道我是否正确设置了Capybara.javascript_driver。

【问题讨论】:

  • 想看浏览器为什么要用poltergeist?来自webpage:“它允许您在无头 WebKit 浏览器上运行 Capybara 测试”。 Headless 表示“已配置为在没有监视器的情况下运行的设备”。
  • 听起来像是“按预期工作”。
  • 有时查看浏览器是有益的,这样您就可以确认测试中出了什么问题。是的,您可以通过控制台检查 DOM,然后重新组装所有内容——但这很乏味。浏览器显示通常在运行期间通过 ENV 标志完成

标签: ruby-on-rails rspec capybara poltergeist


【解决方案1】:

您不会看到浏览器。 Poltergeist 用于无头测试,这意味着它以编程方式呈现下面的所有内容,并以编程方式处理与页面的交互。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-29
    相关资源
    最近更新 更多