Cucumber / Capybara测试不能告诉Jquery Autocomplete Forms Apart

时间:2013-02-14 16:40:57

标签: jquery ruby-on-rails-3 cucumber capybara

我的页面看起来像这样:

#reserve_new
= text_field_tag :autocomplete, '', :id => "agency_autocomplete", :class => [:title, :focus, :string, :required], placeholder: "agency name or ID", data: { search_type: "active_agency", selector: "#pre_executed_bond_number_set_agency_id"}
#results

#lookup_existing
= text_field_tag :autocomplete, '', :id => "agency_autocomplete", :class => [:title, :string, :required], placeholder: "agency name or ID", data: {selector: "#lookup_agency_id", results: "#results2"}
#results2

我有一个看起来像这样的测试:

when /^I look up pre\-executed numbers for that agency$/ do
  within "#lookup_existing" do
    autocomplete_selector = "#{agency.name} (#{agency.id}) :: #{agency.city}, #{agency.state}"
    step "I choose the \"#{autocomplete_selector}\" autocomplete option"
    click_button "Find"
  end
end

调用

When /^I choose the "(.*?)" autocomplete option$/ do |text|
  step "the page should not be an error page"
  find('ul.ui-autocomplete').should have_content(text)

  case Capybara.javascript_driver
  when :selenium
    find('.ui-menu-item a', text: /^#{Regexp.escape(text)}/).click
  when :webkit
    page.execute_script %Q{$('.ui-menu-item:contains("#{text}")').first().find('a').trigger('mouseenter').click();}
  end
end

当我注释掉#reserve_new或#lookup_existing时,测试通过,因为水豚不会感到困惑。但是,当我在同一页面上同时测试失败时。

我尝试过像

这样的事情
within("#reserve_new") do
  find('ul.ui-autocomplete').should have_content(text)
end

find("#reserve_new").find('ul.ui-autocomplete').should have_content(text)

并且所有示例都会导致失败,因为水豚/黄瓜正在错误的自动完成操作。

当我试图找到id并在其中执行时,它说它无法找到id。

有关尝试或破解的任何想法可能对此有用吗?

1 个答案:

答案 0 :(得分:0)

多次定义ID时,它不是有效的html!

:id => "agency_autocomplete"必须只有一次。

我猜这就是导致水豚失败的原因。