Class: AePageObjects::MultipleWindows::WindowHandleManager
- Inherits:
-
Object
- Object
- AePageObjects::MultipleWindows::WindowHandleManager
- Defined in:
- lib/ae_page_objects/multiple_windows/window_handle_manager.rb
Class Method Summary collapse
- .all ⇒ Object
- .browser ⇒ Object
- .close(handle) ⇒ Object
- .current ⇒ Object
- .switch_to(handle) ⇒ Object
Class Method Details
.all ⇒ Object
4 5 6 |
# File 'lib/ae_page_objects/multiple_windows/window_handle_manager.rb', line 4 def self.all browser.window_handles end |
.browser ⇒ Object
22 23 24 |
# File 'lib/ae_page_objects/multiple_windows/window_handle_manager.rb', line 22 def self.browser Capybara.current_session.driver.browser end |
.close(handle) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ae_page_objects/multiple_windows/window_handle_manager.rb', line 26 def self.close(handle) all_handles_before_close = all() more_than_one_window = (all_handles_before_close.size > 1) # We must protect against closing the last window as doing so will quit the entire browser # which would mess up subsequent tests. # http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#close() return false unless more_than_one_window current_handle_before_switch = current # switch to the window to close switch_to(handle) browser.close # need to switch back to something. Use whatever was switched from originally unless we just # closed that window, in which case just pick something else. switch_to(current_handle_before_switch == handle ? all.first : current_handle_before_switch) true end |
.current ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/ae_page_objects/multiple_windows/window_handle_manager.rb', line 8 def self.current # Accessing browser.window_handle tries to find an existing page, which will blow up # if there isn't one. So... we look at the collection first as a guard. if all.empty? nil else browser.window_handle end end |
.switch_to(handle) ⇒ Object
18 19 20 |
# File 'lib/ae_page_objects/multiple_windows/window_handle_manager.rb', line 18 def self.switch_to(handle) browser.switch_to.window(handle) end |