Module: OnlyofficeWebdriverWrapper::WebdriverTabHelper
- Extended by:
- Gem::Deprecate
- Included in:
- WebDriver
- Defined in:
- lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_tab_helper.rb
Overview
Module for work with tabs
Constant Summary collapse
- TIMEOUT_WAIT_ELEMENT =
Returns Default timeout for waiting for element.
15
Instance Method Summary collapse
-
#choose_tab(tab_number, timeout: TIMEOUT_WAIT_ELEMENT) ⇒ void
Choose tab by it’s number.
-
#close_popup_and_switch_to_main_tab ⇒ void
Wait for popup window, close it and return to first tab.
-
#close_tab ⇒ void
Close current active tab and switch to first one.
-
#new_tab ⇒ void
Create new tab.
-
#resize_tab(width, height) ⇒ void
Resize current tab to specific size.
-
#switch_to_main_tab ⇒ void
Switch to first tab of chrome.
-
#switch_to_popup(after_switch_timeout: 3, popup_appear_timeout: 30) ⇒ void
Switch to popup window non-zero to workaround bug with page load hanging up after switch.
-
#tab_count ⇒ Integer
Get tab count.
-
#title_of_current_tab ⇒ String
(also: #get_title_of_current_tab)
Title of current tab.
Instance Method Details
#choose_tab(tab_number, timeout: TIMEOUT_WAIT_ELEMENT) ⇒ void
This method returns an undefined value.
Choose tab by it’s number
55 56 57 58 59 60 61 62 63 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_tab_helper.rb', line 55 def choose_tab(tab_number, timeout: TIMEOUT_WAIT_ELEMENT) counter = 0 while tab_count < tab_number && counter < timeout sleep 1 counter += 1 end webdriver_error("choose_tab: Tab number = #{tab_number} not found") if counter >= timeout @driver.switch_to.window(@driver.window_handles[tab_number - 1]) end |
#close_popup_and_switch_to_main_tab ⇒ void
This method returns an undefined value.
Wait for popup window, close it and return to first tab
81 82 83 84 85 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_tab_helper.rb', line 81 def close_popup_and_switch_to_main_tab switch_to_popup close_tab switch_to_main_tab end |
#close_tab ⇒ void
This method returns an undefined value.
Close current active tab and switch to first one
73 74 75 76 77 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_tab_helper.rb', line 73 def close_tab @driver.close sleep 1 switch_to_main_tab end |
#new_tab ⇒ void
This method returns an undefined value.
Create new tab
11 12 13 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_tab_helper.rb', line 11 def new_tab execute_javascript('window.open()') end |
#resize_tab(width, height) ⇒ void
This method returns an undefined value.
Resize current tab to specific size
19 20 21 22 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_tab_helper.rb', line 19 def resize_tab(width, height) @driver.manage.window.resize_to(width, height) OnlyofficeLoggerHelper.log("Resize current window to #{width}x#{height}") end |
#switch_to_main_tab ⇒ void
This method returns an undefined value.
Switch to first tab of chrome
67 68 69 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_tab_helper.rb', line 67 def switch_to_main_tab @driver.switch_to.window(@driver.window_handles.first) end |
#switch_to_popup(after_switch_timeout: 3, popup_appear_timeout: 30) ⇒ void
This method returns an undefined value.
Switch to popup window non-zero to workaround bug with page load hanging up after switch
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_tab_helper.rb', line 29 def switch_to_popup(after_switch_timeout: 3, popup_appear_timeout: 30) counter = 0 while tab_count < 2 && counter < popup_appear_timeout sleep 1 counter += 1 end webdriver_error('switch_to_popup: Popup window not found') if counter >= popup_appear_timeout list_of_handlers = @driver.window_handles last_window_handler = list_of_handlers.last @driver.switch_to.window(last_window_handler) sleep(after_switch_timeout) # Do not remove until problem with page loading stop resolved end |
#tab_count ⇒ Integer
Get tab count
44 45 46 47 48 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_tab_helper.rb', line 44 def tab_count tab_count = @driver.window_handles.length OnlyofficeLoggerHelper.log("tab_count: #{tab_count}") tab_count end |
#title_of_current_tab ⇒ String Also known as: get_title_of_current_tab
Returns title of current tab.
88 89 90 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_tab_helper.rb', line 88 def title_of_current_tab @driver.title end |