capybara和click_on方法+ simple_form [javascript error]

时间:2017-03-13 13:51:14

标签: ruby-on-rails capybara simple-form

我使用minitest,capybara和poltergeist,这是要测试的simple_form:

<%= simple_form_for :search,  url: ads_path , wrapper: :inline_form, html: {class: 'form-inline'}, :method => :get do |f| %>
  <%= f.error_notification %>
  <%= f.input :type_id, collection: @types, label_html: {class: 'form_home'}, selected: 'house'%>
  <%= f.input :city, label: 'Where?', placeholder: 'What is the city ?'%>
  <br>
  <br>
  <%= f.submit "Search", :class => "btn btn-primary btn-xl page-scroll" %>
<% end %>

当我添加 click_on&#39;搜索&#39;

时,问题依赖于
 test "search correctly" do
    visit "/"
    select "house", :from => "search_type_id"
    fill_in 'search_city' , with: ""
    click_on 'Search'
  end

终端上的javascrip错误:

  

水豚::鬼驱:: JavascriptError:
  Capybara :: Poltergeist :: JavascriptError:引发了一个或多个错误   在页面上的Javascript代码中。如果你不关心这些   错误,你可以通过设置js_errors:false来忽略它们   Poltergeist配置(详见文档)。

    Error: Bounds are not valid.
    Error: Bounds are not valid.
        at http://127.0.0.1:43411/assets/application-1442915127e4fa1072f69aa9aa4d07ce85cdc5115df9b3a40da528ee05ebfe94.js:43537
        at http://127.0.0.1:43411/ads?utf8=%E2%9C%93&search%5Btype_id%5D=1&search%5Bcity%5D=&commit=Search:135
        test/integration/home_test.rb:16:in `block in <class:HomeTest>'

还有其他选择吗?

1 个答案:

答案 0 :(得分:0)

您有两个选项,修复您的JS或禁用错误消息中提到的JS错误报告。

要修复你的JS,首先要查看组合的JS系列43537,看看它为什么记录&#34; Bounds无效&#34;或者在开发模式下执行相同的操作,以确定哪个JS文件产生错误并从那里开始调试。

另一方面,如果您不关心修复错误原因(您应该关心它),那么您可以将驱动程序配置为不报告JS错误

@media print {
    td,td {
        display: table-cell !important
    }
}

如恶作剧自述文件中所述 - https://github.com/teampoltergeist/poltergeist#customization