2016-07-26 4 views
1

があります:RSpecの/カピバラ:奇妙な行動が見つからないの<input type = "隠し">が、それは間違いなく私は、次のスペック持っ

:ここ

within dom_id_selector(@boilerplate_copy) do 
    within '.copied_attributes_differing_from_original' do 
    within 'form.title[action="http://www.textdiff.com/"]' do 
     expect(page).to have_css 'button', text: 'Title' 
     expect(page).to have_css 'input[name="string1"]' 
     expect(page).to have_css 'input[name="string2"]' 
    end 
    end 
end 

は、問題のHTMLです最初have_css通過する間

(ボタンが見つかった)

<div class="copied_attributes_differing_from_original"> 
    <form action="http://www.textdiff.com/" class="title" method="post" target="_blank"> 
    <input name="string1" type="hidden" value="Boilerplate Original test title"> 
    <input name="string2" type="hidden" value="Boilerplate Copy test title"> 
    <button type="submit">Title</button> 
    </form> 

    <form action="http://www.textdiff.com/" class="success_criterion_id" method="post" target="_blank"> 
    <input name="string1" type="hidden"> 
    <input name="string2" type="hidden" value="1"> 
    <button type="submit">Success criterion</button> 
    </form> 

    // More of them... 
    <form action="http://www.textdiff.com/"... 
</div> 
は、第二 have_cssは失敗:

Failure/Error: expect(page).to have_css 'input[name="string1"]' 
    expected to find css "input[name=\"string1\"]" but there were no matches. Also found "", which matched the selector but not all filters. 

しかし、私の意見では、この要素は間違いなくそこにあります!私はまた、出力Also found "", which matched the selector but not all filters.を理解していない、それはどういう意味ですか?

ありがとうございます。

答えて

3

デフォルトでは、ユーザーは表示/非表示ができないため、非表示の要素(非表示の入力)は検出されません。あなたが本当に非可視要素の存在を確認する必要がある場合は、機能テストは、ページの機能は、それはあなたがかもしれないどのように動作するかを正確に詳細ではなく動作することをテストしなければならないので、

言われていること
expect(page).to have_css('input[name="string1"]', visible: false) 

を行うことができます隠された入力の存在をチェックするのではなく、機能が実装されていることを確認してください。

+0

ありがとうございます!あなたが正しいです、機能テストはブラックボックスでなければなりませんが、私は外部リソース(テスト範囲外)にデータを送信するフォームが存在することをテストしています。データは期待どおりに利用可能です。 –

+0

セレクタには一致したものの、すべてのフィルタではないものも考えていますか? –

+0

@JoshuaMuheim唯一の目に見えるビヘイビアは、カピバラの結果のフィルタとして実装されているため、CSSセレクタに一致する要素が見つかりましたが、可視性フィルタと一致しませんでした –

関連する問題