automation_object 0.0.4 → 0.5.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 +4 -4
- data/lib/automation_object.rb +14 -72
- data/lib/automation_object/blue_print.rb +37 -100
- data/lib/automation_object/blue_print/composite/automatic_onload_modal.rb +28 -0
- data/lib/automation_object/blue_print/composite/base.rb +18 -0
- data/lib/automation_object/blue_print/composite/custom_method.rb +23 -0
- data/lib/automation_object/blue_print/composite/element.rb +20 -0
- data/lib/automation_object/blue_print/composite/element_array.rb +21 -0
- data/lib/automation_object/blue_print/composite/element_hash.rb +26 -0
- data/lib/automation_object/blue_print/composite/helpers/element_helper.rb +33 -0
- data/lib/automation_object/blue_print/composite/helpers/multiple_elements_helper.rb +18 -0
- data/lib/automation_object/blue_print/composite/hook.rb +31 -0
- data/lib/automation_object/blue_print/composite/hook_action.rb +84 -0
- data/lib/automation_object/blue_print/composite/hook_element_requirements.rb +39 -0
- data/lib/automation_object/blue_print/composite/modal.rb +56 -0
- data/lib/automation_object/blue_print/composite/screen.rb +61 -0
- data/lib/automation_object/blue_print/composite/top.rb +51 -0
- data/lib/automation_object/blue_print/composite/view.rb +48 -0
- data/lib/automation_object/blue_print/hash_adapter.rb +17 -0
- data/lib/automation_object/blue_print/hash_adapter/automatic_onload_modal.rb +35 -0
- data/lib/automation_object/blue_print/hash_adapter/composite.rb +93 -0
- data/lib/automation_object/blue_print/hash_adapter/custom_method.rb +30 -0
- data/lib/automation_object/blue_print/hash_adapter/element.rb +34 -0
- data/lib/automation_object/blue_print/hash_adapter/element_array.rb +36 -0
- data/lib/automation_object/blue_print/hash_adapter/element_hash.rb +43 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/element_helper.rb +59 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/multiple_elements_helper.rb +35 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validation_error.rb +26 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validation_helper.rb +99 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate.rb +23 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_allowed_keys.rb +31 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_element_presence_of.rb +55 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_instance_of.rb +39 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_modal_presence_of.rb +54 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_presence_of.rb +36 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_screen_presence_of.rb +55 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_view_presence_of.rb +52 -0
- data/lib/automation_object/blue_print/hash_adapter/hook.rb +35 -0
- data/lib/automation_object/blue_print/hash_adapter/hook_action.rb +134 -0
- data/lib/automation_object/blue_print/hash_adapter/hook_element_requirements.rb +64 -0
- data/lib/automation_object/blue_print/hash_adapter/modal.rb +52 -0
- data/lib/automation_object/blue_print/hash_adapter/screen.rb +91 -0
- data/lib/automation_object/blue_print/hash_adapter/top.rb +63 -0
- data/lib/automation_object/blue_print/hash_adapter/view.rb +29 -0
- data/lib/automation_object/blue_print/helpers/file_helper.rb +38 -0
- data/lib/automation_object/blue_print/yaml_adapter.rb +50 -0
- data/lib/automation_object/driver.rb +44 -0
- data/lib/automation_object/driver/appium_adapter/driver.rb +150 -0
- data/lib/automation_object/driver/appium_adapter/element.rb +118 -0
- data/lib/automation_object/driver/base.rb +11 -0
- data/lib/automation_object/driver/driver.rb +69 -245
- data/lib/automation_object/driver/element.rb +51 -210
- data/lib/automation_object/driver/helpers/selenium_driver_helper.rb +41 -0
- data/lib/automation_object/driver/helpers/selenium_element_helper.rb +138 -0
- data/lib/automation_object/driver/nokogiri_adapter/backup/driver.rb +83 -0
- data/lib/automation_object/driver/nokogiri_adapter/backup/element.rb +66 -0
- data/lib/automation_object/driver/nokogiri_adapter/backup/form.rb +29 -0
- data/lib/automation_object/driver/nokogiri_adapter/backup/helpers/driver_element_helper.rb +52 -0
- data/lib/automation_object/driver/nokogiri_adapter/backup/session.rb +115 -0
- data/lib/automation_object/driver/nokogiri_adapter/driver.rb +104 -0
- data/lib/automation_object/driver/nokogiri_adapter/element.rb +85 -0
- data/lib/automation_object/driver/nokogiri_adapter/error.rb +17 -0
- data/lib/automation_object/driver/selenium_adapter/driver.rb +143 -0
- data/lib/automation_object/driver/selenium_adapter/element.rb +116 -0
- data/lib/automation_object/dsl.rb +33 -0
- data/lib/automation_object/dsl/blue_print_adapter.rb +16 -0
- data/lib/automation_object/dsl/blue_print_adapter/composite.rb +54 -0
- data/lib/automation_object/dsl/blue_print_adapter/element.rb +14 -0
- data/lib/automation_object/dsl/blue_print_adapter/element_array.rb +14 -0
- data/lib/automation_object/dsl/blue_print_adapter/element_hash.rb +14 -0
- data/lib/automation_object/dsl/blue_print_adapter/modal.rb +23 -0
- data/lib/automation_object/dsl/blue_print_adapter/screen.rb +26 -0
- data/lib/automation_object/dsl/blue_print_adapter/top.rb +19 -0
- data/lib/automation_object/dsl/models.rb +18 -0
- data/lib/automation_object/dsl/proxies/element.rb +16 -0
- data/lib/automation_object/dsl/proxies/element_array.rb +16 -0
- data/lib/automation_object/dsl/proxies/element_hash.rb +16 -0
- data/lib/automation_object/dsl/proxies/helpers/composite_helper.rb +74 -0
- data/lib/automation_object/dsl/proxies/modal.rb +17 -0
- data/lib/automation_object/dsl/proxies/screen.rb +17 -0
- data/lib/automation_object/dsl/proxies/top.rb +17 -0
- data/lib/automation_object/framework.rb +79 -386
- data/lib/automation_object/helpers/composite.rb +95 -0
- data/lib/automation_object/helpers/composite_hook.rb +46 -0
- data/lib/automation_object/helpers/hash.rb +15 -0
- data/lib/automation_object/helpers/reflection_helper.rb +28 -0
- data/lib/automation_object/helpers/string.rb +27 -0
- data/lib/automation_object/proxies/mutex_proxy.rb +63 -0
- data/lib/automation_object/proxies/proxy.rb +20 -0
- data/lib/automation_object/proxies/throttle_proxy.rb +57 -0
- data/lib/automation_object/state.rb +37 -0
- data/lib/automation_object/state/blue_print_adapter.rb +16 -0
- data/lib/automation_object/state/blue_print_adapter/composite.rb +65 -0
- data/lib/automation_object/state/blue_print_adapter/element.rb +20 -0
- data/lib/automation_object/state/blue_print_adapter/element_array.rb +25 -0
- data/lib/automation_object/state/blue_print_adapter/element_hash.rb +31 -0
- data/lib/automation_object/state/blue_print_adapter/element_proxy.rb +28 -0
- data/lib/automation_object/state/blue_print_adapter/helpers/element_helper.rb +31 -0
- data/lib/automation_object/state/blue_print_adapter/helpers/screen_manager.rb +137 -0
- data/lib/automation_object/state/blue_print_adapter/helpers/window.rb +39 -0
- data/lib/automation_object/state/blue_print_adapter/hook.rb +56 -0
- data/lib/automation_object/state/blue_print_adapter/hook_action.rb +33 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/action_loop.rb +35 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/change_screen.rb +26 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/change_to_previous_screen.rb +21 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/close_modal.rb +31 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/close_screen.rb +19 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/element_requirement.rb +34 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/new_screen.rb +37 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/possible_screen_changes.rb +21 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/reset_screen.rb +18 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/show_modal.rb +26 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/sleep.rb +18 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/wait_for_elements.rb +20 -0
- data/lib/automation_object/state/blue_print_adapter/modal.rb +26 -0
- data/lib/automation_object/state/blue_print_adapter/screen.rb +32 -0
- data/lib/automation_object/state/blue_print_adapter/top.rb +45 -0
- data/lib/automation_object/state/error.rb +24 -0
- data/lib/automation_object/state/session.rb +38 -0
- data/lib/automation_object/step_definitions.rb +14 -0
- data/lib/automation_object/step_definitions/action.rb +21 -0
- data/lib/automation_object/step_definitions/cache.rb +23 -0
- data/lib/automation_object/step_definitions/element/actions.rb +87 -0
- data/lib/automation_object/step_definitions/element/regex.rb +24 -0
- data/lib/automation_object/step_definitions/element/steps.rb +67 -0
- data/lib/automation_object/step_definitions/parse.rb +39 -0
- data/lib/automation_object/version.rb +1 -1
- metadata +194 -110
- data/lib/automation_object/blue_print_validation/base_validation.rb +0 -44
- data/lib/automation_object/blue_print_validation/common_methods.rb +0 -106
- data/lib/automation_object/blue_print_validation/element_validation.rb +0 -198
- data/lib/automation_object/blue_print_validation/formatted_errors.rb +0 -41
- data/lib/automation_object/blue_print_validation/hook_validation.rb +0 -393
- data/lib/automation_object/blue_print_validation/key_value_constants.rb +0 -75
- data/lib/automation_object/blue_print_validation/modal_validation.rb +0 -37
- data/lib/automation_object/blue_print_validation/screen_modal_common_methods.rb +0 -119
- data/lib/automation_object/blue_print_validation/screen_validation.rb +0 -21
- data/lib/automation_object/blue_print_validation/validation_object.rb +0 -32
- data/lib/automation_object/driver/anonymous.rb +0 -27
- data/lib/automation_object/element/element.rb +0 -145
- data/lib/automation_object/element/element_array.rb +0 -12
- data/lib/automation_object/element/element_cell.rb +0 -126
- data/lib/automation_object/element/element_group.rb +0 -33
- data/lib/automation_object/element/element_hash.rb +0 -25
- data/lib/automation_object/element/element_helpers.rb +0 -29
- data/lib/automation_object/element/element_methods.rb +0 -134
- data/lib/automation_object/element/elements_helpers.rb +0 -204
- data/lib/automation_object/framework/events.rb +0 -8
- data/lib/automation_object/framework/helpers.rb +0 -101
- data/lib/automation_object/framework/print_objects.rb +0 -67
- data/lib/automation_object/framework/screen_monitor.rb +0 -55
- data/lib/automation_object/framework/screen_routing.rb +0 -310
- data/lib/automation_object/framework/window_helpers.rb +0 -181
- data/lib/automation_object/hash.rb +0 -6
- data/lib/automation_object/hook_helpers.rb +0 -27
- data/lib/automation_object/logger.rb +0 -179
- data/lib/automation_object/object.rb +0 -22
- data/lib/automation_object/screen/modal.rb +0 -8
- data/lib/automation_object/screen/screen.rb +0 -209
- data/lib/automation_object/screen/screen_hook_helpers.rb +0 -319
- data/lib/automation_object/screen/screen_modal_helpers.rb +0 -101
- data/lib/automation_object/screen/screen_prompt_helpers.rb +0 -21
- data/lib/automation_object/screen/screen_window_helpers.rb +0 -149
|
@@ -1,242 +1,83 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative 'base'
|
|
2
|
+
require_relative 'driver'
|
|
3
|
+
|
|
2
4
|
module AutomationObject
|
|
3
5
|
module Driver
|
|
4
|
-
class Element
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
@@scroll_into_view_methods = [:click, :tap, :hover, :send_keys]
|
|
12
|
-
|
|
13
|
-
def self.throttle_methods
|
|
14
|
-
@@throttle_methods
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def self.throttle_methods=(value)
|
|
18
|
-
@@throttle_methods = value
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def self.minimum_speed
|
|
22
|
-
@@minimum_speed
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def self.minimum_speed=(value)
|
|
26
|
-
@@minimum_speed = value
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def initialize(driver_object, element_object)
|
|
30
|
-
@driver_object = driver_object
|
|
31
|
-
@element_object = element_object
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def respond_to?(method_symbol, include_private = false)
|
|
35
|
-
return true if super
|
|
36
|
-
return @element_object.respond_to?(method_symbol, include_private)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def method_missing(method_symbol, *arguments, &block)
|
|
40
|
-
if @@scroll_into_view_methods.include?(method_symbol)
|
|
41
|
-
self.scroll_into_view
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
@driver_object.mutex_object.synchronize do
|
|
45
|
-
start_time = Time.new.to_f
|
|
46
|
-
element_object_return = @element_object.send(method_symbol, *arguments, &block)
|
|
47
|
-
|
|
48
|
-
self.throttle_speed(method_symbol, start_time)
|
|
49
|
-
|
|
50
|
-
total_time_taken = (Time.new.to_f-start_time)
|
|
51
|
-
AutomationObject::Logger::add_driver_element_message(total_time_taken, caller_locations, method_symbol, *arguments, &block)
|
|
52
|
-
|
|
53
|
-
return element_object_return
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def throttle_speed(method_symbol, start_time)
|
|
58
|
-
method_string = method_symbol.to_s
|
|
59
|
-
|
|
60
|
-
throttle_time_minimum = @@minimum_speed
|
|
61
|
-
if @@throttle_methods.is_a?(Hash)
|
|
62
|
-
if @@throttle_methods.has_key?(method_string)
|
|
63
|
-
throttle_time_minimum = @@throttle_methods[method_string].to_f
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
time_difference = Time.new.to_f - start_time
|
|
68
|
-
|
|
69
|
-
if time_difference < throttle_time_minimum
|
|
70
|
-
sleep((throttle_time_minimum-time_difference))
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def collides_with_element?(second_element_object, collision_tolerance = false)
|
|
75
|
-
box_one = self.get_box_coordinates
|
|
76
|
-
box_two = second_element_object.get_box_coordinates
|
|
77
|
-
|
|
78
|
-
collision_tolerance = 0 unless collision_tolerance.is_a?(Numeric)
|
|
79
|
-
|
|
80
|
-
if box_one[:x2] > box_two[:x1] and box_one[:x1] < box_two[:x2] and box_one[:y2] > box_two[:y1] and box_one[:y1] < box_two[:y2]
|
|
81
|
-
if box_one[:x2] > (box_two[:x1] + collision_tolerance) and (box_one[:x1] + collision_tolerance) < box_two[:x2] and
|
|
82
|
-
box_one[:y2] > (box_two[:y1] + collision_tolerance) and (box_one[:y1] + collision_tolerance) < box_two[:y2]
|
|
83
|
-
return true
|
|
84
|
-
else
|
|
85
|
-
return false
|
|
86
|
-
end
|
|
87
|
-
else
|
|
88
|
-
return false
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def get_box_coordinates
|
|
93
|
-
element_location = self.location
|
|
94
|
-
element_size = self.size
|
|
95
|
-
|
|
96
|
-
box_coordinates = Hash.new
|
|
97
|
-
box_coordinates[:x1] = element_location.x.to_f
|
|
98
|
-
box_coordinates[:y1] = element_location.y.to_f
|
|
99
|
-
box_coordinates[:x2] = element_location.x.to_f + element_size.width.to_f
|
|
100
|
-
box_coordinates[:y2] = element_location.y.to_f + element_size.height.to_f
|
|
101
|
-
|
|
102
|
-
return box_coordinates
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def attribute(key, value = false)
|
|
106
|
-
@driver_object.mutex_object.synchronize do
|
|
107
|
-
return @element_object.attribute(key) unless value
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
script = "return arguments[0].#{key} = '#{value}'"
|
|
111
|
-
@driver_object.execute_script(script, @element_object)
|
|
112
|
-
|
|
113
|
-
@driver_object.mutex_object.synchronize do
|
|
114
|
-
return @element_object.attribute(key)
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
def switch_to_iframe
|
|
119
|
-
@driver_object.switch_to.frame(self.get_iframe_switch_value)
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
def get_iframe_switch_value
|
|
123
|
-
iframe_switch_value = self.attribute('id')
|
|
124
|
-
if iframe_switch_value.length == 0
|
|
125
|
-
iframe_switch_value = self.attribute('name')
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
unless iframe_switch_value
|
|
129
|
-
iframe_switch_value = self.attribute('name', SecureRandom.hex(16))
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
return iframe_switch_value
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def get_element_center
|
|
136
|
-
element_location = self.location
|
|
137
|
-
element_size = self.size
|
|
138
|
-
|
|
139
|
-
center = Hash.new
|
|
140
|
-
center[:x] = (element_location.x.to_f + element_size.width.to_f/2).to_f
|
|
141
|
-
center[:y] = (element_location.y.to_f + element_size.height.to_f/2).to_f
|
|
142
|
-
|
|
143
|
-
return center
|
|
6
|
+
class Element < Base
|
|
7
|
+
# Set or Get attribute
|
|
8
|
+
# @param key [String] key of element
|
|
9
|
+
# @param value [String, nil] set value or leave blank
|
|
10
|
+
# @return [String, nil]
|
|
11
|
+
def attribute(key, value = nil)
|
|
12
|
+
self.adapter.attribute(key, value)
|
|
144
13
|
end
|
|
145
14
|
|
|
146
|
-
|
|
147
|
-
|
|
15
|
+
# @return [String] id of element
|
|
16
|
+
def id
|
|
17
|
+
self.adapter.id
|
|
148
18
|
end
|
|
149
19
|
|
|
150
|
-
|
|
151
|
-
|
|
20
|
+
# @return [String] href of element
|
|
21
|
+
def href
|
|
22
|
+
self.adapter.href
|
|
152
23
|
end
|
|
153
24
|
|
|
154
|
-
|
|
155
|
-
|
|
25
|
+
# Text of element
|
|
26
|
+
# @return [String, nil]
|
|
27
|
+
def text
|
|
28
|
+
self.adapter.text
|
|
156
29
|
end
|
|
157
30
|
|
|
158
|
-
|
|
159
|
-
|
|
31
|
+
# Type into an element
|
|
32
|
+
# @return [void]
|
|
33
|
+
def send_keys(string)
|
|
34
|
+
self.adapter.send_keys(string)
|
|
160
35
|
end
|
|
161
36
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
37
|
+
# Clear the element field
|
|
38
|
+
# @return [void]
|
|
39
|
+
def clear
|
|
40
|
+
self.adapter.clear
|
|
165
41
|
end
|
|
166
42
|
|
|
43
|
+
# @return [Boolean]
|
|
167
44
|
def visible?
|
|
168
|
-
|
|
45
|
+
self.adapter.visible?
|
|
169
46
|
end
|
|
170
47
|
|
|
48
|
+
# @return [Boolean]
|
|
171
49
|
def invisible?
|
|
172
|
-
|
|
50
|
+
self.adapter.invisible?
|
|
173
51
|
end
|
|
174
52
|
|
|
175
|
-
|
|
176
|
-
|
|
53
|
+
# Get the location
|
|
54
|
+
# @return [Point]
|
|
55
|
+
def location
|
|
56
|
+
self.adapter.location
|
|
177
57
|
end
|
|
178
58
|
|
|
179
|
-
|
|
180
|
-
|
|
59
|
+
# Get the size of an element
|
|
60
|
+
# @return [Dimension]
|
|
61
|
+
def size
|
|
62
|
+
self.adapter.size
|
|
181
63
|
end
|
|
182
64
|
|
|
183
|
-
|
|
184
|
-
|
|
65
|
+
# Perform a submit action on an element
|
|
66
|
+
# @return [void]
|
|
67
|
+
def submit
|
|
68
|
+
self.adapter.submit
|
|
185
69
|
end
|
|
186
70
|
|
|
71
|
+
# Scroll the element into view
|
|
72
|
+
# @return [void]
|
|
187
73
|
def scroll_into_view
|
|
188
|
-
|
|
74
|
+
self.adapter.scroll_into_view
|
|
189
75
|
end
|
|
190
76
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
return unless @driver_object.is_browser?
|
|
196
|
-
|
|
197
|
-
element_center = self.get_element_center
|
|
198
|
-
window_height = @driver_object.execute_script('return window.innerHeight;').to_f
|
|
199
|
-
current_y_position = @driver_object.execute_script('var doc = document.documentElement; return (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);').to_f
|
|
200
|
-
|
|
201
|
-
if element_center[:y] < (window_height/2)
|
|
202
|
-
ideal_y_position = (current_y_position + element_center[:y] - (window_height.to_f / 2.0)).abs
|
|
203
|
-
else
|
|
204
|
-
ideal_y_position = (current_y_position - element_center[:y] + (window_height.to_f / 2.0)).abs
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
@driver_object.execute_script("window.scroll(#{element_center[:x].to_f},#{ideal_y_position});")
|
|
208
|
-
#Just in case in close to the top or bottom bounds of the window
|
|
209
|
-
element_location = self.location_once_scrolled_into_view
|
|
210
|
-
|
|
211
|
-
if element_location[:y] < 0
|
|
212
|
-
current_y_position = @driver_object.execute_script('var doc = document.documentElement; return (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);').to_f
|
|
213
|
-
scroll_y_position = current_y_position + element_location[:y]
|
|
214
|
-
@driver_object.execute_script("window.scroll(#{element_location[:x].to_f},#{scroll_y_position});")
|
|
215
|
-
end
|
|
216
|
-
else
|
|
217
|
-
element_location = self.location
|
|
218
|
-
|
|
219
|
-
window_height = @driver_object.execute_script('return window.innerHeight;').to_f
|
|
220
|
-
current_scroll_position = @driver_object.execute_script('var doc = document.documentElement; return (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);').to_f
|
|
221
|
-
|
|
222
|
-
middle_y_bounds = current_scroll_position + window_height/2
|
|
223
|
-
|
|
224
|
-
if middle_y_bounds > element_location.y
|
|
225
|
-
#Add
|
|
226
|
-
y_difference = middle_y_bounds - element_location.y
|
|
227
|
-
scroll_y_position = current_scroll_position - y_difference
|
|
228
|
-
else
|
|
229
|
-
#Subtract
|
|
230
|
-
y_difference = element_location.y - middle_y_bounds
|
|
231
|
-
scroll_y_position = current_scroll_position + y_difference
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
#Get the element to halfway
|
|
235
|
-
scroll_x_position = element_location.x.to_f
|
|
236
|
-
|
|
237
|
-
javascript_string = "return window.scroll(#{scroll_x_position}, #{scroll_y_position});"
|
|
238
|
-
@driver_object.execute_script(javascript_string)
|
|
239
|
-
end
|
|
77
|
+
# Perform a click action on the element
|
|
78
|
+
# @return [void]
|
|
79
|
+
def click
|
|
80
|
+
self.adapter.click
|
|
240
81
|
end
|
|
241
82
|
end
|
|
242
83
|
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module AutomationObject
|
|
2
|
+
module Driver
|
|
3
|
+
#Helper module for Selenium based drivers
|
|
4
|
+
#for use by SeleniumAdapter::Driver and AppiumAdapter::Driver
|
|
5
|
+
module SeleniumDriverHelper
|
|
6
|
+
# @return [Float] inner window height
|
|
7
|
+
def inner_window_height
|
|
8
|
+
@subject.execute_script('return window.innerHeight;').to_f
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# @return [Hash] x,y scroll position
|
|
12
|
+
def scroll_position
|
|
13
|
+
position = OpenStruct.new
|
|
14
|
+
|
|
15
|
+
position.x = @subject.execute_script('var doc = document.documentElement; return (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0);').to_f
|
|
16
|
+
position.y = @subject.execute_script('var doc = document.documentElement; return (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);').to_f
|
|
17
|
+
|
|
18
|
+
return position
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def scroll_position=(position)
|
|
22
|
+
@subject.execute_script("window.scroll(#{position[:x]},#{position[:y]});")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# @param window_dimension [Hash] :width, :height of window
|
|
26
|
+
def window_size=(window_dimension)
|
|
27
|
+
@subject.manage.window.resize_to(window_dimension[:width], window_dimension[:height])
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# @return [Hash] :width, :height of window
|
|
31
|
+
def window_size
|
|
32
|
+
@subject.manage.window.size
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
#Maximize the current window
|
|
36
|
+
def maximize_window
|
|
37
|
+
@subject.manage.window.maximize
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
module AutomationObject
|
|
2
|
+
module Driver
|
|
3
|
+
#Helper module for Selenium based elements
|
|
4
|
+
#for use by SeleniumAdapter::Element and AppiumAdapter::Element
|
|
5
|
+
module SeleniumElementHelper
|
|
6
|
+
# @return [Numeric] x position of element
|
|
7
|
+
def x
|
|
8
|
+
@subject.location.x
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# @return [Numeric] y position of element
|
|
12
|
+
def y
|
|
13
|
+
@subject.location.y
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# @return [Numeric] width of element
|
|
17
|
+
def width
|
|
18
|
+
@subject.size.width
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# @return [Numeric] height of element
|
|
22
|
+
def height
|
|
23
|
+
@subject.size.height
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# @return [Boolean] element visible
|
|
27
|
+
def visible?
|
|
28
|
+
@subject.displayed?
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# @return [Boolean] element invisible
|
|
32
|
+
def invisible?
|
|
33
|
+
@subject.displayed? ? false : true
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# @return [String] id of element
|
|
37
|
+
def id
|
|
38
|
+
@subject.attribute('id').to_s
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# @return [String] href of element
|
|
42
|
+
def href
|
|
43
|
+
@subject.attribute('href').to_s
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# @return [Boolean] content of element
|
|
47
|
+
def content
|
|
48
|
+
@subject.attribute('content').to_s
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# @param key [String] attribute key to get or set
|
|
52
|
+
# @param value [Object] optional value to set the key as
|
|
53
|
+
# @return [Object] value of attribute
|
|
54
|
+
def attribute(key, value = false)
|
|
55
|
+
if value
|
|
56
|
+
script = "return arguments[0].#{key} = '#{value}'"
|
|
57
|
+
@driver.execute_script(script, @subject)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
@subject.attribute(key)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# @return [Hash] :x, :y coordinates
|
|
64
|
+
def element_center
|
|
65
|
+
element_location = @subject.location
|
|
66
|
+
element_size = @subject.size
|
|
67
|
+
|
|
68
|
+
center = OpenStruct.new
|
|
69
|
+
center.x = (element_location.x.to_f + element_size.width.to_f/2).to_f
|
|
70
|
+
center.y = (element_location.y.to_f + element_size.height.to_f/2).to_f
|
|
71
|
+
|
|
72
|
+
return center
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# @return [Hash] :x1, :x2, :y1, :y2 coordinates of a box
|
|
76
|
+
def box_coordinates
|
|
77
|
+
element_location = @subject.location
|
|
78
|
+
element_size = @subject.size
|
|
79
|
+
|
|
80
|
+
box_coordinates = OpenStruct.new
|
|
81
|
+
box_coordinates.x1 = element_location.x.to_f
|
|
82
|
+
box_coordinates.y1 = element_location.y.to_f
|
|
83
|
+
box_coordinates.x2 = element_location.x.to_f + element_size.width.to_f
|
|
84
|
+
box_coordinates.y2 = element_location.y.to_f + element_size.height.to_f
|
|
85
|
+
|
|
86
|
+
return box_coordinates
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# @param second_element_object [Object] element to compare to
|
|
90
|
+
# @param collision_tolerance [Numeric] pixel tolerance of collisions
|
|
91
|
+
# @return [Boolean] element collides with other
|
|
92
|
+
def collides_with_element?(second_element_object, collision_tolerance = false)
|
|
93
|
+
box_one = self.box_coordinates
|
|
94
|
+
box_two = second_element_object.box_coordinates
|
|
95
|
+
|
|
96
|
+
collision_tolerance = 0 unless collision_tolerance.is_a?(Numeric)
|
|
97
|
+
|
|
98
|
+
if box_one.x2 > box_two.x1 and box_one.x1 < box_two.x2 and box_one.y2 > box_two.y1 and box_one.y1 < box_two.y2
|
|
99
|
+
if box_one.x2 > (box_two.x1 + collision_tolerance) and (box_one.x1 + collision_tolerance) < box_two.x2 and
|
|
100
|
+
box_one.y2 > (box_two.y1 + collision_tolerance) and (box_one.y1 + collision_tolerance) < box_two.y2
|
|
101
|
+
return true
|
|
102
|
+
else
|
|
103
|
+
return false
|
|
104
|
+
end
|
|
105
|
+
else
|
|
106
|
+
return false
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
#Hover over element
|
|
111
|
+
def hover
|
|
112
|
+
self.scroll_into_view
|
|
113
|
+
@driver.action.move_to(@subject).perform
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
#Helper method to switch to this element's iframe
|
|
117
|
+
def switch_to_iframe
|
|
118
|
+
@driver.switch_to.frame(self.iframe_switch_value)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
#Helper method for getting the value to switch to
|
|
122
|
+
#If value doesn't exist then create one
|
|
123
|
+
# @return [String] iframe value to switch to
|
|
124
|
+
def iframe_switch_value
|
|
125
|
+
iframe_switch_value = self.attribute('id')
|
|
126
|
+
if iframe_switch_value.length == 0
|
|
127
|
+
iframe_switch_value = self.attribute('name')
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
unless iframe_switch_value
|
|
131
|
+
iframe_switch_value = self.attribute('name', SecureRandom.hex(16))
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
return iframe_switch_value
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|