0

我需要在我的应用程序中测试自动完成功能,但我遇到了一些问题。我正在使用这个脚本: http: //loopj.com/jquery-tokeninput/ 并遵循了本教程:http ://railscasts.com/episodes/258-token-fields

我尝试了一些类似的解决方案,但没有成功: http ://blog.aentos.com/post/1114672143/testing-ajax-autocomplete-fields-with-cucumber-and

黄瓜(场景):

When I fill in "token-input-article_tag_tokens" with "R"
Then I should see the following autocomplete options:
| Ruby |
And I click on the "Ruby" autocomplete option

水豚(步骤):

Then /^I should see the following autocomplete options:$/ do |table|
  table.raw.each do |row|
    page.should have_css('div.token-input-dropdown-facebook ul li', :text => "#{row[0]}")
  end
end

When /^I click on the "([^"]*)" autocomplete option$/ do |link_text|
  page.execute_script %Q{ $('.token-input-dropdown-facebook ul li:contains("#{link_text}")').trigger("mouseenter").click(); }
end

HTML(表单):

<div class="controls">
  <ul class="token-input-list-facebook">
    <li class="token-input-input-token-facebook">
      <input type="text" autocomplete="off" style="outline: none; width: 30px; " id="token-input-article_tag_tokens">
      <tester style="position: absolute; top: -9999px; left: -9999px; width: auto; font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-weight: normal; letter-spacing: normal; white-space: nowrap; "></tester>
    </li>
  </ul><input class="text_field" data-pre="[]" id="article_tag_tokens" name="article[tag_tokens]" size="30" type="text" style="display: none; ">
</div>

HTML(由 JQuery 生成的自动完成列表)

<div class="token-input-dropdown-facebook" style="display: block; position: absolute; top: 931px; left: 192px; ">
  <ul style="display: block; ">
    <li class="token-input-dropdown-item2-facebook token-input-selected-dropdown-item-facebook">
      <b>R</b>uby
    </li>
  </ul>
</div>

但是,当我运行 cucumber 时,我会遇到这个错误:

And I fill in "token-input-article_tag_tokens" with "R" 
  cannot fill in, no text field, text area or password field with id, name, or label 'token-input-article_tag_tokens' found (Capybara::ElementNotFound)
4

1 回答 1

1

对于你的问题,我有一个解决方案。也许它可以帮助某人

page.execute_script %Q{ $('li.token-input-dropdown-item2-facebook:first').trigger('mousedown') }
于 2013-06-21T11:05:22.673 回答