onlyoffice_webdriver_wrapper 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7dd9754453bdfc98d527929ed558a8a8d7246b25e1ddd836b0af4a57ffc4d55
4
- data.tar.gz: 49ca15eea9259e832423665aa0c7a86cc5d2afc17068c65fc6990c272a88091e
3
+ metadata.gz: 198918d5a397566f6099da61229da418520359f28a8eae58c554291303319ccb
4
+ data.tar.gz: a4f7e7764c1a49456b5eed0d8a851a20eb6a3fc38890b222c66540927b03fa11
5
5
  SHA512:
6
- metadata.gz: c7dbe1f1368fb5a3f0b027ede5abc619e97dca747709066fe3fd0d3d7c5c2d89d01a7e45a0eb034652fe238fbb89959fe86deb7dd307ad28b24627381842eba5
7
- data.tar.gz: aa67c58fe56ac730be39894b7aa316dc6e134938c89d13f0c46000d18008244f3d90d631ad0d50ae88a25e77c2808870dc470d7d61b582581376f65335c49a3b
6
+ metadata.gz: 6c7bbf7385332599f38140a7457db436d79ffb298ba63d0895d8582f8092049962b69b6b819ff27b2700e42d6a0ed272776714ef6fc4a4ddc523549e746cde17
7
+ data.tar.gz: 4776a813a596cbb702e4b1a9664ca22b92f65b5eeebe1523adc5ff29b012abee0a698451eab7802cc8c4933f85d8c808244ef29e487693f6d668a0260340cd34
@@ -10,8 +10,11 @@ module OnlyofficeWebdriverWrapper
10
10
  class HeadlessHelper
11
11
  include RealDisplayTools
12
12
  include RubyHelper
13
+ # @return [Headless] instance of headless object
13
14
  attr_accessor :headless_instance
15
+ # @return [Integer] x resolution of virtual screen
14
16
  attr_accessor :resolution_x
17
+ # @return [Integer] y resolution of virtual screen
15
18
  attr_accessor :resolution_y
16
19
 
17
20
  def initialize(resolution_x = 1680, resolution_y = 1050)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OnlyofficeWebdriverWrapper
4
4
  module Version
5
- STRING = '0.3.1'
5
+ STRING = '0.4.0'
6
6
  end
7
7
  end
@@ -7,6 +7,8 @@ require 'selenium-webdriver'
7
7
  require 'uri'
8
8
  require_relative 'helpers/chrome_helper'
9
9
  require_relative 'helpers/firefox_helper'
10
+ require_relative 'webdriver/click_methods'
11
+ require_relative 'webdriver/wait_until_methods'
10
12
  require_relative 'webdriver/webdriver_alert_helper'
11
13
  require_relative 'webdriver/webdriver_attributes_helper'
12
14
  require_relative 'webdriver/webdriver_browser_info_helper'
@@ -24,8 +26,10 @@ module OnlyofficeWebdriverWrapper
24
26
  # noinspection RubyTooManyMethodsInspection, RubyInstanceMethodNamingConvention, RubyParameterNamingConvention
25
27
  class WebDriver
26
28
  include ChromeHelper
29
+ include ClickMethods
27
30
  include FirefoxHelper
28
31
  include RubyHelper
32
+ include WaitUntilMethods
29
33
  include WebdriverAlertHelper
30
34
  include WebdriverAttributesHelper
31
35
  include WebdriverBrowserInfo
@@ -37,17 +41,18 @@ module OnlyofficeWebdriverWrapper
37
41
  include WebdriverTabHelper
38
42
  include WebdriverUserAgentHelper
39
43
  include WebdriverBrowserLogHelper
40
- TIMEOUT_WAIT_ELEMENT = 15
41
44
  TIMEOUT_FILE_DOWNLOAD = 100
42
45
  # @return [Array, String] default switches for chrome
43
46
  attr_accessor :driver
47
+ # @return [Symbol] browser to use
44
48
  attr_accessor :browser
45
49
  # @return [True, False] is browser currently running
46
50
  attr_reader :browser_running
47
51
  # @return [Symbol] device of which we try to simulate, default - :desktop_linux
48
52
  attr_accessor :device
53
+ # @return [String] directory to which file is downloaded
49
54
  attr_accessor :download_directory
50
- attr_accessor :server_address
55
+ # @return [HeadlessHelper] headless wrapper
51
56
  attr_accessor :headless
52
57
  # @return [Net::HTTP::Proxy] connection proxy
53
58
  attr_accessor :proxy
@@ -123,20 +128,6 @@ module OnlyofficeWebdriverWrapper
123
128
  get_elements(array_elements).map { |current_element| get_text(current_element) }
124
129
  end
125
130
 
126
- def click(element)
127
- element.click
128
- end
129
-
130
- def click_and_wait(element_to_click, element_to_wait)
131
- element_to_click.click
132
- count = 0
133
- while !element_to_wait.present? && count < 30
134
- sleep 1
135
- count += 1
136
- end
137
- webdriver_error("click_and_wait: Wait for element: #{element_to_click} for 30 seconds") if count == 30
138
- end
139
-
140
131
  def select_from_list_elements(value, elements_value)
141
132
  index = get_element_index(value, elements_value)
142
133
  elements_value[index].click
@@ -171,27 +162,6 @@ module OnlyofficeWebdriverWrapper
171
162
  OnlyofficeLoggerHelper.log('Go back to previous page')
172
163
  end
173
164
 
174
- def self.host_name_by_full_url(full_url)
175
- uri = URI(full_url)
176
- uri.port == 80 || uri.port == 443 ? "#{uri.scheme}://#{uri.host}" : "#{uri.scheme}://#{uri.host}:#{uri.port}"
177
- end
178
-
179
- def get_host_name
180
- WebDriver.host_name_by_full_url(get_url)
181
- end
182
-
183
- def remove_event(event_name)
184
- execute_javascript("jQuery(document).unbind('#{event_name}');")
185
- end
186
-
187
- def remove_class_by_jquery(selector, class_name)
188
- execute_javascript("$(#{dom_element_by_xpath(selector)}).removeClass('#{class_name}');")
189
- end
190
-
191
- def add_class_by_jquery(selector, class_name)
192
- execute_javascript("$(#{dom_element_by_xpath(selector)}).addClass('#{class_name}');")
193
- end
194
-
195
165
  # Perform drag'n'drop action in one element (for example on big canvas area)
196
166
  # for drag'n'drop one whole element use 'drag_and_drop_by'
197
167
  # ==== Attributes
@@ -250,119 +220,12 @@ module OnlyofficeWebdriverWrapper
250
220
  end
251
221
  end
252
222
 
253
- # Click on locator
254
- # @param count [Integer] count of clicks
255
- def click_on_locator(xpath_name, by_javascript = false, count: 1)
256
- element = get_element(xpath_name)
257
- return webdriver_error("Element with xpath: #{xpath_name} not found") if element.nil?
258
-
259
- if by_javascript
260
- execute_javascript("document.evaluate(\"#{xpath_name}\", document, null, XPathResult.ANY_TYPE, null).iterateNext().click();")
261
- else
262
- begin
263
- count.times { element.click }
264
- rescue Selenium::WebDriver::Error::ElementNotVisibleError
265
- webdriver_error("Selenium::WebDriver::Error::ElementNotVisibleError: element not visible for xpath: #{xpath_name}")
266
- rescue Exception => e
267
- webdriver_error(e.class, "UnknownError #{e.message} #{xpath_name}")
268
- end
269
- end
270
- end
271
-
272
- def left_mouse_click(xpath, x_coord, y_coord)
273
- @driver.action.move_to(get_element(xpath), x_coord.to_i, y_coord.to_i).click.perform
274
- end
275
-
276
- # Context click on locator
277
- # @param [String] xpath_name name of xpath to click
278
- def context_click_on_locator(xpath_name)
279
- wait_until_element_visible(xpath_name)
280
-
281
- element = @driver.find_element(:xpath, xpath_name)
282
- @driver.action.context_click(element).perform
283
- end
284
-
285
- def right_click(xpath_name)
286
- @driver.action.context_click(@driver.find_element(:xpath, xpath_name)).perform
287
- end
288
-
289
- def click_on_displayed(xpath_name)
290
- element = get_element_by_display(xpath_name)
291
- begin
292
- element.is_a?(Array) ? element.first.click : element.click
293
- rescue Exception => e
294
- webdriver_error("Exception #{e} in click_on_displayed(#{xpath_name})")
295
- end
296
- end
297
-
298
- def click_on_locator_coordinates(xpath_name, right_by, down_by)
299
- wait_until_element_visible(xpath_name)
300
- element = @driver.find_element(:xpath, xpath_name)
301
- @driver.action.move_to(element, right_by.to_i, down_by.to_i).perform
302
- @driver.action.move_to(element, right_by.to_i, down_by.to_i).click.perform
303
- end
304
-
305
- def right_click_on_locator_coordinates(xpath_name, right_by = nil, down_by = nil)
306
- wait_until_element_visible(xpath_name)
307
- element = @driver.find_element(:xpath, xpath_name)
308
- @driver.action.move_to(element, right_by.to_i, down_by.to_i).perform
309
- @driver.action.move_to(element, right_by.to_i, down_by.to_i).context_click.perform
310
- end
311
-
312
- def double_click(xpath_name)
313
- wait_until_element_visible(xpath_name)
314
- @driver.action.move_to(@driver.find_element(:xpath, xpath_name)).double_click.perform
315
- end
316
-
317
- def double_click_on_locator_coordinates(xpath_name, right_by, down_by)
318
- wait_until_element_visible(xpath_name)
319
- @driver.action.move_to(@driver.find_element(:xpath, xpath_name), right_by.to_i, down_by.to_i).double_click.perform
320
- end
321
-
322
223
  def action_on_locator_coordinates(xpath_name, right_by, down_by, action = :click, times = 1)
323
224
  wait_until_element_visible(xpath_name)
324
225
  element = @driver.find_element(:xpath, xpath_name)
325
226
  (0...times).inject(@driver.action.move_to(element, right_by.to_i, down_by.to_i)) { |acc, _elem| acc.send(action) }.perform
326
227
  end
327
228
 
328
- def click_on_one_of_several_by_text(xpath_several_elements, text_to_click)
329
- @driver.find_elements(:xpath, xpath_several_elements).each do |current_element|
330
- next unless text_to_click.to_s == current_element.attribute('innerHTML')
331
-
332
- begin
333
- current_element.click
334
- rescue Exception => e
335
- webdriver_error("Error in click_on_one_of_several_by_text(#{xpath_several_elements}, #{text_to_click}): #{e.message}")
336
- end
337
- return true
338
- end
339
- false
340
- end
341
-
342
- def click_on_one_of_several_by_display(xpath_several_elements)
343
- @driver.find_elements(:xpath, xpath_several_elements).each do |current_element|
344
- if current_element.displayed?
345
- current_element.click
346
- return true
347
- end
348
- end
349
- false
350
- end
351
-
352
- def click_on_one_of_several_by_parameter(xpath_several_elements, parameter_name, parameter_value)
353
- @driver.find_elements(:xpath, xpath_several_elements).each do |current_element|
354
- if current_element.attribute(parameter_name).include? parameter_value
355
- current_element.click
356
- return true
357
- end
358
- end
359
- false
360
- end
361
-
362
- def click_on_one_of_several_xpath_by_number(xpath, number_of_element)
363
- click_on_locator("(#{xpath})[#{number_of_element}]")
364
- end
365
-
366
229
  def move_to_element(element)
367
230
  element = get_element(element) if element.is_a?(String)
368
231
  @driver.action.move_to(element).perform
@@ -380,9 +243,10 @@ module OnlyofficeWebdriverWrapper
380
243
  end
381
244
 
382
245
  def element_present?(xpath_name)
383
- if xpath_name.is_a?(PageObject::Elements::Element)
246
+ case xpath_name
247
+ when PageObject::Elements::Element
384
248
  xpath_name.present?
385
- elsif xpath_name.is_a?(Selenium::WebDriver::Element)
249
+ when Selenium::WebDriver::Element
386
250
  xpath_name.displayed?
387
251
  else
388
252
  @driver.find_element(:xpath, xpath_name)
@@ -392,24 +256,6 @@ module OnlyofficeWebdriverWrapper
392
256
  false
393
257
  end
394
258
 
395
- def wait_until_element_present(xpath_name)
396
- wait = Selenium::WebDriver::Wait.new(timeout: TIMEOUT_WAIT_ELEMENT) # seconds
397
- begin
398
- wait.until { get_element(xpath_name) }
399
- rescue Selenium::WebDriver::Error::TimeOutError
400
- webdriver_error("wait_until_element_present(#{xpath_name}) Selenium::WebDriver::Error::TimeOutError: timed out after 15 seconds")
401
- end
402
- end
403
-
404
- def wait_until_element_disappear(xpath_name)
405
- wait = Selenium::WebDriver::Wait.new(timeout: TIMEOUT_WAIT_ELEMENT) # seconds
406
- begin
407
- wait.until { get_element(xpath_name) ? false : true }
408
- rescue Selenium::WebDriver::Error::TimeOutError
409
- webdriver_error("wait_until_element_present(#{xpath_name}) Selenium::WebDriver::Error::TimeOutError: timed out after 15 seconds")
410
- end
411
- end
412
-
413
259
  def get_element_by_display(xpath_name)
414
260
  @driver.find_elements(:xpath, xpath_name).each do |element|
415
261
  return element if element.displayed?
@@ -461,18 +307,6 @@ module OnlyofficeWebdriverWrapper
461
307
  end
462
308
  end
463
309
 
464
- def wait_until_element_visible(xpath_name, timeout = 15)
465
- wait_until_element_present(xpath_name)
466
- time = 0
467
- while !element_visible?(xpath_name) && time < timeout
468
- sleep(1)
469
- time += 1
470
- end
471
- return unless time >= timeout
472
-
473
- webdriver_error("Element #{xpath_name} not visible for #{timeout} seconds")
474
- end
475
-
476
310
  # Check if any element of xpath is displayed
477
311
  # @param xpath_several_elements [String] xpath to check
478
312
  # @return [True, False] result of visibility
@@ -538,16 +372,6 @@ module OnlyofficeWebdriverWrapper
538
372
  @driver.find_elements(:xpath, xpath_several_elements).map { |element| element.text unless element.text == '' }.compact
539
373
  end
540
374
 
541
- def set_parameter(xpath, attribute, attribute_value)
542
- execute_javascript("document.evaluate(\"#{xpath.tr('"', "'")}\",document, null, XPathResult.ANY_TYPE, null ).iterateNext()." \
543
- "#{attribute}=\"#{attribute_value}\";")
544
- end
545
-
546
- def remove_attribute(xpath, attribute)
547
- execute_javascript("document.evaluate(\"#{xpath}\",document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null)." \
548
- "singleNodeValue.removeAttribute('#{attribute}');")
549
- end
550
-
551
375
  def select_combo_box(xpath_name, select_value, select_by = :value)
552
376
  wait_until_element_visible(xpath_name)
553
377
  option = Selenium::WebDriver::Support::Select.new(get_element(xpath_name))
@@ -574,22 +398,6 @@ module OnlyofficeWebdriverWrapper
574
398
  raise exception, "#{error_message}\n\nPage address: #{current_url}\n\nError #{webdriver_screenshot}"
575
399
  end
576
400
 
577
- def wait_until(timeout = ::PageObject.default_page_wait, message = nil, wait_js: true, &block)
578
- tries ||= 3
579
- wait = Object::Selenium::WebDriver::Wait.new(timeout: timeout, message: message)
580
- wait.until(&block)
581
- if wait_js
582
- wait.until { document_ready? }
583
- wait.until { jquery_finished? }
584
- end
585
- rescue Selenium::WebDriver::Error::TimeOutError
586
- webdriver_error("Wait until timeout: #{timeout} seconds in")
587
- rescue Selenium::WebDriver::Error::StaleElementReferenceError
588
- OnlyofficeLoggerHelper.log("Wait until: rescuing from Stale Element error, #{tries} attempts remaining")
589
- retry unless (tries -= 1).zero?
590
- webdriver_error('Wait until: rescuing from Stale Element error failed after 3 tries')
591
- end
592
-
593
401
  def wait_file_for_download(file_name, timeout = TIMEOUT_FILE_DOWNLOAD)
594
402
  full_file_name = "#{@download_directory}/#{file_name}"
595
403
  full_file_name = file_name if file_name[0] == '/'
@@ -603,11 +411,6 @@ module OnlyofficeWebdriverWrapper
603
411
  full_file_name
604
412
  end
605
413
 
606
- def service_unavailable?
607
- source = get_page_source
608
- source.include?('Error 503')
609
- end
610
-
611
414
  # Perform cleanup if something went wrong during tests
612
415
  # @param forced [True, False] should cleanup run in all cases
613
416
  def self.clean_up(forced = false)
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeWebdriverWrapper
4
+ # Method to perform different clicks
5
+ module ClickMethods
6
+ # Click on specified element
7
+ # @param element [Selenium::WebDriver::Element] element to click
8
+ # @return [nil] nothing
9
+ def click(element)
10
+ element.click
11
+ end
12
+
13
+ # Click on locator
14
+ # @param xpath_name [String] xpath to click
15
+ # @param by_javascript [True, False] should be clicked by javascript
16
+ # @param count [Integer] count of clicks
17
+ def click_on_locator(xpath_name, by_javascript = false, count: 1)
18
+ element = get_element(xpath_name)
19
+ return webdriver_error("Element with xpath: #{xpath_name} not found") if element.nil?
20
+
21
+ if by_javascript
22
+ execute_javascript("document.evaluate(\"#{xpath_name}\", document, null, XPathResult.ANY_TYPE, null).iterateNext().click();")
23
+ else
24
+ begin
25
+ count.times { element.click }
26
+ rescue Selenium::WebDriver::Error::ElementNotVisibleError => e
27
+ webdriver_error(e.class, "Selenium::WebDriver::Error::ElementNotVisibleError: element not visible for xpath: #{xpath_name}")
28
+ rescue Exception => e
29
+ webdriver_error(e.class, "UnknownError #{e.message} #{xpath_name}")
30
+ end
31
+ end
32
+ end
33
+
34
+ # Click on one of several which displayed
35
+ # @param xpath_name [String] xpath to find element
36
+ # @return [nil]
37
+ def click_on_displayed(xpath_name)
38
+ element = get_element_by_display(xpath_name)
39
+ begin
40
+ element.is_a?(Array) ? element.first.click : element.click
41
+ rescue Exception => e
42
+ webdriver_error(e.class, "Exception #{e} in click_on_displayed(#{xpath_name})")
43
+ end
44
+ end
45
+
46
+ # Click on locator by coordinates
47
+ # @param xpath_name [String] xpath to click
48
+ # @param right_by [Integer] shift to right
49
+ # @param down_by [Integer] shift to bottom
50
+ # @return [nil]
51
+ def click_on_locator_coordinates(xpath_name, right_by, down_by)
52
+ wait_until_element_visible(xpath_name)
53
+ element = @driver.find_element(:xpath, xpath_name)
54
+ @driver.action.move_to(element, right_by.to_i, down_by.to_i).perform
55
+ @driver.action.move_to(element, right_by.to_i, down_by.to_i).click.perform
56
+ end
57
+
58
+ # Click on one of several which displayed
59
+ # @param xpath_several_elements [String] xpath to find element
60
+ # @return [True, False] true if click successful, false if not found
61
+ def click_on_one_of_several_by_display(xpath_several_elements)
62
+ @driver.find_elements(:xpath, xpath_several_elements).each do |current_element|
63
+ if current_element.displayed?
64
+ current_element.click
65
+ return true
66
+ end
67
+ end
68
+ false
69
+ end
70
+
71
+ # Click on one of several xpath filtered by parameter and value
72
+ # @param xpath_several_elements [String] xpath to select
73
+ # @param parameter_name [String] parameter name
74
+ # @param parameter_value [String] parameter value
75
+ # @return [True, False] true if click successful, false if not found
76
+ def click_on_one_of_several_by_parameter(xpath_several_elements, parameter_name, parameter_value)
77
+ @driver.find_elements(:xpath, xpath_several_elements).each do |current_element|
78
+ if current_element.attribute(parameter_name).include? parameter_value
79
+ current_element.click
80
+ return true
81
+ end
82
+ end
83
+ false
84
+ end
85
+
86
+ # Perform right click on xpath
87
+ # @param xpath_name [String] xpath to click
88
+ # @return [nil]
89
+ def right_click(xpath_name)
90
+ wait_until_element_visible(xpath_name)
91
+
92
+ @driver.action.context_click(@driver.find_element(:xpath, xpath_name)).perform
93
+ end
94
+
95
+ # Perform right click on locator with specified coordinates
96
+ # @param xpath_name [String] xpath to click
97
+ # @param right_by [Integer] shift to right
98
+ # @param down_by [Integer] shift to bottom
99
+ # @return [nil]
100
+ def right_click_on_locator_coordinates(xpath_name, right_by = nil, down_by = nil)
101
+ wait_until_element_visible(xpath_name)
102
+ element = @driver.find_element(:xpath, xpath_name)
103
+ @driver.action.move_to(element, right_by.to_i, down_by.to_i).perform
104
+ @driver.action.move_to(element, right_by.to_i, down_by.to_i).context_click.perform
105
+ end
106
+
107
+ # Perform double_click on element
108
+ # @param xpath_name [String] xpath to click
109
+ # @return [nil]
110
+ def double_click(xpath_name)
111
+ wait_until_element_visible(xpath_name)
112
+ @driver.action.move_to(@driver.find_element(:xpath, xpath_name)).double_click.perform
113
+ end
114
+
115
+ # Perform double_click on specified coordinates
116
+ # @param xpath_name [String] xpath to click
117
+ # @param right_by [Integer] shift to right
118
+ # @param down_by [Integer] shift to bottom
119
+ # @return [nil]
120
+ def double_click_on_locator_coordinates(xpath_name, right_by, down_by)
121
+ wait_until_element_visible(xpath_name)
122
+ @driver.action.move_to(@driver.find_element(:xpath, xpath_name), right_by.to_i, down_by.to_i).double_click.perform
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeWebdriverWrapper
4
+ # Method to different wait_until methods
5
+ module WaitUntilMethods
6
+ # @return [Integer] default timeout for wait element
7
+ TIMEOUT_WAIT_ELEMENT = 15
8
+
9
+ def wait_until(timeout = ::PageObject.default_page_wait, message = nil, wait_js: true, &block)
10
+ tries ||= 3
11
+ wait = Object::Selenium::WebDriver::Wait.new(timeout: timeout, message: message)
12
+ wait.until(&block)
13
+ if wait_js
14
+ wait.until { document_ready? }
15
+ wait.until { jquery_finished? }
16
+ end
17
+ rescue Selenium::WebDriver::Error::TimeOutError
18
+ webdriver_error("Wait until timeout: #{timeout} seconds in")
19
+ rescue Selenium::WebDriver::Error::StaleElementReferenceError
20
+ OnlyofficeLoggerHelper.log("Wait until: rescuing from Stale Element error, #{tries} attempts remaining")
21
+ retry unless (tries -= 1).zero?
22
+ webdriver_error('Wait until: rescuing from Stale Element error failed after 3 tries')
23
+ end
24
+
25
+ def wait_until_element_visible(xpath_name, timeout = 15)
26
+ wait_until_element_present(xpath_name)
27
+ time = 0
28
+ while !element_visible?(xpath_name) && time < timeout
29
+ sleep(1)
30
+ time += 1
31
+ end
32
+ return unless time >= timeout
33
+
34
+ webdriver_error("Element #{xpath_name} not visible for #{timeout} seconds")
35
+ end
36
+
37
+ # Wait until some element present
38
+ # If timeout exceeded - raise an error
39
+ # @param xpath_name [String] xpath of element
40
+ # @param timeout [Integer] timeout to wait
41
+ # @return [Void]
42
+ def wait_until_element_present(xpath_name, timeout: TIMEOUT_WAIT_ELEMENT)
43
+ wait = Selenium::WebDriver::Wait.new(timeout: timeout) # seconds
44
+ begin
45
+ wait.until { get_element(xpath_name) }
46
+ rescue Selenium::WebDriver::Error::TimeOutError => e
47
+ timeout_message = "wait_until_element_present(#{xpath_name}) "\
48
+ 'Selenium::WebDriver::Error::TimeOutError: '\
49
+ "timed out after #{timeout} seconds"
50
+ webdriver_error(e.class, timeout_message)
51
+ end
52
+ end
53
+
54
+ # Wait until some element disappear
55
+ # If timeout exceeded - raise an error
56
+ # @param xpath_name [String] xpath of element
57
+ # @param timeout [Integer] timeout to wait
58
+ # @return [Void]
59
+ def wait_until_element_disappear(xpath_name, timeout: TIMEOUT_WAIT_ELEMENT)
60
+ wait = Selenium::WebDriver::Wait.new(timeout: timeout) # seconds
61
+ begin
62
+ wait.until { get_element(xpath_name) ? false : true }
63
+ rescue Selenium::WebDriver::Error::TimeOutError => e
64
+ timeout_message = "wait_until_element_present(#{xpath_name}) "\
65
+ 'Selenium::WebDriver::Error::TimeOutError: '\
66
+ "timed out after #{timeout} seconds"
67
+ webdriver_error(e.class, timeout_message)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -40,5 +40,24 @@ module OnlyofficeWebdriverWrapper
40
40
  end
41
41
  0
42
42
  end
43
+
44
+ # Set element attribute
45
+ # @param xpath [String] element to select
46
+ # @param attribute [String] attribute to set
47
+ # @param attribute_value [String] value of attribute
48
+ # @return [String] result of execution
49
+ def set_attribute(xpath, attribute, attribute_value)
50
+ execute_javascript("#{dom_element_by_xpath(xpath)}.#{attribute}=\"#{attribute_value}\";")
51
+ end
52
+
53
+ alias set_parameter set_attribute
54
+
55
+ # Remove attribute of element
56
+ # @param xpath [String] xpath of element
57
+ # @param attribute [String] attribute to remove
58
+ # @return [String] result of execution
59
+ def remove_attribute(xpath, attribute)
60
+ execute_javascript("#{dom_element_by_xpath(xpath)}.removeAttribute('#{attribute}');")
61
+ end
43
62
  end
44
63
  end
@@ -28,8 +28,13 @@ module OnlyofficeWebdriverWrapper
28
28
  execute_javascript("document.evaluate('#{xpath_name}', document, null, XPathResult.ANY_TYPE, null).iterateNext().value=\"#{escaped_text}\";")
29
29
  end
30
30
 
31
+ # Get text in object by xpath
32
+ # @param xpath [String] xpath to get text
33
+ # @return [String] text in xpath
31
34
  def get_text_by_js(xpath)
32
- execute_javascript("return document.evaluate(\"#{xpath.tr('"', "'")}\",document, null, XPathResult.ANY_TYPE, null ).iterateNext().textContent")
35
+ text = execute_javascript("return #{dom_element_by_xpath(xpath)}.textContent")
36
+ text = execute_javascript("return #{dom_element_by_xpath(xpath)}.value") if text.empty?
37
+ text
33
38
  end
34
39
 
35
40
  # Calculate object size using Javascript
@@ -10,26 +10,23 @@ module OnlyofficeWebdriverWrapper
10
10
  nil
11
11
  end
12
12
 
13
- def set_style_parameter(xpath, attribute, attribute_value)
14
- execute_javascript("document.evaluate(\"#{xpath.tr('"', "'")}\",document, null, XPathResult.ANY_TYPE, null ).iterateNext()." \
15
- "style.#{attribute}=\"#{attribute_value}\"")
16
- end
17
-
13
+ # Set style attribute value of element
14
+ # @param xpath [String] xpath to set
15
+ # @param attribute [String] style param to set
16
+ # @param attribute_value [String] attribute value to set
17
+ # @return [String] result of execution
18
18
  def set_style_attribute(xpath, attribute, attribute_value)
19
- execute_javascript("document.evaluate('#{xpath}',document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null)." \
20
- "singleNodeValue.style.#{attribute}=\"#{attribute_value}\"")
19
+ execute_javascript("#{dom_element_by_xpath(xpath)}.style.#{attribute}=\"#{attribute_value}\"")
21
20
  end
22
21
 
22
+ alias set_style_parameter set_style_attribute
23
+
23
24
  def set_style_show_by_xpath(xpath, move_to_center = false)
24
- xpath = xpath.tr("'", '"')
25
- execute_javascript('document.evaluate( \'' + xpath.to_s +
26
- '\' ,document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue.style.display = "block";')
25
+ execute_javascript("#{dom_element_by_xpath(xpath)}.style.display = 'block';")
27
26
  return unless move_to_center
28
27
 
29
- execute_javascript('document.evaluate( \'' + xpath.to_s +
30
- '\' ,document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue.style.left = "410px";')
31
- execute_javascript('document.evaluate( \'' + xpath.to_s +
32
- '\' ,document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue.style.top = "260px";')
28
+ execute_javascript("#{dom_element_by_xpath(xpath)}.style.left = '410px';")
29
+ execute_javascript("#{dom_element_by_xpath(xpath)}.style.top = '260px';")
33
30
  end
34
31
  end
35
32
  end
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: 0.3.1
4
+ version: 0.4.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: 2020-06-03 00:00:00.000000000 Z
14
+ date: 2020-07-30 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: headless
@@ -148,6 +148,8 @@ files:
148
148
  - lib/onlyoffice_webdriver_wrapper/name.rb
149
149
  - lib/onlyoffice_webdriver_wrapper/version.rb
150
150
  - lib/onlyoffice_webdriver_wrapper/webdriver.rb
151
+ - lib/onlyoffice_webdriver_wrapper/webdriver/click_methods.rb
152
+ - lib/onlyoffice_webdriver_wrapper/webdriver/wait_until_methods.rb
151
153
  - lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_alert_helper.rb
152
154
  - lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_attributes_helper.rb
153
155
  - lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_browser_info_helper.rb
@@ -184,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
186
  - !ruby/object:Gem::Version
185
187
  version: '0'
186
188
  requirements: []
187
- rubygems_version: 3.1.2
189
+ rubygems_version: 3.1.4
188
190
  signing_key:
189
191
  specification_version: 4
190
192
  summary: ONLYOFFICE Webdriver Wrapper Gem