(Capybara) modal window available

I am writing query specifications ... I am using Capybara ... And I am having problems with some modal windows.

What I really want in my test is to fill out the form that appears in the modal window.

The modal is created using Bootstrap from Twitter ( http://twitter.github.com/bootstrap/javascript.html#modals ) ... and it goes through a set of transitions (but I don’t know what has to do with what I'm going to say )

I tried several workarounds that I found on the Internet, for example:

A) switch between pages from page.driver.browser.window_handles

 page.driver.browser.switch_to.window(page.driver.browser.window_handles.last) 

B) using wait_until to make sure that the modal loads

 def modal_wrapper_id '#modal-edit' end def modal_visible wait_until { find(modal_wrapper_id).visible? } rescue Capybara::TimeoutError flunk 'Expected modal to be visible.' end 

but none of them worked ... so I decided to display the number of window handles when the modal window was active ...

So, I did this:

 puts page.driver.browser.window_handles.length.should == 2 

And I got this:

 Failure/Error: page.driver.browser.window_handles.length.should == 2 expected: 2 got: 1 (using ==) 

From what I understand, practically my modal window does not exist.

Any help on this would be greatly appreciated.

Thanks.

+7
source share
2 answers

I did not use Capybara, but your problem is that the Bootstrap modal dialog is actually pseudo-modal, because in fact it is just a div element and a transparent label behind it. A true modal dialog would be created, for example, using window.confirm , which can actually be requested using your sample code. In your case, you must provide a modal div an id element and use it as a handle to request it from Capybara and wait for its "block". However, I did not test anything.

+1
source

Capybara uses: rack_test driver by default. Can you confirm that you are using Selenium WebDriver or another driver, where it is really possible to open a modal window?

+1
source

All Articles