Class: AePageObjects::Window::HandleManager
- Inherits:
-
Object
- Object
- AePageObjects::Window::HandleManager
- Defined in:
- lib/ae_page_objects/window.rb
Class Method Summary collapse
- .all ⇒ Object
- .browser ⇒ Object
- .close(handle) ⇒ Object
- .current ⇒ Object
- .switch_to(handle) ⇒ Object
Class Method Details
.all ⇒ Object
23 24 25 |
# File 'lib/ae_page_objects/window.rb', line 23 def self.all browser.window_handles end |
.browser ⇒ Object
41 42 43 |
# File 'lib/ae_page_objects/window.rb', line 41 def self.browser Capybara.current_session.driver.browser end |
.close(handle) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ae_page_objects/window.rb', line 45 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
27 28 29 30 31 32 33 34 35 |
# File 'lib/ae_page_objects/window.rb', line 27 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
37 38 39 |
# File 'lib/ae_page_objects/window.rb', line 37 def self.switch_to(handle) browser.switch_to.window(handle) end |