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.

Returns:

  • (Integer)

    Default timeout for waiting for element

15

Instance Method Summary collapse

Instance Method Details

#choose_tab(tab_number, timeout: TIMEOUT_WAIT_ELEMENT) ⇒ void

This method returns an undefined value.

Choose tab by it’s number

Parameters:

  • tab_number (Integer)

    to choose

  • timeout (Integer) (defaults to: TIMEOUT_WAIT_ELEMENT)

    how much for this tab

Raises:

  • (RuntimeError)

    error if tab not found



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_tabvoid

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_tabvoid

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_tabvoid

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

Parameters:

  • width (Integer)

    to set

  • height (Integer)

    to set



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_tabvoid

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

Parameters:

  • popup_appear_timeout (Integer) (defaults to: 30)

    how much time to wait for popup window

  • after_switch_timeout (Integer) (defaults to: 3)

    wait after switch to window



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_countInteger

Get tab count

Returns:

  • (Integer)

    count of tabs in opened session



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_tabString Also known as: get_title_of_current_tab

Returns title of current tab.

Returns:

  • (String)

    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