我目前正在为 Rails 应用程序中的消息传递系统编写 Cucumber 功能。这是我的步骤之一。
Then(/^they should see the message displayed in their language$/) do
id = "message_to_#{@family.id}"
expect(page).to have_selector("textarea##{id}")
save_and_open_page
expect(page).to have_field(id, type: :textarea)
end
第一个断言通过,但第二个断言失败。当我检查 save_and_open_page 创建的标记时,存在以下元素:
<textarea cols="22" disabled="disabled" id="message_to_13" name="body" placeholder="Hallo, Ich bin sehr interessiert an deinem Profil. Würdest du gerne mit mir in Kontakt treten?" rows="7"></textarea>
第二次测试显示的错误消息是:
expected to find field "message_to_13" but there were no matches. Also found "", which matched the selector but not all filters. (Capybara::ExpectationNotMet)
我在这里扯了扯头发,以了解为什么 Capybara 可以找到使用 have_selector 明显存在的这个元素,但不能使用 have_field?