onlyoffice_webdriver_wrapper 1.8.0 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (22) hide show
  1. checksums.yaml +4 -4
  2. data/lib/onlyoffice_webdriver_wrapper/helpers/chrome_helper/chromedriver_bin/{chromedriver_linux_101 → chromedriver_linux_104} +0 -0
  3. data/lib/onlyoffice_webdriver_wrapper/helpers/chrome_helper/chromedriver_bin/chromedriver_mac +0 -0
  4. data/lib/onlyoffice_webdriver_wrapper/helpers/firefox_helper.rb +4 -1
  5. data/lib/onlyoffice_webdriver_wrapper/helpers/headless_helper/headless_patch.rb +1 -1
  6. data/lib/onlyoffice_webdriver_wrapper/helpers/headless_helper.rb +1 -1
  7. data/lib/onlyoffice_webdriver_wrapper/version.rb +1 -1
  8. data/lib/onlyoffice_webdriver_wrapper/webdriver/click_methods.rb +10 -12
  9. data/lib/onlyoffice_webdriver_wrapper/webdriver/element_getters.rb +46 -0
  10. data/lib/onlyoffice_webdriver_wrapper/webdriver/get_text_methods.rb +48 -0
  11. data/lib/onlyoffice_webdriver_wrapper/webdriver/select_list_methods.rb +52 -0
  12. data/lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_attributes_helper.rb +1 -1
  13. data/lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_exceptions.rb +2 -0
  14. data/lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_frame_methods.rb +2 -2
  15. data/lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_js_methods.rb +2 -11
  16. data/lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_move_cursor_methods.rb +19 -11
  17. data/lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_navigation_methods.rb +7 -3
  18. data/lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_screenshot_helper.rb +5 -4
  19. data/lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_tab_helper.rb +6 -1
  20. data/lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb +12 -4
  21. data/lib/onlyoffice_webdriver_wrapper/webdriver.rb +19 -133
  22. metadata +15 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb66b9cb0b1d1d9c2c1b073c87c8448f219ab606167cf04fc07098fb1b9ab52c
4
- data.tar.gz: dcc8a129fd4bb6c1bf03cb3c7512e02307b1c468a57692b0cccfaf367013a810
3
+ metadata.gz: 643b10c1d669416dbc430566e360d7ccec6ea147d42f37707a0534b734bc1d98
4
+ data.tar.gz: 0e8b63041f0e9db6a2415f9aaa9eb966866d6555479bfec7f93c983011b5500b
5
5
  SHA512:
6
- metadata.gz: 9d291a4d9e4cb76071c29f99ff9e406aed808acadd2da20b8a4809da3104ec6787632a46049af95def7b6ea631a1a345f180e7313297089fc369d13ffa43eefe
7
- data.tar.gz: 79450930ff1f94e966076dd0ad4c34ea8a88ca746b373dd6505dfc7f1f888b2cd8fb6deac3f2f96d46d763ead26d60dee27bddbe40e1a60540ff0cbc79f89052
6
+ metadata.gz: 117134c44e8598f311bf93bf457bbd4768b9eafbc6b97c8fc294c9b584143623a64473b733952b7539d5f0b1663a2da3b80d6c60f5866391a4e3870195e4326e
7
+ data.tar.gz: d9e14fc44a181d86a6a8c85e9b8c89f2d41c279ab19a8cd00c8d209dcd4df55c1bbf98fee9059de3506cdd704315eb64588e062853b8563df3a035e44e5a0e37
@@ -21,7 +21,10 @@ module OnlyofficeWebdriverWrapper
21
21
  caps = Selenium::WebDriver::Remote::Capabilities.firefox
22
22
  caps[:proxy] = Selenium::WebDriver::Proxy.new(ssl: "#{@proxy.proxy_address}:#{@proxy.proxy_port}") if @proxy
23
23
  driver = Selenium::WebDriver.for :firefox, service: firefox_service, capabilities: [caps, options]
24
- driver.manage.window.size = Selenium::WebDriver::Dimension.new(headless.resolution_x, headless.resolution_y) if headless.running?
24
+ if headless.running?
25
+ driver.manage.window.size = Selenium::WebDriver::Dimension.new(headless.resolution_x,
26
+ headless.resolution_y)
27
+ end
25
28
  driver
26
29
  end
27
30
 
@@ -29,7 +29,7 @@ class Headless
29
29
  class VideoRecorder
30
30
  # Stop recording and save it
31
31
  # @param [String] path to save
32
- # @retunr [nil, String] path to result file or nil if error
32
+ # @return [nil, String] path to result file or nil if error
33
33
  def stop_and_save(path)
34
34
  CliUtil.kill_process(@pid_file_path, :wait => true)
35
35
  if File.exist? @tmp_file_path
@@ -54,7 +54,7 @@ module OnlyofficeWebdriverWrapper
54
54
  destroy_at_exit: true,
55
55
  dimensions: "#{@resolution_x + 1}x#{@resolution_y + 1}x24",
56
56
  video: { provider: :ffmpeg })
57
- rescue Exception => e
57
+ rescue StandardError => e
58
58
  OnlyofficeLoggerHelper.log("xvfb not started with problem #{e}")
59
59
  WebDriver.clean_up(true)
60
60
  @headless_instance = Headless.new(reuse: false,
@@ -4,6 +4,6 @@ module OnlyofficeWebdriverWrapper
4
4
  # Module for storing version data
5
5
  module Version
6
6
  # @return [String] Current stable version of gem
7
- STRING = '1.8.0'
7
+ STRING = '1.10.0'
8
8
  end
9
9
  end
@@ -24,8 +24,10 @@ module OnlyofficeWebdriverWrapper
24
24
  begin
25
25
  count.times { element.click }
26
26
  rescue Selenium::WebDriver::Error::ElementNotInteractableError => e
27
- webdriver_error(e.class, "Selenium::WebDriver::Error::ElementNotInteractableError: element not visible for xpath: #{xpath_name}")
28
- rescue Exception => e
27
+ webdriver_error(e.class,
28
+ 'Selenium::WebDriver::Error::ElementNotInteractableError: ' \
29
+ "element not visible for xpath: #{xpath_name}")
30
+ rescue StandardError => e
29
31
  webdriver_error(e.class, "UnknownError #{e.message} #{xpath_name}")
30
32
  end
31
33
  end
@@ -38,7 +40,7 @@ module OnlyofficeWebdriverWrapper
38
40
  element = get_element_by_display(xpath_name)
39
41
  begin
40
42
  element.is_a?(Array) ? element.first.click : element.click
41
- rescue Exception => e
43
+ rescue StandardError => e
42
44
  webdriver_error(e.class, "Exception #{e} in click_on_displayed(#{xpath_name})")
43
45
  end
44
46
  end
@@ -50,10 +52,8 @@ module OnlyofficeWebdriverWrapper
50
52
  # @return [nil]
51
53
  def click_on_locator_coordinates(xpath_name, right_by, down_by)
52
54
  wait_until_element_visible(xpath_name)
53
- element = @driver.find_element(:xpath, xpath_name)
54
- shift_to_zero = move_to_shift_to_top_left(xpath_name)
55
- @driver.action.move_to(element, right_by.to_i - shift_to_zero.x, down_by.to_i - shift_to_zero.y).perform
56
- @driver.action.move_to(element, right_by.to_i - shift_to_zero.x, down_by.to_i - shift_to_zero.y).click.perform
55
+ move_to_driver_action(xpath_name, right_by, down_by).perform
56
+ move_to_driver_action(xpath_name, right_by, down_by).click.perform
57
57
  end
58
58
 
59
59
  # Click on one of several which displayed
@@ -100,10 +100,8 @@ module OnlyofficeWebdriverWrapper
100
100
  # @return [nil]
101
101
  def right_click_on_locator_coordinates(xpath_name, right_by = nil, down_by = nil)
102
102
  wait_until_element_visible(xpath_name)
103
- element = @driver.find_element(:xpath, xpath_name)
104
- shift_to_zero = move_to_shift_to_top_left(xpath_name)
105
- @driver.action.move_to(element, right_by.to_i - shift_to_zero.x, down_by.to_i - shift_to_zero.y).perform
106
- @driver.action.move_to(element, right_by.to_i - shift_to_zero.x, down_by.to_i - shift_to_zero.y).context_click.perform
103
+ move_to_driver_action(xpath_name, right_by, down_by).perform
104
+ move_to_driver_action(xpath_name, right_by, down_by).context_click.perform
107
105
  end
108
106
 
109
107
  # Perform double_click on element
@@ -121,7 +119,7 @@ module OnlyofficeWebdriverWrapper
121
119
  # @return [nil]
122
120
  def double_click_on_locator_coordinates(xpath_name, right_by, down_by)
123
121
  wait_until_element_visible(xpath_name)
124
- @driver.action.move_to(@driver.find_element(:xpath, xpath_name), right_by.to_i, down_by.to_i).double_click.perform
122
+ move_to_driver_action(xpath_name, right_by, down_by).double_click.perform
125
123
  end
126
124
  end
127
125
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeWebdriverWrapper
4
+ # Methods to get elements
5
+ module ClickMethods
6
+ # Get element by it's xpath
7
+ # @param [String] object_identification xpath of object to find
8
+ # @return [Object, nil] nil if nothing found
9
+ def get_element(object_identification)
10
+ return object_identification unless object_identification.is_a?(String)
11
+
12
+ @driver.find_element(:xpath, object_identification)
13
+ rescue StandardError
14
+ nil
15
+ end
16
+
17
+ # Get first visible element from several
18
+ # @param [String] xpath_name to find several objects
19
+ # @raise [Selenium::WebDriver::Error::InvalidSelectorError] if selector is invalid
20
+ # @return [Object] first visible element
21
+ def get_element_by_display(xpath_name)
22
+ @driver.find_elements(:xpath, xpath_name).each do |element|
23
+ return element if element.displayed?
24
+ end
25
+ rescue Selenium::WebDriver::Error::InvalidSelectorError
26
+ webdriver_error(Selenium::WebDriver::Error::InvalidSelectorError,
27
+ "Invalid Selector: get_element_by_display('#{xpath_name}')")
28
+ end
29
+
30
+ # Get array of webdriver object by xpath
31
+ # @param [String] objects_identification object to find
32
+ # @param [Boolean] only_visible return invisible if true
33
+ # @return [Array, Object] list of objects
34
+ def get_elements(objects_identification, only_visible = true)
35
+ return objects_identification if objects_identification.is_a?(Array)
36
+
37
+ elements = @driver.find_elements(:xpath, objects_identification)
38
+ if only_visible
39
+ elements.each do |current|
40
+ elements.delete(current) unless @browser == :firefox || current.displayed?
41
+ end
42
+ end
43
+ elements
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeWebdriverWrapper
4
+ # Method to get text
5
+ module GetTextMethods
6
+ # Get text of current element
7
+ # @param [String] xpath_name name of xpath
8
+ # @param [Boolean] wait_until_visible wait until element visible
9
+ # @return [String] result string
10
+ def get_text(xpath_name, wait_until_visible = true)
11
+ wait_until_element_visible(xpath_name) if wait_until_visible
12
+
13
+ element = get_element(xpath_name)
14
+ webdriver_error("get_text(#{xpath_name}, #{wait_until_visible}) not found element by xpath") if element.nil?
15
+ if element.tag_name == 'input' || element.tag_name == 'textarea'
16
+ element.attribute('value')
17
+ else
18
+ element.text
19
+ end
20
+ end
21
+
22
+ # Get text in object by xpath
23
+ # @param xpath [String] xpath to get text
24
+ # @return [String] text in xpath
25
+ def get_text_by_js(xpath)
26
+ text = execute_javascript("return #{dom_element_by_xpath(xpath)}.textContent")
27
+ text = execute_javascript("return #{dom_element_by_xpath(xpath)}.value") if text.empty?
28
+ text
29
+ end
30
+
31
+ # Get text from all elements with specified xpath
32
+ # @param array_elements [String] xpath of elements
33
+ # @return [Array<String>] values of elements
34
+ def get_text_array(array_elements)
35
+ get_elements(array_elements).map { |current_element| get_text(current_element) }
36
+ end
37
+
38
+ # Get text from several elements
39
+ # This method filter out all elements with empty text
40
+ # @param [String] xpath_several_elements to find objects
41
+ # @return [Array<String>] text of those elements
42
+ def get_text_of_several_elements(xpath_several_elements)
43
+ @driver.find_elements(:xpath, xpath_several_elements).filter_map do |element|
44
+ element.text unless element.text == ''
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeWebdriverWrapper
4
+ # Method to work with select list
5
+ module SelectListMethods
6
+ # Select from list elements
7
+ # @param [String] value value to find object
8
+ # @param [Array<PageObject::Elements::Element>] elements_value `elements` page object to select from
9
+ # @raise [SelectEntryNotFound] if value not found in select list
10
+ # @return [void]
11
+ def select_from_list_elements(value, elements_value)
12
+ index = get_element_index(value, elements_value)
13
+ webdriver_error(SelectEntryNotFound, "Select entry `#{value}` not found in #{elements_value}") if index.nil?
14
+
15
+ elements_value[index].click
16
+ end
17
+
18
+ # Get index of element by it's text
19
+ # @param [String] text to compare text
20
+ # @param [Array<PageObject::Elements::Element>] list_elements array with
21
+ # PageObject elements to find in
22
+ # @return [Integer, nil] nil if nothing found, index if found
23
+ def get_element_index(text, list_elements)
24
+ list_elements.each_with_index do |current, i|
25
+ return i if get_text(current) == text
26
+ end
27
+ nil
28
+ end
29
+
30
+ # Get all options for combobox or select
31
+ # @param [String] xpath_name to find element
32
+ # @return [Array<String>] values
33
+ def get_all_combo_box_values(xpath_name)
34
+ @driver.find_element(:xpath, xpath_name).find_elements(tag_name: 'option').map { |el| el.attribute('value') }
35
+ end
36
+
37
+ # Select value of combo box
38
+ # @param [String] xpath_name to find combobox
39
+ # @param [String] select_value to select
40
+ # @param [Symbol] select_by select type, can be `:value` or `:text`
41
+ # @return [void]
42
+ def select_combo_box(xpath_name, select_value, select_by = :value)
43
+ wait_until_element_visible(xpath_name)
44
+ option = Selenium::WebDriver::Support::Select.new(get_element(xpath_name))
45
+ begin
46
+ option.select_by(select_by, select_value)
47
+ rescue StandardError
48
+ option.select_by(:text, select_value)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -12,7 +12,7 @@ module OnlyofficeWebdriverWrapper
12
12
  begin
13
13
  attribute_value = element.attribute(attribute)
14
14
  exist = !(attribute_value.empty? || attribute_value.nil?)
15
- rescue Exception
15
+ rescue StandardError
16
16
  exist = false
17
17
  end
18
18
  exist
@@ -3,4 +3,6 @@
3
3
  module OnlyofficeWebdriverWrapper
4
4
  # Exception class if system is not supported
5
5
  class WebdriverSystemNotSupported < StandardError; end
6
+ # If entry needed to be selected not found in select
7
+ class SelectEntryNotFound < StandardError; end
6
8
  end
@@ -13,7 +13,7 @@ module OnlyofficeWebdriverWrapper
13
13
  @driver.switch_to.frame frame
14
14
  rescue Selenium::WebDriver::Error::NoSuchElementError
15
15
  OnlyofficeLoggerHelper.log('Raise NoSuchElementError in the select_frame method')
16
- rescue Exception => e
16
+ rescue StandardError => e
17
17
  webdriver_error("Raise unknown exception: #{e}")
18
18
  end
19
19
  end
@@ -24,7 +24,7 @@ module OnlyofficeWebdriverWrapper
24
24
  @driver.switch_to.default_content
25
25
  rescue Timeout::Error
26
26
  OnlyofficeLoggerHelper.log('Raise TimeoutError in the select_top_frame method')
27
- rescue Exception => e
27
+ rescue StandardError => e
28
28
  raise "Browser is crushed or hangup with error: #{e}"
29
29
  end
30
30
  end
@@ -18,7 +18,7 @@ module OnlyofficeWebdriverWrapper
18
18
  # in that case performing `webdriver_error` only cause forever loop
19
19
  # since webdriver_error trying to get_url or make screenshots
20
20
  raise(e.class, "Timeout Error #{e} happened while executing #{script}")
21
- rescue Exception => e
21
+ rescue StandardError => e
22
22
  webdriver_error(e, "Exception #{e} in execute_javascript: #{script}")
23
23
  end
24
24
 
@@ -40,15 +40,6 @@ module OnlyofficeWebdriverWrapper
40
40
  execute_javascript("#{dom_element_by_xpath(xpath)}.value=\"#{escaped_text}\";")
41
41
  end
42
42
 
43
- # Get text in object by xpath
44
- # @param xpath [String] xpath to get text
45
- # @return [String] text in xpath
46
- def get_text_by_js(xpath)
47
- text = execute_javascript("return #{dom_element_by_xpath(xpath)}.textContent")
48
- text = execute_javascript("return #{dom_element_by_xpath(xpath)}.value") if text.empty?
49
- text
50
- end
51
-
52
43
  # Calculate object size using Javascript
53
44
  # @param xpath [Sting] xpath of object
54
45
  # @return [Dimensions] size of element
@@ -93,7 +84,7 @@ module OnlyofficeWebdriverWrapper
93
84
  # @param property [String] property to get
94
85
  # @return [String] value of property
95
86
  def computed_style(xpath, pseudo_element = 'null', property = nil)
96
- element_by_xpath = "document.evaluate(\"#{xpath.tr('"', "'")}\",document, null, XPathResult.ANY_TYPE, null ).iterateNext()"
87
+ element_by_xpath = dom_element_by_xpath(xpath)
97
88
  style = "window.getComputedStyle(#{element_by_xpath}, '#{pseudo_element}')"
98
89
  full_command = "#{style}.getPropertyValue('#{property}')"
99
90
  result = execute_javascript("return #{full_command}")
@@ -14,13 +14,9 @@ module OnlyofficeWebdriverWrapper
14
14
  # * +y2+ - shift vector y coordinate
15
15
  # * +mouse_release+ - release mouse after move
16
16
  def drag_and_drop(xpath, x1, y1, x2, y2, mouse_release: true)
17
- canvas = get_element(xpath)
18
- shift_to_zero = move_to_shift_to_top_left(xpath)
19
- move_action = @driver.action
20
- .move_to(canvas, x1.to_i - shift_to_zero.x,
21
- y1.to_i - shift_to_zero.y)
22
- .click_and_hold
23
- .move_by(x2, y2)
17
+ move_action = move_to_driver_action(xpath, x1, y1)
18
+ .click_and_hold
19
+ .move_by(x2, y2)
24
20
  move_action = move_action.release if mouse_release
25
21
 
26
22
  move_action.perform
@@ -56,12 +52,11 @@ module OnlyofficeWebdriverWrapper
56
52
  # @return [nil]
57
53
  def mouse_over(xpath_name, x_coordinate = 0, y_coordinate = 0)
58
54
  wait_until_element_present(xpath_name)
59
- shift_to_zero = move_to_shift_to_top_left(xpath_name)
60
- @driver.action.move_to(@driver.find_element(:xpath, xpath_name),
61
- x_coordinate.to_i - shift_to_zero.x,
62
- y_coordinate.to_i - shift_to_zero.y).perform
55
+ move_to_driver_action(xpath_name, x_coordinate, y_coordinate).perform
63
56
  end
64
57
 
58
+ private
59
+
65
60
  # Since v4.3.0 of `webdriver` gem `move_to` method is moving
66
61
  # from the center of the element
67
62
  # Add additional negative shift if this version is used
@@ -73,5 +68,18 @@ module OnlyofficeWebdriverWrapper
73
68
  Dimensions.new(0, 0)
74
69
  end
75
70
  end
71
+
72
+ # Generate action to move cursor to element
73
+ # @param [String] xpath xpath to move
74
+ # @param [Integer] right_by shift vector x coordinate
75
+ # @param [Integer] down_by shift vector y coordinate
76
+ # @return [Selenium::WebDriver::ActionBuilder] object to perform actions
77
+ def move_to_driver_action(xpath, right_by, down_by)
78
+ element = @driver.find_element(:xpath, xpath)
79
+ shift_to_zero = move_to_shift_to_top_left(xpath)
80
+ @driver.action.move_to(element,
81
+ right_by.to_i - shift_to_zero.x,
82
+ down_by.to_i - shift_to_zero.y)
83
+ end
76
84
  end
77
85
  end
@@ -20,12 +20,16 @@ module OnlyofficeWebdriverWrapper
20
20
 
21
21
  # @return [String] url of current frame, or browser url if
22
22
  # it is a root frame
23
- def get_url
23
+ def current_url
24
24
  execute_javascript('return window.location.href')
25
25
  rescue Selenium::WebDriver::Error::NoSuchFrameError, Timeout::Error => e
26
26
  raise(e.class, "Browser is crushed or hangup with #{e}")
27
27
  end
28
28
 
29
+ alias get_url current_url
30
+ extend Gem::Deprecate
31
+ deprecate :get_url, 'current_url', 2069, 1
32
+
29
33
  # Refresh current page
30
34
  # @return [nil]
31
35
  def refresh
@@ -48,11 +52,11 @@ module OnlyofficeWebdriverWrapper
48
52
  begin
49
53
  @driver.execute_script('window.onbeforeunload = null') # off popup window
50
54
  rescue StandardError
51
- Exception
55
+ StandardError
52
56
  end
53
57
  begin
54
58
  @driver.quit
55
- rescue Exception => e
59
+ rescue StandardError => e
56
60
  OnlyofficeLoggerHelper.log("Some error happened on webdriver.quit #{e.backtrace}")
57
61
  end
58
62
  alert_confirm
@@ -22,7 +22,8 @@ module OnlyofficeWebdriverWrapper
22
22
  # Get screenshot of current windows and upload it to cloud storage
23
23
  # @param [String] path_to_screenshot place to store local screenshot
24
24
  # @return [String] url of public screenshot
25
- def get_screenshot_and_upload(path_to_screenshot = "#{screenshot_folder}/#{StringHelper.generate_random_string}.png")
25
+ def get_screenshot_and_upload(path_to_screenshot = nil)
26
+ path_to_screenshot ||= "#{screenshot_folder}/#{StringHelper.generate_random_string}.png"
26
27
  begin
27
28
  get_screenshot(path_to_screenshot)
28
29
  cloud_screenshot = publish_screenshot(path_to_screenshot)
@@ -57,20 +58,20 @@ module OnlyofficeWebdriverWrapper
57
58
  def webdriver_screenshot(screenshot_name = SecureRandom.uuid)
58
59
  begin
59
60
  link = get_screenshot_and_upload("#{screenshot_folder}/#{screenshot_name}.png")
60
- rescue Exception => e
61
+ rescue StandardError => e
61
62
  OnlyofficeLoggerHelper.log("Error in get screenshot: #{e}. Trying to get headless screenshot")
62
63
  if @headless.headless_instance.nil?
63
64
  system_screenshot("/tmp/#{screenshot_name}.png")
64
65
  begin
65
66
  link = publish_screenshot("/tmp/#{screenshot_name}.png")
66
- rescue Exception => e
67
+ rescue StandardError => e
67
68
  OnlyofficeLoggerHelper.log("Error in get screenshot: #{e}. System screenshot #{link}")
68
69
  end
69
70
  else
70
71
  @headless.take_screenshot("/tmp/#{screenshot_name}.png")
71
72
  begin
72
73
  link = publish_screenshot("/tmp/#{screenshot_name}.png")
73
- rescue Exception => e
74
+ rescue StandardError => e
74
75
  OnlyofficeLoggerHelper.log("Error in get screenshot: #{e}. Headless screenshot #{link}")
75
76
  end
76
77
  end
@@ -85,8 +85,13 @@ module OnlyofficeWebdriverWrapper
85
85
  end
86
86
 
87
87
  # @return [String] title of current tab
88
- def get_title_of_current_tab
88
+ def title_of_current_tab
89
89
  @driver.title
90
90
  end
91
+
92
+ alias get_title_of_current_tab title_of_current_tab
93
+
94
+ extend Gem::Deprecate
95
+ deprecate :get_title_of_current_tab, 'title_of_current_tab', 2069, 1
91
96
  end
92
97
  end
@@ -32,12 +32,17 @@ module OnlyofficeWebdriverWrapper
32
32
  # @param [Boolean] by_action type by `@driver.action` if true
33
33
  # @param [Boolean] by_element_send_key use `element.send_keys` if true
34
34
  # @return [void]
35
- def type_to_locator(xpath_name, text_to_send, clear_content = true, click_on_it = false, by_action = false, by_element_send_key = false)
35
+ def type_to_locator(xpath_name,
36
+ text_to_send,
37
+ clear_content = true,
38
+ click_on_it = false,
39
+ by_action = false,
40
+ by_element_send_key = false)
36
41
  element = get_element(xpath_name)
37
42
  if clear_content
38
43
  begin
39
44
  element.clear
40
- rescue Exception => e
45
+ rescue StandardError => e
41
46
  webdriver_error(e.class, "Error in element.clear #{e} for " \
42
47
  "type_to_locator(#{xpath_name}, #{text_to_send}, " \
43
48
  "#{clear_content}, #{click_on_it}, " \
@@ -81,8 +86,11 @@ module OnlyofficeWebdriverWrapper
81
86
  if click_on_it
82
87
  begin
83
88
  element.click
84
- rescue Exception => e
85
- webdriver_error(e.class, "type_to_input(#{xpath_name}, #{text_to_send}, #{clear_content}, #{click_on_it}) error in 'element.click' error: #{e}")
89
+ rescue StandardError => e
90
+ webdriver_error(e.class,
91
+ "type_to_input(#{xpath_name}, #{text_to_send}, " \
92
+ "#{clear_content}, #{click_on_it}) " \
93
+ "error in 'element.click' error: #{e}")
86
94
  end
87
95
  sleep 0.2
88
96
  end
@@ -8,6 +8,9 @@ require 'uri'
8
8
  require_relative 'helpers/chrome_helper'
9
9
  require_relative 'helpers/firefox_helper'
10
10
  require_relative 'webdriver/click_methods'
11
+ require_relative 'webdriver/element_getters'
12
+ require_relative 'webdriver/get_text_methods'
13
+ require_relative 'webdriver/select_list_methods'
11
14
  require_relative 'webdriver/wait_until_methods'
12
15
  require_relative 'webdriver/webdriver_alert_helper'
13
16
  require_relative 'webdriver/webdriver_attributes_helper'
@@ -31,6 +34,8 @@ module OnlyofficeWebdriverWrapper
31
34
  class WebDriver
32
35
  include ChromeHelper
33
36
  include ClickMethods
37
+ include GetTextMethods
38
+ include SelectListMethods
34
39
  include FirefoxHelper
35
40
  include RubyHelper
36
41
  include WaitUntilMethods
@@ -91,68 +96,12 @@ module OnlyofficeWebdriverWrapper
91
96
  @browser_running = true
92
97
  end
93
98
 
94
- # Get element by it's xpath
95
- # @param [String] object_identification xpath of object to find
96
- # @return [Object, nil] nil if nothing found
97
- def get_element(object_identification)
98
- return object_identification unless object_identification.is_a?(String)
99
-
100
- @driver.find_element(:xpath, object_identification)
101
- rescue StandardError
102
- nil
103
- end
104
-
105
- # Get text from all elements with specified xpath
106
- # @param array_elements [String] xpath of elements
107
- # @return [Array<String>] values of elements
108
- def get_text_array(array_elements)
109
- get_elements(array_elements).map { |current_element| get_text(current_element) }
110
- end
111
-
112
- # Select from list elements
113
- # @param [String] value value to find object
114
- # @param [Array<Object>] elements_value elements to check
115
- # @return [void]
116
- def select_from_list_elements(value, elements_value)
117
- index = get_element_index(value, elements_value)
118
- elements_value[index].click
119
- end
120
-
121
- # Get index of element by it's text
122
- # @param [String] text to compare text
123
- # @param [Array<PageObject::Elements::Element>] list_elements array with
124
- # PageObject elements to find in
125
- # @return [Integer, nil] nil if nothing found, index if found
126
- def get_element_index(text, list_elements)
127
- list_elements.each_with_index do |current, i|
128
- return i if get_text(current) == text
129
- end
130
- nil
131
- end
132
-
133
- # Get all options for combo box
134
- # @param [String] xpath_name to find combobox
135
- # @return [Array<String>] values
136
- def get_all_combo_box_values(xpath_name)
137
- @driver.find_element(:xpath, xpath_name).find_elements(tag_name: 'option').map { |el| el.attribute('value') }
138
- end
139
-
140
- # Scroll list to specific element
141
- # @param [String] list_xpath how to find this list
142
- # @param [String] element_xpath to which we should scrolled
143
- # @return [void]
144
- def scroll_list_to_element(list_xpath, element_xpath)
145
- execute_javascript("$(document.evaluate(\"#{list_xpath}\", document, null, XPathResult.ANY_TYPE, null).
146
- iterateNext()).jScrollPane().data('jsp').scrollToElement(document.evaluate(\"#{element_xpath}\",
147
- document, null, XPathResult.ANY_TYPE, null).iterateNext());")
148
- end
149
-
150
99
  # Scroll list by pixel count
151
100
  # @param [String] list_xpath how to detect this list
152
101
  # @param [Integer] pixels how much to scroll
153
102
  # @return [void]
154
103
  def scroll_list_by_pixels(list_xpath, pixels)
155
- execute_javascript("$(document.evaluate(\"#{list_xpath.tr('"', "'")}\", document, null, XPathResult.ANY_TYPE, null).iterateNext()).scrollTop(#{pixels})")
104
+ execute_javascript("#{dom_element_by_xpath(list_xpath)}.scrollTop(#{pixels})")
156
105
  end
157
106
 
158
107
  # Open dropdown selector, like 'Color Selector', which has no element id
@@ -169,8 +118,7 @@ module OnlyofficeWebdriverWrapper
169
118
  set_style_attribute("#{xpath_name}/button", 'display', 'inline-block')
170
119
  set_style_attribute(xpath_name, 'display', 'block')
171
120
  else
172
- shift_to_zero = move_to_shift_to_top_left(xpath_name)
173
- @driver.action.move_to(element, horizontal_shift - shift_to_zero.x, vertical_shift - shift_to_zero.y).click.perform
121
+ move_to_driver_action(xpath_name, horizontal_shift, vertical_shift).click.perform
174
122
  end
175
123
  end
176
124
 
@@ -183,14 +131,11 @@ module OnlyofficeWebdriverWrapper
183
131
  # @return [void]
184
132
  def action_on_locator_coordinates(xpath_name, right_by, down_by, action = :click, times = 1)
185
133
  wait_until_element_visible(xpath_name)
186
- element = @driver.find_element(:xpath, xpath_name)
187
- shift_to_zero = move_to_shift_to_top_left(xpath_name)
188
- (0...times).inject(@driver.action.move_to(element,
189
- right_by.to_i - shift_to_zero.x,
190
- down_by.to_i - shift_to_zero.y)) { |acc, _elem| acc.send(action) }.perform
134
+ (0...times).inject(move_to_driver_action(xpath_name, right_by, down_by)) { |acc, _elem| acc.send(action) }.perform
191
135
  end
192
136
 
193
137
  # Check if element present on page
138
+ # It may be visible or invisible, but should be present in DOM tree
194
139
  # @param [String] xpath_name to find element
195
140
  # @return [Boolean] result of check
196
141
  def element_present?(xpath_name)
@@ -203,21 +148,10 @@ module OnlyofficeWebdriverWrapper
203
148
  @driver.find_element(:xpath, xpath_name)
204
149
  true
205
150
  end
206
- rescue Exception
151
+ rescue StandardError
207
152
  false
208
153
  end
209
154
 
210
- # Get first visible element from several
211
- # @param [String] xpath_name to find several objects
212
- # @return [Object] first visible element
213
- def get_element_by_display(xpath_name)
214
- @driver.find_elements(:xpath, xpath_name).each do |element|
215
- return element if element.displayed?
216
- end
217
- rescue Selenium::WebDriver::Error::InvalidSelectorError
218
- webdriver_error("get_element_by_display(#{xpath_name}): invalid selector: Unable to locate an element with the xpath expression")
219
- end
220
-
221
155
  # Return count of elements (visible and not visible)
222
156
  # @param xpath_name [String] xpath to find
223
157
  # @param only_visible [True, False] count only visible elements?
@@ -231,23 +165,8 @@ module OnlyofficeWebdriverWrapper
231
165
  end
232
166
  end
233
167
 
234
- # Get array of webdriver object by xpath
235
- # @param [String] objects_identification object to find
236
- # @param [Boolean] only_visible return invisible if true
237
- # @return [Array, Object] list of objects
238
- def get_elements(objects_identification, only_visible = true)
239
- return objects_identification if objects_identification.is_a?(Array)
240
-
241
- elements = @driver.find_elements(:xpath, objects_identification)
242
- if only_visible
243
- elements.each do |current|
244
- elements.delete(current) unless @browser == :firefox || current.displayed?
245
- end
246
- end
247
- elements
248
- end
249
-
250
168
  # Check if element visible on page
169
+ # It should be part of DOM and should be visible on current visible part of page
251
170
  # @param [String] xpath_name element to find
252
171
  # @return [Boolean] result of check
253
172
  def element_visible?(xpath_name)
@@ -259,7 +178,7 @@ module OnlyofficeWebdriverWrapper
259
178
 
260
179
  begin
261
180
  visible = element.displayed?
262
- rescue Exception => e
181
+ rescue StandardError => e
263
182
  OnlyofficeLoggerHelper.log("Element #{xpath_name} is not visible because of: #{e.message}")
264
183
  visible = false
265
184
  end
@@ -277,54 +196,21 @@ module OnlyofficeWebdriverWrapper
277
196
  return true if current_element.displayed?
278
197
  end
279
198
  false
280
- rescue Exception => e
199
+ rescue StandardError => e
281
200
  webdriver_error("Raise unknown exception: #{e}")
282
201
  end
283
202
 
284
- # Get text of current element
285
- # @param [String] xpath_name name of xpath
286
- # @param [Boolean] wait_until_visible wait until element visible
287
- # @return [String] result string
288
- def get_text(xpath_name, wait_until_visible = true)
289
- wait_until_element_visible(xpath_name) if wait_until_visible
290
-
291
- element = get_element(xpath_name)
292
- webdriver_error("get_text(#{xpath_name}, #{wait_until_visible}) not found element by xpath") if element.nil?
293
- if element.tag_name == 'input' || element.tag_name == 'textarea'
294
- element.attribute('value')
295
- else
296
- element.text
297
- end
298
- end
299
-
300
- # Get text from several elements
301
- # @param [String] xpath_several_elements to find objects
302
- # @return [Array<String>] text of those elements
303
- def get_text_of_several_elements(xpath_several_elements)
304
- @driver.find_elements(:xpath, xpath_several_elements).filter_map { |element| element.text unless element.text == '' }
305
- end
306
-
307
- # Select value of combo box
308
- # @param [String] xpath_name to find combobox
309
- # @param [String] select_value to select
310
- # @param [Symbol] select_by select type
311
- # @return [void]
312
- def select_combo_box(xpath_name, select_value, select_by = :value)
313
- wait_until_element_visible(xpath_name)
314
- option = Selenium::WebDriver::Support::Select.new(get_element(xpath_name))
315
- begin
316
- option.select_by(select_by, select_value)
317
- rescue StandardError
318
- option.select_by(:text, select_value)
319
- end
320
- end
321
-
322
203
  # Get page source
323
204
  # @return [String] all page source
324
- def get_page_source
205
+ def page_source
325
206
  @driver.execute_script('return document.documentElement.innerHTML;')
326
207
  end
327
208
 
209
+ alias get_page_source page_source
210
+
211
+ extend Gem::Deprecate
212
+ deprecate :get_page_source, 'page_source', 2069, 1
213
+
328
214
  # Raise an error, making a screenshot before it
329
215
  # @param [String, Object] exception class to raise
330
216
  # @param [String] error_message to raise
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onlyoffice_webdriver_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ONLYOFFICE
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2022-07-07 00:00:00.000000000 Z
14
+ date: 2022-08-10 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: headless
@@ -31,16 +31,16 @@ dependencies:
31
31
  name: onlyoffice_file_helper
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
- - - "~>"
34
+ - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: '0'
36
+ version: '2'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - "~>"
41
+ - - "<"
42
42
  - !ruby/object:Gem::Version
43
- version: '0'
43
+ version: '2'
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: onlyoffice_logger_helper
46
46
  requirement: !ruby/object:Gem::Requirement
@@ -59,9 +59,9 @@ dependencies:
59
59
  name: onlyoffice_s3_wrapper
60
60
  requirement: !ruby/object:Gem::Requirement
61
61
  requirements:
62
- - - "~>"
62
+ - - "<"
63
63
  - !ruby/object:Gem::Version
64
- version: '0'
64
+ version: '2'
65
65
  - - ">="
66
66
  - !ruby/object:Gem::Version
67
67
  version: 0.5.0
@@ -69,9 +69,9 @@ dependencies:
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - "~>"
72
+ - - "<"
73
73
  - !ruby/object:Gem::Version
74
- version: '0'
74
+ version: '2'
75
75
  - - ">="
76
76
  - !ruby/object:Gem::Version
77
77
  version: 0.5.0
@@ -275,9 +275,9 @@ files:
275
275
  - lib/onlyoffice_webdriver_wrapper/helpers/bin/geckodriver
276
276
  - lib/onlyoffice_webdriver_wrapper/helpers/chrome_helper.rb
277
277
  - lib/onlyoffice_webdriver_wrapper/helpers/chrome_helper/chrome_version_helper.rb
278
- - lib/onlyoffice_webdriver_wrapper/helpers/chrome_helper/chromedriver_bin/chromedriver_linux_101
279
278
  - lib/onlyoffice_webdriver_wrapper/helpers/chrome_helper/chromedriver_bin/chromedriver_linux_102
280
279
  - lib/onlyoffice_webdriver_wrapper/helpers/chrome_helper/chromedriver_bin/chromedriver_linux_103
280
+ - lib/onlyoffice_webdriver_wrapper/helpers/chrome_helper/chromedriver_bin/chromedriver_linux_104
281
281
  - lib/onlyoffice_webdriver_wrapper/helpers/chrome_helper/chromedriver_bin/chromedriver_mac
282
282
  - lib/onlyoffice_webdriver_wrapper/helpers/firefox_helper.rb
283
283
  - lib/onlyoffice_webdriver_wrapper/helpers/firefox_helper/save_to_disk_files.list
@@ -291,6 +291,9 @@ files:
291
291
  - lib/onlyoffice_webdriver_wrapper/version.rb
292
292
  - lib/onlyoffice_webdriver_wrapper/webdriver.rb
293
293
  - lib/onlyoffice_webdriver_wrapper/webdriver/click_methods.rb
294
+ - lib/onlyoffice_webdriver_wrapper/webdriver/element_getters.rb
295
+ - lib/onlyoffice_webdriver_wrapper/webdriver/get_text_methods.rb
296
+ - lib/onlyoffice_webdriver_wrapper/webdriver/select_list_methods.rb
294
297
  - lib/onlyoffice_webdriver_wrapper/webdriver/wait_until_methods.rb
295
298
  - lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_alert_helper.rb
296
299
  - lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_attributes_helper.rb
@@ -332,7 +335,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
332
335
  - !ruby/object:Gem::Version
333
336
  version: '0'
334
337
  requirements: []
335
- rubygems_version: 3.3.17
338
+ rubygems_version: 3.3.20
336
339
  signing_key:
337
340
  specification_version: 4
338
341
  summary: ONLYOFFICE Webdriver Wrapper Gem