capybara-mechanize icon indicating copy to clipboard operation
capybara-mechanize copied to clipboard

Accessing popup windows

Open mmrobins opened this issue 13 years ago • 13 comments

A fairly common practice in authentication of Twitter apps via OAuth is to redirect to the authorize endpoint in a popup window. I'm not able to use Selenium to fully test because it doesn't handle redirects (AFAIK), but mechanize doesn't handle popup windows

main, popup = page.driver.browser.window_handles
within_window(popup) do
  # fill in login info here and click authorize 
end

Any suggestions on how to handle this or if it would be possible to add window handling to capybara-mechanize? Thanks.

mmrobins avatar May 25 '12 19:05 mmrobins

I believe this has been fixed since the 1.0 release.

ryansch avatar Jan 17 '14 20:01 ryansch

No kidding? @ryansch thanks for helping to clear out the backlog. I'll try to add a test for this.

phillbaker avatar Jan 18 '14 18:01 phillbaker

Does it work?

page.driver.browser.window_handles (version 1.4.0)

undefined method 'window_handles ' for #Capybara::Mechanize::Browser

brunobrgs avatar Nov 12 '14 17:11 brunobrgs

It worked as of the 1.1.0 release with capybara 2.1.0. Sounds like we might have a regression.

ryansch avatar Nov 12 '14 18:11 ryansch

I will try like you said, thanks

brunobrgs avatar Nov 12 '14 18:11 brunobrgs

@ryansch For this, the method window_handles should be here, on 1.1.0.

https://github.com/jeroenvandijk/capybara-mechanize/blob/v1.1.0/lib/capybara/mechanize/browser.rb

or not?

brunobrgs avatar Nov 12 '14 19:11 brunobrgs

Not there. Notice how the class inherits from Capybara::RackTest::Browser? That should lead you to it.

ryansch avatar Nov 12 '14 20:11 ryansch

I'm assuming this broke due to changes in Capybara.

ryansch avatar Nov 12 '14 20:11 ryansch

I'm saying this, because when i use capybara-webkit, it works.

At master there, the method exist: https://github.com/thoughtbot/capybara-webkit/blob/c1b501ca525532d261ded8d3c0c6408716a1f8ef/lib/capybara/webkit/browser.rb#L129

brunobrgs avatar Nov 12 '14 20:11 brunobrgs

Right they wrote their own browser. Capybara-mechanize is a special kind of racktest driver.

I'm interested in that deprecation warning. I'm fairly certain that's the real cause of this issue. What version of capybara are you running?

ryansch avatar Nov 12 '14 21:11 ryansch

With webkit: gem 'capybara', '2.1.0' gem 'capybara-webkit', '1.0.0'

With mechanize i tried, but didn't work: gem 'capybara', '2.1.0' gem 'capybara-mechanize', '1.1.0'

brunobrgs avatar Nov 12 '14 22:11 brunobrgs

Something strange is going on then. We're using the second stanza in our app right now and we make pretty heavy use of page.driver.browser.window_handles.

ryansch avatar Nov 12 '14 22:11 ryansch

I will try again, will check it outside my app, maybe it is a something else, then i come back here. Thank you.

brunobrgs avatar Nov 12 '14 22:11 brunobrgs