我的页面看起来像这样:
#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。
关于尝试的任何想法或可能有助于使其正常工作的技巧?