没有找到Rspec Capybara poltergeist Element

时间:2018-02-14 00:41:21

标签: rspec capybara poltergeist

Rspec - 3.7.1 poltergeist(1.17.0)

我有一个使用js运行的功能测试:true

它以

失败
Failure/Error:
       within(page.find('#by_category')) do
         select(category_2.name, from: 'q_category_id_eq')
       end

     Capybara::ElementNotFound:
       Unable to find visible css "#by_category"

rails_heper.rb我的设置就像这样

    Capybara.default_driver = :rack_test
require 'capybara/poltergeist'
options = { js_errors: true }
Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, options)
end

Capybara.javascript_driver = :poltergeist

我的考试

scenario 'they can seach books by category', js: true do
    visit root_url
    puts page.body
    within(page.find('#by_category')) do
      select(category_2.name, from: 'q_category_id_eq')
    end

    within(page.find('.category')) do
      expect(page).to have_content("#{category_2.name}")
    end
end

页面正文导致一个空页面,我也没有看到任何javascript错误。类别选择是通过更改AJAX调用完成的。

root to:'books #index'

0 个答案:

没有答案