2017-07-10 23 views
-1

私はCapybaraを初めて使い、ドロップダウンリストのデフォルトオプションが前のページでクリックしたリンクによって変わるテストを作成しようとしています。例えばlink1をクリックすると、link1がデフォルトのオプションになります。Capybaraドロップダウンリストで無効なオプションをテストする方法

オンラインで、次の項目のドロップダウンで無効なオプションをテストすると言われましたが、まだ動作させることができません。あなたの説明に基づいて

Then /^"([^"]*)" should be selected for "([^"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector| 
    with_scope(selector) do 
    field_labeled(field).find(:xpath, ".//option[@selected = 'selected'][text() = '#{value}']").should be_present 
    end 
end 

答えて

1

私はあなたがselectedオプションではなく、disabledオプションを意味すると仮定しています。カピバラのそれは、あなたのようなものを呼ぶだろう

Then /^"([^"]*)" should be selected for "([^"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector| 
    within(selector) do 
    expect(page).to have_select(field, selected: value) 
    end 
end 

なるスコープの可能性があなたのキュウリのステップでそれを使用して

expect(page).to have_select('id, name, placeholder or label text of select', selected: 'text of selected option') 

なりません。

Then "California" should be selected for "State" within "#user_profile" 

あなたは本当にあなたが無効になってオプションを持っているかどうかをテストする場合は、

select = find(:select, 'id, name, placeholder or label text of select') 
expect(select).to have_selector(:option, 'text of disabled option', disabled: true) 
0
  1. のようにそれを行うことを選択で無効オプションをチェックしたいなかった場合。
  2. その領域を無効にする要素の数を検索します。コマンド「 」を使用してください。
  3. 結果が1または0の場合は、このコマンドを入力できます。

例:

And(/^All segments in this area need to be subject to the product (\d+) see it$/) do 
    area=find_by_id('temelGostergeler') 
    number=area.all("div#urunTab.caption[style='display: none;']").size 

    print "All of  " 

     expect(number).to eq 0 

    if 
    number==1 
    number="No product" 
    else 
    number="There are product" 
    end 
    p number 
end 

したい場合は、期待してコマンドを使用して同期することができます。

関連する問題