简体   繁体   English

水豚和Poltergeist测试失败

[英]Capybara and poltergeist test failing

I been using :firefox drivers for capyabara and this test was passing but when I switch to poltergeist driver the test been failing now with the following error: 我一直在使用:firefox驱动程序作为capyabara,并且该测试通过了,但是当我切换到poltergeist驱动程序时,该测试现在由于以下错误而失败:

Minitest::UnexpectedError: Capybara::ElementNotFound: Unable to find field "email" Minitest :: UnexpectedError:Capybara :: ElementNotFound:无法找到字段“电子邮件”

Here is the capybara and poltergeist setup: 这是水豚和poltergeist的设置:

  def setup
    # FactoryGirl.lint
    DatabaseCleaner.strategy = :truncation
    DatabaseCleaner.start
    Capybara.run_server = true
    Capybara.register_driver :poltergeist do |app|
      Capybara::Poltergeist::Driver.new(app, :js_errors => false)
    end

    Capybara.default_driver = :poltergeist
    Capybara.current_driver = :poltergeist
    Capybara.javascript_driver = :poltergeist
    Capybara.app_host = 'http://localhost:4200'
    Capybara.server_port = 3000
    Capybara.default_max_wait_time = 5
  end

Here is the test: 这是测试:

test "User should be able to signin" do
    visit '/'
    wait_for_ajax
    fill_in 'email', with: @user.email
    fill_in 'password', with: @user.password
    assert true
  end

So, when I changed the driver to :selenium the test pass with no error. 因此,当我将驱动程序更改为:selenium时,测试通过并没有错误。

How do I setup/fix poltergeist to pass this test? 如何设置/修复Poltergeist通过此测试?

I took screenshot and it shows loading indicator which is a div that is removed in afterModel Ember hook using the following code: 我拍了屏幕截图,它显示了加载指示器,它是使用以下代码在afterModel Ember挂钩中删除的一个div:

_ember['default'].$('.ember-load-indicator').remove();

For Ajax calls we have the following function as test helper to wait for ajax calls: 对于Ajax调用,我们具有以下功能作为测试助手来等待ajax调用:

  def wait_for_ajax
    Timeout.timeout(Capybara.default_wait_time) do
      loop until finished_all_ajax_requests?
    end
  end

  def finished_all_ajax_requests?
    page.evaluate_script('jQuery.active').zero?
  end

I suspect it's a timing issue... When using poltergeist vs a browser, you can get these weird behaviours, where an element is present, but not really loaded hence the error... An easy way to confirm this is by putting a sleep prior to fill_in email... put sleep 10 just to be safe... 我怀疑这是时间问题...使用poltergeist对比浏览器时,您会得到这些奇怪的行为,其中存在一个元素,但并未真正加载,因此出现了错误...一种简单的确认方法是通过入睡在填写电子邮件之前...为了安全起见,请sleep 10 ...

Additional tip: 附加提示:

To help debug headless tests, consider adding screenshots on failures - 为了帮助调试无头测试,请考虑添加有关失败的屏幕截图-

Add this to the end of your Capybara setup: 将其添加到水豚设置的末尾:

Capybara::Screenshot.register_filename_prefix_formatter(:rspec) do |example|
  "screenshot_#{example.description.gsub(' ', '-').gsub(/^.*\/spec\//,'')}"
end

screenshot_path = "#{PROJECT_ROOT}/screenshot/"
Capybara.save_and_open_page_path = screenshot_path

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM