3

だから私はシナリオを持っています:

Given I signed in to my business account
And there is one customer named "Samantha Seeley"
When I go to the customers management page
Then "Delete" should show a confirmation dialog saying "Are you sure?"

リンクは単純です:

<%= link_to 'Delete' customer_path(customer), method: :delete, confirm: 'Are you sure?' do %>

したがって、このコードでは、Chromeでリンクをクリックすると確認ダイアログが表示されますが、ページレンダリングを使用すると次のようになります。

Then /^"(.*?)" should show a confirmation dialog saying "(.*?)"$/ do |arg1, arg2|
  click_on arg1
  page.driver.render "tmp/screenshot.jpg"
end

スクリーンショットから、JavaScriptが評価されていないように見える(確認ダイアログが表示されていない)ことを確認できると思います。しかし、この仮定は間違っているかもしれませんが、私にはわかりません。

ご協力いただきありがとうございます。

4

1 に答える 1

5

GitHubでも同様の問題が発生しました:https ://github.com/thoughtbot/capybara-webkit/issues/84

結論は、このようなものを使用することでした。これは、JesseCookeKenCollinsによって提案されました。

def handle_js_confirm(accept=true)
  page.evaluate_script "window.original_confirm_function = window.confirm"
  page.evaluate_script "window.confirm = function(msg) { return #{!!accept}; }"
  yield
ensure
  page.evaluate_script "window.confirm = window.original_confirm_function"
end

これは確認ダイアログの内容をテストするのに役立ちませんが(簡単に拡張できますが)、ユーザーが[OK]または[キャンセル]をクリックしたときに何が起こるかをテストできます。

この特定のケースでは、確認ダイアログを生成するRailsヘルパーを使用しているため、確認ダイアログが必要です。これがあなた自身のアプリでテストカバレッジを必要とするかどうかについて考える価値があります。Railsにはそれをカバーするためのテストがすでにあります。

于 2012-05-26T09:46:38.760 に答える