onlyoffice_webdriver_wrapper 1.7.0 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (21) hide show
  1. checksums.yaml +4 -4
  2. data/lib/onlyoffice_webdriver_wrapper/dimensions.rb +14 -0
  3. data/lib/onlyoffice_webdriver_wrapper/helpers/chrome_helper/chromedriver_bin/{chromedriver_linux_101 → chromedriver_linux_104} +0 -0
  4. data/lib/onlyoffice_webdriver_wrapper/helpers/chrome_helper/chromedriver_bin/chromedriver_mac +0 -0
  5. data/lib/onlyoffice_webdriver_wrapper/helpers/firefox_helper.rb +1 -1
  6. data/lib/onlyoffice_webdriver_wrapper/helpers/headless_helper/headless_patch.rb +1 -1
  7. data/lib/onlyoffice_webdriver_wrapper/version.rb +1 -1
  8. data/lib/onlyoffice_webdriver_wrapper/webdriver/click_methods.rb +5 -9
  9. data/lib/onlyoffice_webdriver_wrapper/webdriver/element_getters.rb +46 -0
  10. data/lib/onlyoffice_webdriver_wrapper/webdriver/get_text_methods.rb +46 -0
  11. data/lib/onlyoffice_webdriver_wrapper/webdriver/select_list_methods.rb +52 -0
  12. data/lib/onlyoffice_webdriver_wrapper/webdriver/wait_until_methods.rb +4 -4
  13. data/lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_exceptions.rb +2 -0
  14. data/lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_helper.rb +1 -1
  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_screenshot_helper.rb +2 -1
  18. data/lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb +4 -4
  19. data/lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_user_agent_helper.rb +8 -8
  20. data/lib/onlyoffice_webdriver_wrapper/webdriver.rb +9 -127
  21. metadata +7 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6dc61124365371ac4e24646ae4333ae1a590a6e2b0cf8c477c093e335e5d249f
4
- data.tar.gz: cba7d248075d58ebc1249166f684a92ca695b359b3e2e2472e3cc1cbe2ea84da
3
+ metadata.gz: fdfe224abc7b1f2c7e69e8830ec5cc388d3b8fa165a969f8860a832e1ab51319
4
+ data.tar.gz: cf61e06fce72afbb30398cdd62693544107059701316698705da602231eb7d9a
5
5
  SHA512:
6
- metadata.gz: dc5c7c14c73b7ed444ee5f5f1278867199b13b5b2b6a30e9cd0e0018c0456e79d8a029cc7e4a5ce578588e2af4a9f63ad0f890e337338bc9b634d3212931d71a
7
- data.tar.gz: 6283edb3f3b215c3c6aea865e7aaaa9ed2908374a2325d1eb7eda334e72325b07c9aa6a93929b809f895c7e28b9aba1676808ca79dba5329cb8b17a012deef0b
6
+ metadata.gz: '061282552a87103e53e3d94f4ce3be7d8a811378ad6d64c1620089b7f259ce231c8d7de931d8a60c83a7b601c31f599b7ccf3e92a4d86ae22efae2f5d8f5b6c6'
7
+ data.tar.gz: 7d0d8e1528f07f2a8bca61a972acf872075870ffd2dba37b088e9969c4b2f8d9ed91baee62df2a2b732930a77c9e0b0760541b743496d333cdc464c61ce08d5e
@@ -10,6 +10,15 @@ module OnlyofficeWebdriverWrapper
10
10
  @top = top
11
11
  end
12
12
 
13
+ # Compare two dimensions object
14
+ # @param [Object] other object
15
+ # @return [Boolean] result of comparison
16
+ def ==(other)
17
+ return false unless other.respond_to?(:left) && other.respond_to?(:top)
18
+
19
+ @left == other.left && @top == other.top
20
+ end
21
+
13
22
  alias width left
14
23
  alias height top
15
24
  alias x left
@@ -19,5 +28,10 @@ module OnlyofficeWebdriverWrapper
19
28
  def to_s
20
29
  "Dimensions(left: #{@left}, top: #{@top})"
21
30
  end
31
+
32
+ # @return [Dimensions] Center point of current dimension
33
+ def center
34
+ Dimensions.new(@left / 2, @top / 2)
35
+ end
22
36
  end
23
37
  end
@@ -29,7 +29,7 @@ module OnlyofficeWebdriverWrapper
29
29
 
30
30
  # @return [Array<String>] list of formats to save
31
31
  def read_firefox_files_to_save
32
- path_to_file = "#{Dir.pwd}/lib/onlyoffice_webdriver_wrapper/"\
32
+ path_to_file = "#{Dir.pwd}/lib/onlyoffice_webdriver_wrapper/" \
33
33
  'helpers/firefox_helper/save_to_disk_files.list'
34
34
  OnlyofficeFileHelper::FileHelper.read_array_from_file(path_to_file)
35
35
  .join(', ')
@@ -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
@@ -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.7.0'
7
+ STRING = '1.9.0'
8
8
  end
9
9
  end
@@ -50,10 +50,8 @@ module OnlyofficeWebdriverWrapper
50
50
  # @return [nil]
51
51
  def click_on_locator_coordinates(xpath_name, right_by, down_by)
52
52
  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
53
+ move_to_driver_action(xpath_name, right_by, down_by).perform
54
+ move_to_driver_action(xpath_name, right_by, down_by).click.perform
57
55
  end
58
56
 
59
57
  # Click on one of several which displayed
@@ -100,10 +98,8 @@ module OnlyofficeWebdriverWrapper
100
98
  # @return [nil]
101
99
  def right_click_on_locator_coordinates(xpath_name, right_by = nil, down_by = nil)
102
100
  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
101
+ move_to_driver_action(xpath_name, right_by, down_by).perform
102
+ move_to_driver_action(xpath_name, right_by, down_by).context_click.perform
107
103
  end
108
104
 
109
105
  # Perform double_click on element
@@ -121,7 +117,7 @@ module OnlyofficeWebdriverWrapper
121
117
  # @return [nil]
122
118
  def double_click_on_locator_coordinates(xpath_name, right_by, down_by)
123
119
  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
120
+ move_to_driver_action(xpath_name, right_by, down_by).double_click.perform
125
121
  end
126
122
  end
127
123
  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,46 @@
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 { |element| element.text unless element.text == '' }
44
+ end
45
+ end
46
+ 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
@@ -71,8 +71,8 @@ module OnlyofficeWebdriverWrapper
71
71
  begin
72
72
  wait.until { get_element(xpath_name) }
73
73
  rescue Selenium::WebDriver::Error::TimeoutError => e
74
- timeout_message = "wait_until_element_present(#{xpath_name}) "\
75
- 'Selenium::WebDriver::Error::TimeoutError: '\
74
+ timeout_message = "wait_until_element_present(#{xpath_name}) " \
75
+ 'Selenium::WebDriver::Error::TimeoutError: ' \
76
76
  "timed out after #{timeout} seconds"
77
77
  webdriver_error(e.class, timeout_message)
78
78
  end
@@ -88,8 +88,8 @@ module OnlyofficeWebdriverWrapper
88
88
  begin
89
89
  wait.until { get_element(xpath_name) ? false : true }
90
90
  rescue Selenium::WebDriver::Error::TimeoutError => e
91
- timeout_message = "wait_until_element_present(#{xpath_name}) "\
92
- 'Selenium::WebDriver::Error::TimeoutError: '\
91
+ timeout_message = "wait_until_element_present(#{xpath_name}) " \
92
+ 'Selenium::WebDriver::Error::TimeoutError: ' \
93
93
  "timed out after #{timeout} seconds"
94
94
  webdriver_error(e.class, timeout_message)
95
95
  end
@@ -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
@@ -33,7 +33,7 @@ module OnlyofficeWebdriverWrapper
33
33
  if @download_directory.start_with?(Dir.tmpdir)
34
34
  FileUtils.remove_dir(@download_directory)
35
35
  else
36
- OnlyofficeLoggerHelper.log("Download directory #{@download_directory} is not at tmp dir. "\
36
+ OnlyofficeLoggerHelper.log("Download directory #{@download_directory} is not at tmp dir. " \
37
37
  'It will be not deleted')
38
38
  end
39
39
  end
@@ -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
@@ -104,8 +95,8 @@ module OnlyofficeWebdriverWrapper
104
95
  # @param [String] xpath of element to remove
105
96
  # @return [String] result of javascript execution
106
97
  def remove_element(xpath)
107
- script = "element = #{dom_element_by_xpath(xpath)};"\
108
- 'if (element !== null) '\
98
+ script = "element = #{dom_element_by_xpath(xpath)};" \
99
+ 'if (element !== null) ' \
109
100
  '{element.parentNode.removeChild(element);};'
110
101
  execute_javascript(script)
111
102
  end
@@ -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
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'fileutils'
3
4
  require 'onlyoffice_s3_wrapper'
4
5
  module OnlyofficeWebdriverWrapper
5
6
  # Working with screenshots
@@ -25,7 +26,7 @@ module OnlyofficeWebdriverWrapper
25
26
  begin
26
27
  get_screenshot(path_to_screenshot)
27
28
  cloud_screenshot = publish_screenshot(path_to_screenshot)
28
- File.delete(path_to_screenshot) if File.exist?(path_to_screenshot)
29
+ FileUtils.rm_rf(path_to_screenshot)
29
30
  OnlyofficeLoggerHelper.log("upload screenshot: #{cloud_screenshot}")
30
31
  return cloud_screenshot
31
32
  rescue Errno::ENOENT => e
@@ -38,9 +38,9 @@ module OnlyofficeWebdriverWrapper
38
38
  begin
39
39
  element.clear
40
40
  rescue Exception => e
41
- webdriver_error(e.class, "Error in element.clear #{e} for "\
42
- "type_to_locator(#{xpath_name}, #{text_to_send}, "\
43
- "#{clear_content}, #{click_on_it}, "\
41
+ webdriver_error(e.class, "Error in element.clear #{e} for " \
42
+ "type_to_locator(#{xpath_name}, #{text_to_send}, " \
43
+ "#{clear_content}, #{click_on_it}, " \
44
44
  "#{by_action}, #{by_element_send_key})")
45
45
  end
46
46
  end
@@ -73,7 +73,7 @@ module OnlyofficeWebdriverWrapper
73
73
  element = get_element(xpath_name)
74
74
  if element.nil?
75
75
  webdriver_error(Selenium::WebDriver::Error::NoSuchElementError,
76
- "type_to_input(#{xpath_name}, #{text_to_send}, "\
76
+ "type_to_input(#{xpath_name}, #{text_to_send}, " \
77
77
  "#{clear_content}, #{click_on_it}): element not found")
78
78
  end
79
79
  element.clear if clear_content
@@ -4,20 +4,20 @@ module OnlyofficeWebdriverWrapper
4
4
  # Module for working with webdriver useragent
5
5
  module WebdriverUserAgentHelper
6
6
  # @return [String] useragent for Android phone browser
7
- USERAGENT_ANDROID_PHONE = 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MDB08M) '\
8
- 'AppleWebKit/537.36 (KHTML, like Gecko) '\
7
+ USERAGENT_ANDROID_PHONE = 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MDB08M) ' \
8
+ 'AppleWebKit/537.36 (KHTML, like Gecko) ' \
9
9
  'Chrome/51.0.2704.81 Mobile Safari/537.36'
10
10
  # @return [String] useragent for iPhone browser
11
- USERAGENT_IPHONE = 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_2 like Mac OS X) '\
12
- 'AppleWebKit/601.1.46 (KHTML, like Gecko) '\
11
+ USERAGENT_IPHONE = 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_2 like Mac OS X) ' \
12
+ 'AppleWebKit/601.1.46 (KHTML, like Gecko) ' \
13
13
  'Version/9.0 Mobile/13F69 Safari/601.1'
14
14
  # @return [String] useragent for iPad Air 2 Safari browser
15
- USERAGENT_IPAD_AIR_2_SAFARI = 'Mozilla/5.0 (iPad; CPU OS 10_0 like Mac OS X) '\
16
- 'AppleWebKit/602.1.50 (KHTML, like Gecko) '\
15
+ USERAGENT_IPAD_AIR_2_SAFARI = 'Mozilla/5.0 (iPad; CPU OS 10_0 like Mac OS X) ' \
16
+ 'AppleWebKit/602.1.50 (KHTML, like Gecko) ' \
17
17
  'Version/10.0 Mobile/14A5346a Safari/602.1'
18
18
  # @return [String] useragent for Nexus 10 Chrome browser
19
- USERAGENT_NEXUS_10_CHROME = 'Mozilla/5.0 (Linux; Android 4.3; Nexus 10 Build/JSS15Q) '\
20
- 'AppleWebKit/537.36 (KHTML, like Gecko) '\
19
+ USERAGENT_NEXUS_10_CHROME = 'Mozilla/5.0 (Linux; Android 4.3; Nexus 10 Build/JSS15Q) ' \
20
+ 'AppleWebKit/537.36 (KHTML, like Gecko) ' \
21
21
  'Chrome/48.0.2564.23 Safari/537.36'
22
22
 
23
23
  # @return [String, nil] user agent string for current device
@@ -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,61 +96,6 @@ 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] title to compare text
123
- # @param [Array<Objects>] list_elements to find in which
124
- # @return [Object, nil] nil if nothing found
125
- def get_element_index(title, list_elements)
126
- list_elements.each_with_index do |current, i|
127
- return i if get_text(current) == title
128
- end
129
- nil
130
- end
131
-
132
- # Get all options for combo box
133
- # @param [String] xpath_name to find combobox
134
- # @return [Array<String>] values
135
- def get_all_combo_box_values(xpath_name)
136
- @driver.find_element(:xpath, xpath_name).find_elements(tag_name: 'option').map { |el| el.attribute('value') }
137
- end
138
-
139
- # Scroll list to specific element
140
- # @param [String] list_xpath how to find this list
141
- # @param [String] element_xpath to which we should scrolled
142
- # @return [void]
143
- def scroll_list_to_element(list_xpath, element_xpath)
144
- execute_javascript("$(document.evaluate(\"#{list_xpath}\", document, null, XPathResult.ANY_TYPE, null).
145
- iterateNext()).jScrollPane().data('jsp').scrollToElement(document.evaluate(\"#{element_xpath}\",
146
- document, null, XPathResult.ANY_TYPE, null).iterateNext());")
147
- end
148
-
149
99
  # Scroll list by pixel count
150
100
  # @param [String] list_xpath how to detect this list
151
101
  # @param [Integer] pixels how much to scroll
@@ -168,8 +118,7 @@ module OnlyofficeWebdriverWrapper
168
118
  set_style_attribute("#{xpath_name}/button", 'display', 'inline-block')
169
119
  set_style_attribute(xpath_name, 'display', 'block')
170
120
  else
171
- shift_to_zero = move_to_shift_to_top_left(xpath_name)
172
- @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
173
122
  end
174
123
  end
175
124
 
@@ -182,14 +131,11 @@ module OnlyofficeWebdriverWrapper
182
131
  # @return [void]
183
132
  def action_on_locator_coordinates(xpath_name, right_by, down_by, action = :click, times = 1)
184
133
  wait_until_element_visible(xpath_name)
185
- element = @driver.find_element(:xpath, xpath_name)
186
- shift_to_zero = move_to_shift_to_top_left(xpath_name)
187
- (0...times).inject(@driver.action.move_to(element,
188
- right_by.to_i - shift_to_zero.x,
189
- 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
190
135
  end
191
136
 
192
137
  # Check if element present on page
138
+ # It may be visible or invisible, but should be present in DOM tree
193
139
  # @param [String] xpath_name to find element
194
140
  # @return [Boolean] result of check
195
141
  def element_present?(xpath_name)
@@ -206,17 +152,6 @@ module OnlyofficeWebdriverWrapper
206
152
  false
207
153
  end
208
154
 
209
- # Get first visible element from several
210
- # @param [String] xpath_name to find several objects
211
- # @return [Object] first visible element
212
- def get_element_by_display(xpath_name)
213
- @driver.find_elements(:xpath, xpath_name).each do |element|
214
- return element if element.displayed?
215
- end
216
- rescue Selenium::WebDriver::Error::InvalidSelectorError
217
- webdriver_error("get_element_by_display(#{xpath_name}): invalid selector: Unable to locate an element with the xpath expression")
218
- end
219
-
220
155
  # Return count of elements (visible and not visible)
221
156
  # @param xpath_name [String] xpath to find
222
157
  # @param only_visible [True, False] count only visible elements?
@@ -230,23 +165,8 @@ module OnlyofficeWebdriverWrapper
230
165
  end
231
166
  end
232
167
 
233
- # Get array of webdriver object by xpath
234
- # @param [String] objects_identification object to find
235
- # @param [Boolean] only_visible return invisible if true
236
- # @return [Array, Object] list of objects
237
- def get_elements(objects_identification, only_visible = true)
238
- return objects_identification if objects_identification.is_a?(Array)
239
-
240
- elements = @driver.find_elements(:xpath, objects_identification)
241
- if only_visible
242
- elements.each do |current|
243
- elements.delete(current) unless @browser == :firefox || current.displayed?
244
- end
245
- end
246
- elements
247
- end
248
-
249
168
  # Check if element visible on page
169
+ # It should be part of DOM and should be visible on current visible part of page
250
170
  # @param [String] xpath_name element to find
251
171
  # @return [Boolean] result of check
252
172
  def element_visible?(xpath_name)
@@ -280,44 +200,6 @@ module OnlyofficeWebdriverWrapper
280
200
  webdriver_error("Raise unknown exception: #{e}")
281
201
  end
282
202
 
283
- # Get text of current element
284
- # @param [String] xpath_name name of xpath
285
- # @param [Boolean] wait_until_visible wait until element visible
286
- # @return [String] result string
287
- def get_text(xpath_name, wait_until_visible = true)
288
- wait_until_element_visible(xpath_name) if wait_until_visible
289
-
290
- element = get_element(xpath_name)
291
- webdriver_error("get_text(#{xpath_name}, #{wait_until_visible}) not found element by xpath") if element.nil?
292
- if element.tag_name == 'input' || element.tag_name == 'textarea'
293
- element.attribute('value')
294
- else
295
- element.text
296
- end
297
- end
298
-
299
- # Get text from several elements
300
- # @param [String] xpath_several_elements to find objects
301
- # @return [Array<String>] text of those elements
302
- def get_text_of_several_elements(xpath_several_elements)
303
- @driver.find_elements(:xpath, xpath_several_elements).filter_map { |element| element.text unless element.text == '' }
304
- end
305
-
306
- # Select value of combo box
307
- # @param [String] xpath_name to find combobox
308
- # @param [String] select_value to select
309
- # @param [Symbol] select_by select type
310
- # @return [void]
311
- def select_combo_box(xpath_name, select_value, select_by = :value)
312
- wait_until_element_visible(xpath_name)
313
- option = Selenium::WebDriver::Support::Select.new(get_element(xpath_name))
314
- begin
315
- option.select_by(select_by, select_value)
316
- rescue StandardError
317
- option.select_by(:text, select_value)
318
- end
319
- end
320
-
321
203
  # Get page source
322
204
  # @return [String] all page source
323
205
  def get_page_source
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.7.0
4
+ version: 1.9.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-06-24 00:00:00.000000000 Z
14
+ date: 2022-08-01 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: headless
@@ -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.16
338
+ rubygems_version: 3.3.19
336
339
  signing_key:
337
340
  specification_version: 4
338
341
  summary: ONLYOFFICE Webdriver Wrapper Gem