Capybara Exile Warning

I am upgrading from rails 3.2.19 to rails 4.1.5 using rspec-rails 2.14.0.rc1 and capybara 2.4.1. All tests pass, and I have only one warning about the failure:

[DEPRECATION] Capybara::Webkit::Driver#accept_js_confirms! is deprecated. Please use Capybara::Session#accept_confirm instead. 

The line of code calling this,

 page.driver.accept_js_confirms! 

How do I change this line to exclude a failure warning?

+8
ruby-on-rails rspec capybara capybara-webkit
Oct 09 '14 at 9:49 on
source share
5 answers

Given that the exception says:

Use Capybara :: Session # accept_confirm instead.

You probably want:

 page.accept_confirm 

Note that accept_confirm is executed instead of Capybara :: Session instead of the driver.

This method expects a block that triggers an acknowledgment warning. For example:

 page.accept_confirm do click_link('that_opens_confirm') end 
+10
Oct 10 '14 at 18:31
source share

Justin Ko's answer is correct regarding using #accept_confirm - this is

 page.accept_confirm do #code that will trigger the modal end 

or you can do

 page.accept_confirm 'Are you sure?' do #code that will trigger the modal end 

who will verify that "are you sure?" This is the prompt displayed in the confirmation box.

In your failed test, do you deal with another modal first? Capybara-webkit had an error with several modules that were fixed a few days ago - https://github.com/thoughtbot/capybara-webkit/commit/86e422f94422d39e537329d64d7bfe8f6360bd8b . However, this is not a version.

+5
Oct 13 '14 at 21:14
source share

I had a 50/50 success with Justin Co.'s answer. The one that worked had this code:

 link_to "Reset", reset_pre_shot_description_mental_game_path(@mental_game), data: {confirm: 'Are you sure?'}, class: "small_button round", id: "reset_pre-shot" 

and this test:

 page.accept_confirm do click_link "Reset" end 

A test that does not work (but has code that works in the browser) has code

 link_to 'Delete', micropost, data: {confirm: 'Are you sure?'}, method: :delete 

and test

 page.accept_confirm do click_link "Delete" end 

The error message was

 Failure/Error: page.accept_confirm do Capybara::ModalNotFound: Timed out waiting for modal dialog 

I tried moving method: :delete to the hash :data , but that didn't help.

It turned out that the obsolescence warning actually detected two errors in the code, since I used the rails 3 syntax to confirm, i.e. didn't use the hash :data , so my code was broken, but the page.driver.accept_js_confirms! test page.driver.accept_js_confirms! was not picking him up. Therefore, it was important to keep track.

+3
Oct 13 '14 at 10:01
source share

I replaced page.driver.accept_js_confirms! from:

page.execute_script ('window.confirm = function () {return true}')

And the test passed.

This was from the documentation here: http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Session#evaluate_script-instance_method

And help from the internet. Now this does not yet tell us how to use accept_confirm, so I'm still looking for an answer.

The actual code is as follows:

 # Execute the block, accepting a confirm. # # @macro modal_params # def accept_confirm(text_or_options=nil, options={}, &blk) if text_or_options.is_a? Hash options=text_or_options else options[:text]=text_or_options end driver.accept_modal(:confirm, options, &blk) end 

Honestly, I think this is just page.accept_confirm with SOMETHING else, but I cannot figure out what is or is being passed in this block.

0
10 Oct '14 at 17:47
source share

Great for me:

 page.execute_script('window.confirm = function() { return true }') 
0
Apr 26 '16 at 5:39 on
source share



All Articles