1

私のページの入力フィールド#graph_start_dateにjqueryuidatepickerがあります

私は次のキュウリのステップを書き込もうとしています

When I click the graph start date
Then I should see a datepicker

ステップ定義については、次のとおりです。

When /I click the graph start date/ do
  find(".//*[@id='graph_start_date']").click
end

Then /^I should see a datepicker$/ do
  page.should have_xpath(".//div[@id='ui-datepicker-div' and ?????????]")
end

jqueryuidatepickerは最初にDOMに挿入されます

<div class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all ui-helper-hidden-accessible" id="ui-datepicker-div"></div>

そのポップアップがドームに含まれているとき

<div class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all ui-helper-hidden-accessible" id="ui-datepicker-div" style="position: absolute; top: 523px; left: 167.5px; z-index: 1;">

その却下された後、domには含まれています

<div class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all ui-helper-hidden-accessible" id="ui-datepicker-div" style="position: absolute; top: 523px; left: 167.5px; z-index: 1; display: none;">
4

3 に答える 3

3

そのよう:visible => trueに文書化されているオプションがありますCapybara::Node::Matchers#has_xpath?

Then /^I should see a datepicker$/ do
  page.should have_xpath(".//div[@id='ui-datepicker-div']", :visible => true)
end

ただし、これは別の問題である可能性がありますが、私にとっては、カピバラ駆動のブラウザーにフォーカスがない場合、日付ピッカーがまったく表示されないため、テストが失敗します(時々)

編集:

まず第一に、datepickerは実際にはフィールドのクリックをトリガーすることを望んでいないようですが、残念ながらcapybaraのセレンドライバーではサポートされていないフォーカスであり、クリックをトリガーしてもトリガーされませんが、ブラウザーにはフォーカスがありません。

フォーカスをトリガーする正しい方法は次のとおりです。

find(".//div[@id='ui-datepicker-div']").trigger('focus')

しかし、それはCapybara::NotSupportedByDriverError:(

回避策として、ハックを使用できます。

When /I focus the graph start date/ do
  page.execute_script("$('#graph_start_date').focus()")
end

(ありがとう: http: //groups.google.com/group/ruby-capybara/msg/af6caeef01d978b0

Googleグループでは、これに関するさまざまな議論と関連する問題があります。

于 2011-12-21T13:33:22.220 に答える
0

#focussフィールドを実行し、アンカーの1つをクリックするだけで、capybaraに正しい値がフィールドにあることを確認させます。

于 2010-11-17T01:54:16.950 に答える
0

私は今朝同じ問題に遭遇していました、そしてこれが私がそれを修正した方法です。

私の機能ファイルで

@javascript # You need this javascript tag 
Scenario:Adding a date to a job 
  When I go to enter a date 
  Then I should see a date picker appear

私のステップ定義では:

When /^ I go to enter a date$/ do 
  element = find_by_id("you_date_field_id") 
  element.click 
end

The /^I should see a date picker appear$/ do 
  date = find(:xpath, "//div[@id='ui-datepicker-div']") 
end

お役に立てれば

于 2012-03-18T23:19:06.327 に答える