automation_object 0.5.0 → 0.5.1

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.
Files changed (167) hide show
  1. checksums.yaml +4 -4
  2. data/lib/automation_object.rb +22 -11
  3. data/lib/automation_object/blue_print.rb +13 -12
  4. data/lib/automation_object/blue_print/composite/automatic_onload_modal.rb +9 -8
  5. data/lib/automation_object/blue_print/composite/base.rb +5 -4
  6. data/lib/automation_object/blue_print/composite/custom_method.rb +8 -7
  7. data/lib/automation_object/blue_print/composite/element.rb +6 -5
  8. data/lib/automation_object/blue_print/composite/element_array.rb +6 -5
  9. data/lib/automation_object/blue_print/composite/element_hash.rb +7 -6
  10. data/lib/automation_object/blue_print/composite/helpers/element_helper.rb +7 -7
  11. data/lib/automation_object/blue_print/composite/helpers/multiple_elements_helper.rb +5 -4
  12. data/lib/automation_object/blue_print/composite/hook.rb +9 -11
  13. data/lib/automation_object/blue_print/composite/hook_action.rb +25 -24
  14. data/lib/automation_object/blue_print/composite/hook_element_requirements.rb +14 -13
  15. data/lib/automation_object/blue_print/composite/modal.rb +11 -21
  16. data/lib/automation_object/blue_print/composite/screen.rb +22 -16
  17. data/lib/automation_object/blue_print/composite/top.rb +13 -12
  18. data/lib/automation_object/blue_print/composite/view.rb +27 -16
  19. data/lib/automation_object/blue_print/hash_adapter.rb +15 -11
  20. data/lib/automation_object/blue_print/hash_adapter/automatic_onload_modal.rb +12 -11
  21. data/lib/automation_object/blue_print/hash_adapter/composite.rb +28 -25
  22. data/lib/automation_object/blue_print/hash_adapter/custom_method.rb +11 -10
  23. data/lib/automation_object/blue_print/hash_adapter/element.rb +10 -9
  24. data/lib/automation_object/blue_print/hash_adapter/element_array.rb +10 -9
  25. data/lib/automation_object/blue_print/hash_adapter/element_hash.rb +11 -10
  26. data/lib/automation_object/blue_print/hash_adapter/helpers/element_helper.rb +20 -25
  27. data/lib/automation_object/blue_print/hash_adapter/helpers/multiple_elements_helper.rb +15 -14
  28. data/lib/automation_object/blue_print/hash_adapter/helpers/validation_error.rb +9 -8
  29. data/lib/automation_object/blue_print/hash_adapter/helpers/validation_helper.rb +19 -24
  30. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate.rb +8 -5
  31. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_allowed_keys.rb +7 -8
  32. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_element_presence_of.rb +28 -23
  33. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_instance_of.rb +12 -13
  34. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_modal_presence_of.rb +27 -23
  35. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_presence_of.rb +9 -8
  36. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_screen_presence_of.rb +27 -23
  37. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_view_presence_of.rb +25 -21
  38. data/lib/automation_object/blue_print/hash_adapter/hook.rb +14 -11
  39. data/lib/automation_object/blue_print/hash_adapter/hook_action.rb +45 -47
  40. data/lib/automation_object/blue_print/hash_adapter/hook_element_requirements.rb +24 -28
  41. data/lib/automation_object/blue_print/hash_adapter/modal.rb +14 -13
  42. data/lib/automation_object/blue_print/hash_adapter/screen.rb +23 -22
  43. data/lib/automation_object/blue_print/hash_adapter/top.rb +16 -15
  44. data/lib/automation_object/blue_print/hash_adapter/view.rb +58 -4
  45. data/lib/automation_object/blue_print/yaml_adapter.rb +33 -34
  46. data/lib/automation_object/driver.rb +15 -13
  47. data/lib/automation_object/driver/appium_adapter/driver.rb +47 -46
  48. data/lib/automation_object/driver/appium_adapter/element.rb +29 -96
  49. data/lib/automation_object/driver/base.rb +4 -2
  50. data/lib/automation_object/driver/common_selenium/driver.rb +60 -0
  51. data/lib/automation_object/driver/common_selenium/element.rb +107 -0
  52. data/lib/automation_object/driver/common_selenium/element_geometry.rb +86 -0
  53. data/lib/automation_object/driver/driver.rb +60 -30
  54. data/lib/automation_object/driver/element.rb +70 -15
  55. data/lib/automation_object/driver/nokogiri_adapter/driver.rb +88 -34
  56. data/lib/automation_object/driver/nokogiri_adapter/element.rb +94 -16
  57. data/lib/automation_object/driver/nokogiri_adapter/error.rb +29 -8
  58. data/lib/automation_object/driver/nokogiri_adapter/{backup/form.rb → form.rb} +19 -6
  59. data/lib/automation_object/driver/nokogiri_adapter/request.rb +17 -0
  60. data/lib/automation_object/driver/nokogiri_adapter/session.rb +94 -0
  61. data/lib/automation_object/driver/nokogiri_adapter/window.rb +86 -0
  62. data/lib/automation_object/driver/selenium_adapter/driver.rb +36 -45
  63. data/lib/automation_object/driver/selenium_adapter/element.rb +15 -85
  64. data/lib/automation_object/dsl.rb +11 -28
  65. data/lib/automation_object/dsl/_base.rb +70 -0
  66. data/lib/automation_object/dsl/_proxy.rb +24 -0
  67. data/lib/automation_object/dsl/element.rb +34 -0
  68. data/lib/automation_object/dsl/element_array.rb +34 -0
  69. data/lib/automation_object/dsl/element_hash.rb +34 -0
  70. data/lib/automation_object/dsl/modal.rb +43 -0
  71. data/lib/automation_object/dsl/screen.rb +45 -0
  72. data/lib/automation_object/dsl/top.rb +25 -0
  73. data/lib/automation_object/framework.rb +28 -38
  74. data/lib/automation_object/helpers/composite.rb +30 -27
  75. data/lib/automation_object/helpers/composite_hook.rb +16 -15
  76. data/lib/automation_object/{blue_print/helpers/file_helper.rb → helpers/file.rb} +12 -12
  77. data/lib/automation_object/helpers/hash.rb +6 -5
  78. data/lib/automation_object/helpers/kernel.rb +11 -0
  79. data/lib/automation_object/helpers/{reflection_helper.rb → reflection.rb} +9 -8
  80. data/lib/automation_object/helpers/string.rb +25 -15
  81. data/lib/automation_object/{proxies → proxy}/mutex_proxy.rb +18 -21
  82. data/lib/automation_object/proxy/proxy.rb +23 -0
  83. data/lib/automation_object/proxy/throttle_proxy.rb +52 -0
  84. data/lib/automation_object/state.rb +11 -29
  85. data/lib/automation_object/state/{blue_print_adapter/composite.rb → composite/_base.rb} +35 -25
  86. data/lib/automation_object/state/{blue_print_adapter/helpers/element_helper.rb → composite/_common_element.rb} +11 -11
  87. data/lib/automation_object/state/composite/element.rb +22 -0
  88. data/lib/automation_object/state/composite/element_array.rb +27 -0
  89. data/lib/automation_object/state/composite/element_hash.rb +33 -0
  90. data/lib/automation_object/state/composite/element_proxy.rb +33 -0
  91. data/lib/automation_object/state/composite/helpers/window.rb +61 -0
  92. data/lib/automation_object/state/composite/helpers/window_manager.rb +60 -0
  93. data/lib/automation_object/state/composite/hook.rb +56 -0
  94. data/lib/automation_object/state/{blue_print_adapter → composite}/hook_action.rb +10 -8
  95. data/lib/automation_object/state/composite/hook_actions/action_loop.rb +36 -0
  96. data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/change_screen.rb +7 -5
  97. data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/change_to_previous_screen.rb +7 -5
  98. data/lib/automation_object/state/composite/hook_actions/close_modal.rb +29 -0
  99. data/lib/automation_object/state/composite/hook_actions/close_screen.rb +19 -0
  100. data/lib/automation_object/state/composite/hook_actions/element_requirement.rb +32 -0
  101. data/lib/automation_object/state/composite/hook_actions/new_screen.rb +35 -0
  102. data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/possible_screen_changes.rb +8 -7
  103. data/lib/automation_object/state/composite/hook_actions/reset_screen.rb +14 -0
  104. data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/show_modal.rb +7 -5
  105. data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/sleep.rb +4 -2
  106. data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/wait_for_elements.rb +7 -5
  107. data/lib/automation_object/state/composite/modal.rb +45 -0
  108. data/lib/automation_object/state/composite/screen.rb +58 -0
  109. data/lib/automation_object/state/composite/top.rb +51 -0
  110. data/lib/automation_object/state/error.rb +45 -6
  111. data/lib/automation_object/state/session.rb +25 -23
  112. data/lib/automation_object/step_definitions.rb +5 -3
  113. data/lib/automation_object/step_definitions/element.rb +77 -0
  114. data/lib/automation_object/step_definitions/element_array.rb +135 -0
  115. data/lib/automation_object/step_definitions/element_hash.rb +126 -0
  116. data/lib/automation_object/step_definitions/screen.rb +62 -0
  117. data/lib/automation_object/step_definitions/{cache.rb → support/cache.rb} +8 -6
  118. data/lib/automation_object/step_definitions/support/element_array.rb +40 -0
  119. data/lib/automation_object/step_definitions/support/element_hash.rb +41 -0
  120. data/lib/automation_object/step_definitions/{parse.rb → support/parse.rb} +8 -6
  121. data/lib/automation_object/version.rb +2 -1
  122. metadata +203 -103
  123. data/lib/automation_object/driver/helpers/selenium_driver_helper.rb +0 -41
  124. data/lib/automation_object/driver/helpers/selenium_element_helper.rb +0 -138
  125. data/lib/automation_object/driver/nokogiri_adapter/backup/driver.rb +0 -83
  126. data/lib/automation_object/driver/nokogiri_adapter/backup/element.rb +0 -66
  127. data/lib/automation_object/driver/nokogiri_adapter/backup/helpers/driver_element_helper.rb +0 -52
  128. data/lib/automation_object/driver/nokogiri_adapter/backup/session.rb +0 -115
  129. data/lib/automation_object/dsl/blue_print_adapter.rb +0 -16
  130. data/lib/automation_object/dsl/blue_print_adapter/composite.rb +0 -54
  131. data/lib/automation_object/dsl/blue_print_adapter/element.rb +0 -14
  132. data/lib/automation_object/dsl/blue_print_adapter/element_array.rb +0 -14
  133. data/lib/automation_object/dsl/blue_print_adapter/element_hash.rb +0 -14
  134. data/lib/automation_object/dsl/blue_print_adapter/modal.rb +0 -23
  135. data/lib/automation_object/dsl/blue_print_adapter/screen.rb +0 -26
  136. data/lib/automation_object/dsl/blue_print_adapter/top.rb +0 -19
  137. data/lib/automation_object/dsl/models.rb +0 -18
  138. data/lib/automation_object/dsl/proxies/element.rb +0 -16
  139. data/lib/automation_object/dsl/proxies/element_array.rb +0 -16
  140. data/lib/automation_object/dsl/proxies/element_hash.rb +0 -16
  141. data/lib/automation_object/dsl/proxies/helpers/composite_helper.rb +0 -74
  142. data/lib/automation_object/dsl/proxies/modal.rb +0 -17
  143. data/lib/automation_object/dsl/proxies/screen.rb +0 -17
  144. data/lib/automation_object/dsl/proxies/top.rb +0 -17
  145. data/lib/automation_object/proxies/proxy.rb +0 -20
  146. data/lib/automation_object/proxies/throttle_proxy.rb +0 -57
  147. data/lib/automation_object/state/blue_print_adapter.rb +0 -16
  148. data/lib/automation_object/state/blue_print_adapter/element.rb +0 -20
  149. data/lib/automation_object/state/blue_print_adapter/element_array.rb +0 -25
  150. data/lib/automation_object/state/blue_print_adapter/element_hash.rb +0 -31
  151. data/lib/automation_object/state/blue_print_adapter/element_proxy.rb +0 -28
  152. data/lib/automation_object/state/blue_print_adapter/helpers/screen_manager.rb +0 -137
  153. data/lib/automation_object/state/blue_print_adapter/helpers/window.rb +0 -39
  154. data/lib/automation_object/state/blue_print_adapter/hook.rb +0 -56
  155. data/lib/automation_object/state/blue_print_adapter/hook_actions/action_loop.rb +0 -35
  156. data/lib/automation_object/state/blue_print_adapter/hook_actions/close_modal.rb +0 -31
  157. data/lib/automation_object/state/blue_print_adapter/hook_actions/close_screen.rb +0 -19
  158. data/lib/automation_object/state/blue_print_adapter/hook_actions/element_requirement.rb +0 -34
  159. data/lib/automation_object/state/blue_print_adapter/hook_actions/new_screen.rb +0 -37
  160. data/lib/automation_object/state/blue_print_adapter/hook_actions/reset_screen.rb +0 -18
  161. data/lib/automation_object/state/blue_print_adapter/modal.rb +0 -26
  162. data/lib/automation_object/state/blue_print_adapter/screen.rb +0 -32
  163. data/lib/automation_object/state/blue_print_adapter/top.rb +0 -45
  164. data/lib/automation_object/step_definitions/action.rb +0 -21
  165. data/lib/automation_object/step_definitions/element/actions.rb +0 -87
  166. data/lib/automation_object/step_definitions/element/regex.rb +0 -24
  167. data/lib/automation_object/step_definitions/element/steps.rb +0 -67
@@ -1,17 +1,38 @@
1
+ # frozen_string_literal: true
1
2
  module AutomationObject
2
3
  module Driver
3
- #Emulate Selenium errors
4
- #http://www.rubydoc.info/gems/selenium-webdriver/Selenium/WebDriver/Error
4
+ # Emulate Selenium errors
5
+ # http://www.rubydoc.info/gems/selenium-webdriver/Selenium/WebDriver/Error
5
6
  module NokogiriAdapter
6
- #
7
- class WebDriverError < StandardError;
7
+ # Web driver error
8
+ class WebDriverError < StandardError
8
9
  end
9
- class NoSuchElementError < WebDriverError;
10
+
11
+ # Element doesn't exist error
12
+ class NoSuchElementError < WebDriverError
10
13
  end
11
- class NoSuchWindowError < WebDriverError;
14
+
15
+ # No window when switching error
16
+ class NoSuchWindowError < WebDriverError
12
17
  end
13
- class NoSuchDocumentError < WebDriverError;
18
+
19
+ # Document doesn't exist
20
+ class NoSuchDocumentError < WebDriverError
21
+ end
22
+
23
+ # Can't navigate forward
24
+ class UnableToNavigateForward < WebDriverError
25
+ def initialize(message = 'Cannot navigate forward')
26
+ super
27
+ end
28
+ end
29
+
30
+ # Can't navigate backward
31
+ class UnableToNavigateBackward < WebDriverError
32
+ def initialize(message = 'Cannot navigate backward')
33
+ super
34
+ end
14
35
  end
15
36
  end
16
37
  end
17
- end
38
+ end
@@ -1,29 +1,42 @@
1
+ # frozen_string_literal: true
1
2
  module AutomationObject
2
3
  module Driver
3
4
  module NokogiriAdapter
5
+ # Class to wrap a form node
4
6
  class Form
7
+ # @return [Nokogiri::XML::Node]
8
+ attr_accessor :node
9
+
5
10
  # @param node [Nokogiri::XML::Node]
6
11
  def initialize(node)
7
- @node = node
12
+ self.node = node
13
+ end
14
+
15
+ def url
16
+ node['action']
17
+ end
18
+
19
+ def new_window?
20
+ attribute('target') == '_blank'
8
21
  end
9
22
 
10
23
  # @return [Hash]
11
24
  def params
12
25
  params = {}
13
26
 
14
- @node.traverse { |node|
27
+ node.traverse do |node|
15
28
  next unless node.name == 'input'
16
29
  params[node['name']] = node['value']
17
- }
30
+ end
18
31
 
19
- return params
32
+ params
20
33
  end
21
34
 
22
35
  # @return [Symbol]
23
36
  def request_method
24
- (@node['method'].upcase == 'GET') ? :get : :post
37
+ node['method'].casecmp('GET').zero? ? :get : :post
25
38
  end
26
39
  end
27
40
  end
28
41
  end
29
- end
42
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ module AutomationObject
3
+ module Driver
4
+ module NokogiriAdapter
5
+ # Request class
6
+ class Request
7
+ attr_accessor :type, :url, :params
8
+
9
+ def initialize(type, url, params)
10
+ self.type = type
11
+ self.url = url
12
+ self.params = params
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'error'
3
+ require_relative 'window'
4
+
5
+ module AutomationObject
6
+ module Driver
7
+ module NokogiriAdapter
8
+ # Class for creating/maintaining XML session
9
+ # Trying to replicate some functionality of Selenium like multiple windows, etc...
10
+ class Session
11
+ def initialize
12
+ @windows = [Window.new]
13
+ @position = 0 # Position
14
+ end
15
+
16
+ def xml
17
+ return nil if @windows[@position].nil?
18
+ @windows[@position].xml
19
+ end
20
+
21
+ # @return [Array<String>] window handles
22
+ def window_handles
23
+ @windows.map(&:handle)
24
+ end
25
+
26
+ # @return [String] current window handle
27
+ def window_handle
28
+ return nil if @windows[@position].nil?
29
+ @windows[@position].handle
30
+ end
31
+
32
+ # @return [String] current URL
33
+ def current_url
34
+ return nil if @windows[@position].nil?
35
+ @windows[@position].current_url
36
+ end
37
+
38
+ # Switch window handles
39
+ # @param handle_value [String] handle value of window to switch to
40
+ def window_handle=(handle_value)
41
+ raise NoSuchWindowError unless window_handles.include?(handle_value)
42
+
43
+ @position = 0
44
+ @windows.each_with_index do |index, window|
45
+ @position = index if window.handle == handle_value
46
+ end
47
+ end
48
+
49
+ # Request url, will set xml to current window handle
50
+ # @param type [Symbol] request type
51
+ # @param url [String] url
52
+ # @param params [Hash<String:String>] params
53
+ # @param blank [Boolean] new window
54
+ # @return [void]
55
+ def request(type, url, params = {}, blank = false)
56
+ if blank
57
+ @windows.push(Window.new)
58
+ @position = @windows.length - 1
59
+ end
60
+
61
+ @windows[@position].request(type, url, params)
62
+ end
63
+
64
+ def back
65
+ return if @windows[@position].nil?
66
+ @windows[@position].back
67
+ end
68
+
69
+ def forward
70
+ return if @windows[@position].nil?
71
+ @windows[@position].forward
72
+ end
73
+
74
+ def refresh
75
+ return if @windows[@position].nil?
76
+ @windows[@position].refresh
77
+ end
78
+
79
+ def close
80
+ # Reset session if only one window
81
+ quit if @windows.length == 1
82
+
83
+ @windows.delete_at(@position)
84
+ @position -= 1 if @position.positive?
85
+ end
86
+
87
+ # Just reset the session
88
+ def quit
89
+ @windows = [Window.new]
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+ require 'rest-client'
3
+ require 'nokogiri'
4
+
5
+ require_relative 'request'
6
+ require_relative 'error'
7
+
8
+ module AutomationObject
9
+ module Driver
10
+ module NokogiriAdapter
11
+ # Window class
12
+ class Window
13
+ attr_accessor :handle, :xml
14
+
15
+ def initialize
16
+ self.handle = SecureRandom.hex(16)
17
+
18
+ # Use to control history
19
+ @position = 0
20
+ @history = []
21
+ end
22
+
23
+ # Get url, will set xml to current window handle
24
+ # @param url [String] url to get xml for
25
+ # @return [Object] nokogiri object
26
+ def request(type, url, params = {})
27
+ request = Request.new(type, url, params)
28
+ make_request(request)
29
+
30
+ update_history(request)
31
+ end
32
+
33
+ # @return [String]
34
+ def current_url
35
+ request = @history.at(@position)
36
+ !request.nil? ? request.url : nil
37
+ end
38
+
39
+ # @return [void]
40
+ def back
41
+ raise UnableToNavigateBackward if @position.zero?
42
+ @position -= 1
43
+
44
+ make_request(@history.at(@position))
45
+ end
46
+
47
+ # @return [void]
48
+ def forward
49
+ raise UnableToNavigateForward if @position >= @history.length - 2
50
+ @position += 1
51
+
52
+ make_request(@history.at(@position))
53
+ end
54
+
55
+ # @return [void]
56
+ def refresh
57
+ make_request(@history.at(@position))
58
+ end
59
+
60
+ protected
61
+
62
+ # @return [void]
63
+ def update_history(request)
64
+ @history.push(request)
65
+ @position = @history.length - 1
66
+ end
67
+
68
+ # Request url, will set xml to current window handle
69
+ # @param request [Request] request object
70
+ # @return [void]
71
+ def make_request(request)
72
+ parsed_url = request.url
73
+
74
+ raise ArgumentError, "Expecting get argument url to be a valid_url?, got #{request.url}" if !parsed_url.valid_url? && current_url.nil?
75
+
76
+ parsed_url = current_url.join_url(request.url) if !request.url.valid_url? && !current_url.nil?
77
+
78
+ client_resource = RestClient::Resource.new(parsed_url, ssl_version: 'SSLv23_client')
79
+ response = client_resource.send(request.type, params: request.params)
80
+
81
+ self.xml = Nokogiri::HTML.parse(response)
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -1,5 +1,8 @@
1
- require_relative '../../proxies/proxy'
2
- require_relative '../helpers/selenium_driver_helper'
1
+ # frozen_string_literal: true
2
+ require_relative '../../proxy/proxy'
3
+
4
+ require_relative '../driver'
5
+ require_relative '../common_selenium/driver'
3
6
 
4
7
  require_relative '../element'
5
8
  require_relative 'element'
@@ -7,12 +10,10 @@ require_relative 'element'
7
10
  module AutomationObject
8
11
  module Driver
9
12
  module SeleniumAdapter
10
- #Driver proxy for Selenium
11
- #Conform Selenium driver interface to what's expected of the Driver Port
12
- class Driver < AutomationObject::Proxies::Proxy
13
- DOC_COMPLETE_SLEEP = 1
14
-
15
- include AutomationObject::Driver::SeleniumDriverHelper
13
+ # Driver proxy for Selenium
14
+ # Conform Selenium driver interface to what's expected of the Driver Port
15
+ class Driver < AutomationObject::Proxy::Proxy
16
+ include AutomationObject::Driver::CommonSelenium::Driver
16
17
 
17
18
  # @param driver [Selenium::WebDriver::Driver] Selenium Web Driver
18
19
  def initialize(driver)
@@ -26,10 +27,16 @@ module AutomationObject
26
27
  @subject.navigate.to(url)
27
28
  end
28
29
 
30
+ # Get the title of the document
31
+ # @return [String]
32
+ def title
33
+ @subject.title
34
+ end
35
+
29
36
  # Set timeout wait
30
37
  # @param timeout [Integer] the timeout in seconds
31
38
  # @return [void]
32
- def set_wait(timeout = nil)
39
+ def wait(timeout = nil)
33
40
  timeout = 0 unless timeout
34
41
  @subject.manage.timeouts.implicit_wait = timeout
35
42
  end
@@ -41,17 +48,15 @@ module AutomationObject
41
48
  exists = false
42
49
 
43
50
  begin
44
- original_timeout = @subject.manage.timeouts.implicit_wait
45
- @subject.manage.timeouts.implicit_wait = 0
46
- element_objects = @subject.find_elements(selector_type, selector_path)
47
- @subject.manage.timeouts.implicit_wait = original_timeout
48
- if element_objects.length > 0
49
- exists = true
51
+ suspend_timeout do
52
+ element_objects = @subject.find_elements(selector_type, selector_path)
53
+ exists = true unless element_objects.empty?
50
54
  end
51
- rescue Exception => e
55
+ rescue StandardError
56
+ return false
52
57
  end
53
58
 
54
- return exists
59
+ exists
55
60
  end
56
61
 
57
62
  # @param selector_type [Symbol] selector type, :css, :xpath, etc...
@@ -59,8 +64,9 @@ module AutomationObject
59
64
  # @return [Object] element
60
65
  def find_element(selector_type, selector_path)
61
66
  element = @subject.find_element(selector_type, selector_path)
62
- #Wrap in adapter interface
63
- return AutomationObject::Driver::Element.new(Element.new(driver: self, element: element))
67
+
68
+ # Wrap in adapter interface
69
+ AutomationObject::Driver::Element.new(Element.new(self, element))
64
70
  end
65
71
 
66
72
  # @param selector_type [Symbol] selector type, :css, :xpath, etc...
@@ -69,19 +75,19 @@ module AutomationObject
69
75
  def find_elements(selector_type, selector_path)
70
76
  elements = @subject.find_elements(selector_type, selector_path)
71
77
 
72
- elements.map { |element|
73
- AutomationObject::Driver::Element.new(Element.new(driver: self, element: element))
74
- }
78
+ elements.map do |element|
79
+ AutomationObject::Driver::Element.new(Element.new(self, element))
80
+ end
75
81
  end
76
82
 
77
- #Accept prompt either in browser or mobile
83
+ # Accept prompt either in browser or mobile
78
84
  def accept_prompt
79
85
  alert = @subject.switch_to.alert
80
86
  alert.accept
81
87
  @subject.switch_to.default_content
82
88
  end
83
89
 
84
- #Dismiss the prompt
90
+ # Dismiss the prompt
85
91
  def dismiss_prompt
86
92
  alert = @subject.switch_to.alert
87
93
  alert.dismiss
@@ -90,23 +96,23 @@ module AutomationObject
90
96
 
91
97
  # Check if browser, more useful for Appium but can be generic here
92
98
  # @return [Boolean] whether or not browser is being used
93
- def is_browser?
99
+ def browser?
94
100
  true
95
101
  end
96
102
 
97
- #Window Handles
103
+ # Window Handles
98
104
  # @return [Array<String>] array of window handle ids
99
105
  def window_handles
100
106
  @subject.window_handles
101
107
  end
102
108
 
103
- #Current window handle
109
+ # Current window handle
104
110
  # @return [String] handle id
105
111
  def window_handle
106
112
  @subject.window_handle
107
113
  end
108
114
 
109
- #Set current window handle to, will switch windows
115
+ # Set current window handle to, will switch windows
110
116
  # @param handle_value [String] window handle value
111
117
  def window_handle=(handle_value)
112
118
  @subject.switch_to.window(handle_value)
@@ -115,22 +121,7 @@ module AutomationObject
115
121
  # Run script in browser to check if document in JS is complete
116
122
  # @return [Boolean] document is complete
117
123
  def document_complete?
118
- return @subject.execute_script('return document.readyState;') == 'complete'
119
- end
120
-
121
- # Wait till the document is complete
122
- # @return [void]
123
- def document_complete_wait
124
- 30.times do
125
- sleep(DOC_COMPLETE_SLEEP)
126
- break if self.document_complete?
127
- end
128
- end
129
-
130
- # @param script [String] JS to run
131
- # @return [Object, nil]
132
- def execute_script(script)
133
- @subject.execute_script(script)
124
+ @subject.execute_script('return document.readyState;') == 'complete'
134
125
  end
135
126
 
136
127
  # Destroy the driver
@@ -140,4 +131,4 @@ module AutomationObject
140
131
  end
141
132
  end
142
133
  end
143
- end
134
+ end