Method: Capybara::Session#window_opened_by
- Defined in:
- lib/capybara/session.rb
#window_opened_by(**options, &block) ⇒ Capybara::Window
Get the window that has been opened by the passed block.
It will wait for it to be opened (in the same way as other Capybara methods wait).
It's better to use this method than windows.last
as order of windows isn't defined in some drivers.
581 582 583 584 585 586 587 588 589 590 591 592 593 |
# File 'lib/capybara/session.rb', line 581 def window_opened_by(**) old_handles = driver.window_handles yield synchronize_windows() do opened_handles = (driver.window_handles - old_handles) if opened_handles.size != 1 raise Capybara::WindowError, 'block passed to #window_opened_by ' \ "opened #{opened_handles.size} windows instead of 1" end Window.new(self, opened_handles.first) end end |