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.
- checksums.yaml +4 -4
- data/lib/automation_object.rb +22 -11
- data/lib/automation_object/blue_print.rb +13 -12
- data/lib/automation_object/blue_print/composite/automatic_onload_modal.rb +9 -8
- data/lib/automation_object/blue_print/composite/base.rb +5 -4
- data/lib/automation_object/blue_print/composite/custom_method.rb +8 -7
- data/lib/automation_object/blue_print/composite/element.rb +6 -5
- data/lib/automation_object/blue_print/composite/element_array.rb +6 -5
- data/lib/automation_object/blue_print/composite/element_hash.rb +7 -6
- data/lib/automation_object/blue_print/composite/helpers/element_helper.rb +7 -7
- data/lib/automation_object/blue_print/composite/helpers/multiple_elements_helper.rb +5 -4
- data/lib/automation_object/blue_print/composite/hook.rb +9 -11
- data/lib/automation_object/blue_print/composite/hook_action.rb +25 -24
- data/lib/automation_object/blue_print/composite/hook_element_requirements.rb +14 -13
- data/lib/automation_object/blue_print/composite/modal.rb +11 -21
- data/lib/automation_object/blue_print/composite/screen.rb +22 -16
- data/lib/automation_object/blue_print/composite/top.rb +13 -12
- data/lib/automation_object/blue_print/composite/view.rb +27 -16
- data/lib/automation_object/blue_print/hash_adapter.rb +15 -11
- data/lib/automation_object/blue_print/hash_adapter/automatic_onload_modal.rb +12 -11
- data/lib/automation_object/blue_print/hash_adapter/composite.rb +28 -25
- data/lib/automation_object/blue_print/hash_adapter/custom_method.rb +11 -10
- data/lib/automation_object/blue_print/hash_adapter/element.rb +10 -9
- data/lib/automation_object/blue_print/hash_adapter/element_array.rb +10 -9
- data/lib/automation_object/blue_print/hash_adapter/element_hash.rb +11 -10
- data/lib/automation_object/blue_print/hash_adapter/helpers/element_helper.rb +20 -25
- data/lib/automation_object/blue_print/hash_adapter/helpers/multiple_elements_helper.rb +15 -14
- data/lib/automation_object/blue_print/hash_adapter/helpers/validation_error.rb +9 -8
- data/lib/automation_object/blue_print/hash_adapter/helpers/validation_helper.rb +19 -24
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate.rb +8 -5
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_allowed_keys.rb +7 -8
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_element_presence_of.rb +28 -23
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_instance_of.rb +12 -13
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_modal_presence_of.rb +27 -23
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_presence_of.rb +9 -8
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_screen_presence_of.rb +27 -23
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_view_presence_of.rb +25 -21
- data/lib/automation_object/blue_print/hash_adapter/hook.rb +14 -11
- data/lib/automation_object/blue_print/hash_adapter/hook_action.rb +45 -47
- data/lib/automation_object/blue_print/hash_adapter/hook_element_requirements.rb +24 -28
- data/lib/automation_object/blue_print/hash_adapter/modal.rb +14 -13
- data/lib/automation_object/blue_print/hash_adapter/screen.rb +23 -22
- data/lib/automation_object/blue_print/hash_adapter/top.rb +16 -15
- data/lib/automation_object/blue_print/hash_adapter/view.rb +58 -4
- data/lib/automation_object/blue_print/yaml_adapter.rb +33 -34
- data/lib/automation_object/driver.rb +15 -13
- data/lib/automation_object/driver/appium_adapter/driver.rb +47 -46
- data/lib/automation_object/driver/appium_adapter/element.rb +29 -96
- data/lib/automation_object/driver/base.rb +4 -2
- data/lib/automation_object/driver/common_selenium/driver.rb +60 -0
- data/lib/automation_object/driver/common_selenium/element.rb +107 -0
- data/lib/automation_object/driver/common_selenium/element_geometry.rb +86 -0
- data/lib/automation_object/driver/driver.rb +60 -30
- data/lib/automation_object/driver/element.rb +70 -15
- data/lib/automation_object/driver/nokogiri_adapter/driver.rb +88 -34
- data/lib/automation_object/driver/nokogiri_adapter/element.rb +94 -16
- data/lib/automation_object/driver/nokogiri_adapter/error.rb +29 -8
- data/lib/automation_object/driver/nokogiri_adapter/{backup/form.rb → form.rb} +19 -6
- data/lib/automation_object/driver/nokogiri_adapter/request.rb +17 -0
- data/lib/automation_object/driver/nokogiri_adapter/session.rb +94 -0
- data/lib/automation_object/driver/nokogiri_adapter/window.rb +86 -0
- data/lib/automation_object/driver/selenium_adapter/driver.rb +36 -45
- data/lib/automation_object/driver/selenium_adapter/element.rb +15 -85
- data/lib/automation_object/dsl.rb +11 -28
- data/lib/automation_object/dsl/_base.rb +70 -0
- data/lib/automation_object/dsl/_proxy.rb +24 -0
- data/lib/automation_object/dsl/element.rb +34 -0
- data/lib/automation_object/dsl/element_array.rb +34 -0
- data/lib/automation_object/dsl/element_hash.rb +34 -0
- data/lib/automation_object/dsl/modal.rb +43 -0
- data/lib/automation_object/dsl/screen.rb +45 -0
- data/lib/automation_object/dsl/top.rb +25 -0
- data/lib/automation_object/framework.rb +28 -38
- data/lib/automation_object/helpers/composite.rb +30 -27
- data/lib/automation_object/helpers/composite_hook.rb +16 -15
- data/lib/automation_object/{blue_print/helpers/file_helper.rb → helpers/file.rb} +12 -12
- data/lib/automation_object/helpers/hash.rb +6 -5
- data/lib/automation_object/helpers/kernel.rb +11 -0
- data/lib/automation_object/helpers/{reflection_helper.rb → reflection.rb} +9 -8
- data/lib/automation_object/helpers/string.rb +25 -15
- data/lib/automation_object/{proxies → proxy}/mutex_proxy.rb +18 -21
- data/lib/automation_object/proxy/proxy.rb +23 -0
- data/lib/automation_object/proxy/throttle_proxy.rb +52 -0
- data/lib/automation_object/state.rb +11 -29
- data/lib/automation_object/state/{blue_print_adapter/composite.rb → composite/_base.rb} +35 -25
- data/lib/automation_object/state/{blue_print_adapter/helpers/element_helper.rb → composite/_common_element.rb} +11 -11
- data/lib/automation_object/state/composite/element.rb +22 -0
- data/lib/automation_object/state/composite/element_array.rb +27 -0
- data/lib/automation_object/state/composite/element_hash.rb +33 -0
- data/lib/automation_object/state/composite/element_proxy.rb +33 -0
- data/lib/automation_object/state/composite/helpers/window.rb +61 -0
- data/lib/automation_object/state/composite/helpers/window_manager.rb +60 -0
- data/lib/automation_object/state/composite/hook.rb +56 -0
- data/lib/automation_object/state/{blue_print_adapter → composite}/hook_action.rb +10 -8
- data/lib/automation_object/state/composite/hook_actions/action_loop.rb +36 -0
- data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/change_screen.rb +7 -5
- data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/change_to_previous_screen.rb +7 -5
- data/lib/automation_object/state/composite/hook_actions/close_modal.rb +29 -0
- data/lib/automation_object/state/composite/hook_actions/close_screen.rb +19 -0
- data/lib/automation_object/state/composite/hook_actions/element_requirement.rb +32 -0
- data/lib/automation_object/state/composite/hook_actions/new_screen.rb +35 -0
- data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/possible_screen_changes.rb +8 -7
- data/lib/automation_object/state/composite/hook_actions/reset_screen.rb +14 -0
- data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/show_modal.rb +7 -5
- data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/sleep.rb +4 -2
- data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/wait_for_elements.rb +7 -5
- data/lib/automation_object/state/composite/modal.rb +45 -0
- data/lib/automation_object/state/composite/screen.rb +58 -0
- data/lib/automation_object/state/composite/top.rb +51 -0
- data/lib/automation_object/state/error.rb +45 -6
- data/lib/automation_object/state/session.rb +25 -23
- data/lib/automation_object/step_definitions.rb +5 -3
- data/lib/automation_object/step_definitions/element.rb +77 -0
- data/lib/automation_object/step_definitions/element_array.rb +135 -0
- data/lib/automation_object/step_definitions/element_hash.rb +126 -0
- data/lib/automation_object/step_definitions/screen.rb +62 -0
- data/lib/automation_object/step_definitions/{cache.rb → support/cache.rb} +8 -6
- data/lib/automation_object/step_definitions/support/element_array.rb +40 -0
- data/lib/automation_object/step_definitions/support/element_hash.rb +41 -0
- data/lib/automation_object/step_definitions/{parse.rb → support/parse.rb} +8 -6
- data/lib/automation_object/version.rb +2 -1
- metadata +203 -103
- data/lib/automation_object/driver/helpers/selenium_driver_helper.rb +0 -41
- data/lib/automation_object/driver/helpers/selenium_element_helper.rb +0 -138
- data/lib/automation_object/driver/nokogiri_adapter/backup/driver.rb +0 -83
- data/lib/automation_object/driver/nokogiri_adapter/backup/element.rb +0 -66
- data/lib/automation_object/driver/nokogiri_adapter/backup/helpers/driver_element_helper.rb +0 -52
- data/lib/automation_object/driver/nokogiri_adapter/backup/session.rb +0 -115
- data/lib/automation_object/dsl/blue_print_adapter.rb +0 -16
- data/lib/automation_object/dsl/blue_print_adapter/composite.rb +0 -54
- data/lib/automation_object/dsl/blue_print_adapter/element.rb +0 -14
- data/lib/automation_object/dsl/blue_print_adapter/element_array.rb +0 -14
- data/lib/automation_object/dsl/blue_print_adapter/element_hash.rb +0 -14
- data/lib/automation_object/dsl/blue_print_adapter/modal.rb +0 -23
- data/lib/automation_object/dsl/blue_print_adapter/screen.rb +0 -26
- data/lib/automation_object/dsl/blue_print_adapter/top.rb +0 -19
- data/lib/automation_object/dsl/models.rb +0 -18
- data/lib/automation_object/dsl/proxies/element.rb +0 -16
- data/lib/automation_object/dsl/proxies/element_array.rb +0 -16
- data/lib/automation_object/dsl/proxies/element_hash.rb +0 -16
- data/lib/automation_object/dsl/proxies/helpers/composite_helper.rb +0 -74
- data/lib/automation_object/dsl/proxies/modal.rb +0 -17
- data/lib/automation_object/dsl/proxies/screen.rb +0 -17
- data/lib/automation_object/dsl/proxies/top.rb +0 -17
- data/lib/automation_object/proxies/proxy.rb +0 -20
- data/lib/automation_object/proxies/throttle_proxy.rb +0 -57
- data/lib/automation_object/state/blue_print_adapter.rb +0 -16
- data/lib/automation_object/state/blue_print_adapter/element.rb +0 -20
- data/lib/automation_object/state/blue_print_adapter/element_array.rb +0 -25
- data/lib/automation_object/state/blue_print_adapter/element_hash.rb +0 -31
- data/lib/automation_object/state/blue_print_adapter/element_proxy.rb +0 -28
- data/lib/automation_object/state/blue_print_adapter/helpers/screen_manager.rb +0 -137
- data/lib/automation_object/state/blue_print_adapter/helpers/window.rb +0 -39
- data/lib/automation_object/state/blue_print_adapter/hook.rb +0 -56
- data/lib/automation_object/state/blue_print_adapter/hook_actions/action_loop.rb +0 -35
- data/lib/automation_object/state/blue_print_adapter/hook_actions/close_modal.rb +0 -31
- data/lib/automation_object/state/blue_print_adapter/hook_actions/close_screen.rb +0 -19
- data/lib/automation_object/state/blue_print_adapter/hook_actions/element_requirement.rb +0 -34
- data/lib/automation_object/state/blue_print_adapter/hook_actions/new_screen.rb +0 -37
- data/lib/automation_object/state/blue_print_adapter/hook_actions/reset_screen.rb +0 -18
- data/lib/automation_object/state/blue_print_adapter/modal.rb +0 -26
- data/lib/automation_object/state/blue_print_adapter/screen.rb +0 -32
- data/lib/automation_object/state/blue_print_adapter/top.rb +0 -45
- data/lib/automation_object/step_definitions/action.rb +0 -21
- data/lib/automation_object/step_definitions/element/actions.rb +0 -87
- data/lib/automation_object/step_definitions/element/regex.rb +0 -24
- data/lib/automation_object/step_definitions/element/steps.rb +0 -67
@@ -1,84 +1,139 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require_relative 'base'
|
2
|
-
require_relative 'driver'
|
3
3
|
|
4
4
|
module AutomationObject
|
5
5
|
module Driver
|
6
|
+
# Element adapter interface
|
6
7
|
class Element < Base
|
7
8
|
# Set or Get attribute
|
8
9
|
# @param key [String] key of element
|
9
10
|
# @param value [String, nil] set value or leave blank
|
10
11
|
# @return [String, nil]
|
11
12
|
def attribute(key, value = nil)
|
12
|
-
|
13
|
+
adapter.attribute(key, value)
|
13
14
|
end
|
14
15
|
|
15
16
|
# @return [String] id of element
|
16
17
|
def id
|
17
|
-
|
18
|
+
adapter.id
|
18
19
|
end
|
19
20
|
|
20
21
|
# @return [String] href of element
|
21
22
|
def href
|
22
|
-
|
23
|
+
adapter.href
|
23
24
|
end
|
24
25
|
|
25
26
|
# Text of element
|
26
27
|
# @return [String, nil]
|
27
28
|
def text
|
28
|
-
|
29
|
+
adapter.text
|
29
30
|
end
|
30
31
|
|
31
32
|
# Type into an element
|
32
33
|
# @return [void]
|
33
34
|
def send_keys(string)
|
34
|
-
|
35
|
+
adapter.send_keys(string)
|
35
36
|
end
|
36
37
|
|
37
38
|
# Clear the element field
|
38
39
|
# @return [void]
|
39
40
|
def clear
|
40
|
-
|
41
|
+
adapter.clear
|
41
42
|
end
|
42
43
|
|
43
44
|
# @return [Boolean]
|
44
45
|
def visible?
|
45
|
-
|
46
|
+
adapter.visible?
|
46
47
|
end
|
47
48
|
|
48
49
|
# @return [Boolean]
|
49
50
|
def invisible?
|
50
|
-
|
51
|
+
adapter.invisible?
|
51
52
|
end
|
52
53
|
|
53
54
|
# Get the location
|
54
55
|
# @return [Point]
|
55
56
|
def location
|
56
|
-
|
57
|
+
adapter.location
|
57
58
|
end
|
58
59
|
|
59
60
|
# Get the size of an element
|
60
61
|
# @return [Dimension]
|
61
62
|
def size
|
62
|
-
|
63
|
+
adapter.size
|
63
64
|
end
|
64
65
|
|
65
66
|
# Perform a submit action on an element
|
66
67
|
# @return [void]
|
67
68
|
def submit
|
68
|
-
|
69
|
+
adapter.submit
|
69
70
|
end
|
70
71
|
|
71
72
|
# Scroll the element into view
|
72
73
|
# @return [void]
|
73
74
|
def scroll_into_view
|
74
|
-
|
75
|
+
adapter.scroll_into_view
|
75
76
|
end
|
76
77
|
|
77
78
|
# Perform a click action on the element
|
78
79
|
# @return [void]
|
79
80
|
def click
|
80
|
-
|
81
|
+
adapter.click
|
82
|
+
end
|
83
|
+
|
84
|
+
# @return [Numeric] x position of element
|
85
|
+
def x
|
86
|
+
adapter.x
|
87
|
+
end
|
88
|
+
|
89
|
+
# @return [Numeric] y position of element
|
90
|
+
def y
|
91
|
+
adapter.y
|
92
|
+
end
|
93
|
+
|
94
|
+
# @return [Numeric] width of element
|
95
|
+
def width
|
96
|
+
adapter.width
|
97
|
+
end
|
98
|
+
|
99
|
+
# @return [Numeric] height of element
|
100
|
+
def height
|
101
|
+
adapter.height
|
102
|
+
end
|
103
|
+
|
104
|
+
# @return [String, nil] content attribute
|
105
|
+
def content
|
106
|
+
adapter.content
|
107
|
+
end
|
108
|
+
|
109
|
+
# @return [Point] :x, :y coordinates
|
110
|
+
def element_center
|
111
|
+
adapter.element_center
|
112
|
+
end
|
113
|
+
|
114
|
+
# @return [BoxCoordinates] :x1, :x2, :y1, :y2 coordinates of a box
|
115
|
+
def box_coordinates
|
116
|
+
adapter.box_coordinates
|
117
|
+
end
|
118
|
+
|
119
|
+
# @param second_element_object [Object] element to compare to
|
120
|
+
# @param collision_tolerance [Numeric, FalseClass] pixel tolerance of collisions
|
121
|
+
# @return [Boolean] element collides with other
|
122
|
+
def collides_with_element?(second_element_object, collision_tolerance = false)
|
123
|
+
adapter.collides_with_element?(second_element_object, collision_tolerance)
|
124
|
+
end
|
125
|
+
|
126
|
+
# Hover over element
|
127
|
+
# @return [void]
|
128
|
+
def hover
|
129
|
+
adapter.hover
|
130
|
+
end
|
131
|
+
|
132
|
+
# Helper method to switch to this element's iframe
|
133
|
+
# @return [void]
|
134
|
+
def switch_to_iframe
|
135
|
+
adapter.switch_to_iframe
|
81
136
|
end
|
82
137
|
end
|
83
138
|
end
|
84
|
-
end
|
139
|
+
end
|
@@ -1,104 +1,158 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'session'
|
3
|
+
|
1
4
|
require_relative '../element'
|
2
5
|
require_relative 'element'
|
3
6
|
|
4
7
|
module AutomationObject
|
5
8
|
module Driver
|
6
9
|
module NokogiriAdapter
|
7
|
-
#Driver for Nokogiri
|
8
|
-
#Conforms to interface and provides Selenium type functionality for XML only functionality
|
10
|
+
# Driver for Nokogiri
|
11
|
+
# Conforms to interface and provides Selenium type functionality for XML only functionality
|
9
12
|
class Driver
|
13
|
+
# @return [AutomationObject::Driver::NokogiriAdapter::Session]
|
14
|
+
attr_accessor :session
|
15
|
+
|
16
|
+
def initialize(*_args)
|
17
|
+
self.session = Session.new
|
18
|
+
end
|
19
|
+
|
10
20
|
# Navigates current window to a given url
|
11
21
|
# @param url [String] navigate to the following url
|
12
22
|
# @return [void]
|
13
23
|
def get(url)
|
14
|
-
|
24
|
+
session.request(:get, url)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Get the title of the document
|
28
|
+
# @return [String]
|
29
|
+
def title
|
30
|
+
find_element(:xpath, '//title').text
|
31
|
+
end
|
32
|
+
|
33
|
+
def back
|
34
|
+
session.back
|
35
|
+
end
|
36
|
+
|
37
|
+
def forward
|
38
|
+
session.forward
|
39
|
+
end
|
40
|
+
|
41
|
+
def refresh
|
42
|
+
session.refresh
|
43
|
+
end
|
44
|
+
|
45
|
+
# Destroy the driver
|
46
|
+
def quit
|
47
|
+
session.quit
|
15
48
|
end
|
16
49
|
|
17
50
|
# Set timeout wait
|
18
51
|
# @param timeout [Integer] the timeout in seconds
|
19
52
|
# @return [void]
|
20
|
-
def
|
21
|
-
self.adapter.set_wait(timeout)
|
53
|
+
def wait(timeout = nil)
|
22
54
|
end
|
23
55
|
|
24
|
-
# @param selector_type [Symbol] selector type
|
56
|
+
# @param selector_type [Symbol] selector type, :css, :xpath, etc...
|
25
57
|
# @param selector_path [String] path to element
|
26
|
-
# @return [Boolean] exists
|
58
|
+
# @return [Boolean] element exists?
|
27
59
|
def exists?(selector_type, selector_path)
|
28
|
-
|
60
|
+
elements = get_elements(selector_type, selector_path)
|
61
|
+
!elements.empty? ? true : false
|
29
62
|
end
|
30
63
|
|
31
64
|
# @param selector_type [Symbol] selector type, :css, :xpath, etc...
|
32
65
|
# @param selector_path [String] path to element
|
33
66
|
# @return [AutomationObject::Driver::Element] element
|
34
67
|
def find_element(selector_type, selector_path)
|
35
|
-
|
68
|
+
elements = get_elements(selector_type, selector_path)
|
69
|
+
raise NoSuchElementError if elements.length.zero?
|
70
|
+
|
71
|
+
AutomationObject::Driver::Element.new(
|
72
|
+
AutomationObject::Driver::NokogiriAdapter::Element.new(self, elements.first)
|
73
|
+
)
|
36
74
|
end
|
37
75
|
|
38
76
|
# @param selector_type [Symbol] selector type, :css, :xpath, etc...
|
39
77
|
# @param selector_path [String] path to element
|
40
78
|
# @return [Array<AutomationObject::Driver::Element>] elements
|
41
79
|
def find_elements(selector_type, selector_path)
|
42
|
-
|
80
|
+
elements = get_elements(selector_type, selector_path)
|
81
|
+
elements.map do |element|
|
82
|
+
AutomationObject::Driver::Element.new(
|
83
|
+
AutomationObject::Driver::NokogiriAdapter::Element.new(self, element)
|
84
|
+
)
|
85
|
+
end
|
43
86
|
end
|
44
87
|
|
45
|
-
#Accept prompt either in browser or mobile
|
88
|
+
# Accept prompt either in browser or mobile
|
46
89
|
def accept_prompt
|
47
|
-
self.adapter.accept_prompt
|
48
90
|
end
|
49
91
|
|
50
|
-
#Dismiss the prompt
|
92
|
+
# Dismiss the prompt
|
51
93
|
def dismiss_prompt
|
52
|
-
self.adapter.dismiss_prompt
|
53
94
|
end
|
54
95
|
|
55
96
|
# Check if browser, more useful for Appium but can be generic here
|
56
97
|
# @return [Boolean] whether or not browser is being used
|
57
|
-
def
|
58
|
-
|
98
|
+
def browser?
|
99
|
+
true
|
59
100
|
end
|
60
101
|
|
61
|
-
#Window Handles
|
102
|
+
# Window Handles
|
62
103
|
# @return [Array<String>] array of window handle ids
|
63
104
|
def window_handles
|
64
|
-
|
105
|
+
session.window_handles
|
65
106
|
end
|
66
107
|
|
67
|
-
#Current window handle
|
108
|
+
# Current window handle
|
68
109
|
# @return [String] handle id
|
69
110
|
def window_handle
|
70
|
-
|
111
|
+
session.window_handle
|
71
112
|
end
|
72
113
|
|
73
|
-
#Set current window handle to, will switch windows
|
114
|
+
# Set current window handle to, will switch windows
|
74
115
|
# @param handle_value [String] window handle value
|
75
116
|
def window_handle=(handle_value)
|
76
|
-
|
117
|
+
session.window_handle = handle_value
|
77
118
|
end
|
78
119
|
|
79
120
|
# Run script in browser to check if document in JS is complete
|
80
121
|
# @return [Boolean] document is complete
|
81
122
|
def document_complete?
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
# Wait till the document is complete
|
86
|
-
# @return [void]
|
87
|
-
def document_complete_wait
|
88
|
-
self.adapter.document_complete_wait
|
123
|
+
true
|
89
124
|
end
|
90
125
|
|
91
126
|
# @param script [String] JS to run
|
92
127
|
# @return [Object, nil]
|
93
128
|
def execute_script(script)
|
94
|
-
self.adapter.execute_script(script)
|
95
129
|
end
|
96
130
|
|
97
|
-
#
|
98
|
-
def
|
99
|
-
|
131
|
+
# @return [Point] x,y scroll position
|
132
|
+
def scroll_position
|
133
|
+
Point.new(x: 0, y: 0)
|
134
|
+
end
|
135
|
+
|
136
|
+
# @return [Float] inner window height
|
137
|
+
def inner_window_height
|
138
|
+
0
|
139
|
+
end
|
140
|
+
|
141
|
+
private
|
142
|
+
|
143
|
+
def get_elements(selector_type, selector_path)
|
144
|
+
case selector_type
|
145
|
+
when :xpath
|
146
|
+
elements = session.xml.xpath(selector_path)
|
147
|
+
when :css
|
148
|
+
elements = session.xml.css(selector_path)
|
149
|
+
else
|
150
|
+
raise ArgumentError, "#{selector_type} selector type not implemented. Only :css, :xpath"
|
151
|
+
end
|
152
|
+
|
153
|
+
elements
|
100
154
|
end
|
101
155
|
end
|
102
156
|
end
|
103
157
|
end
|
104
|
-
end
|
158
|
+
end
|
@@ -1,85 +1,163 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative '../driver'
|
3
|
+
require_relative 'error'
|
4
|
+
|
1
5
|
module AutomationObject
|
2
6
|
module Driver
|
3
7
|
module NokogiriAdapter
|
4
|
-
#Element for nokogiri
|
5
|
-
#Conforms to Element interface for an XML source using Nokogiri
|
8
|
+
# Element for nokogiri
|
9
|
+
# Conforms to Element interface for an XML source using Nokogiri
|
6
10
|
class Element
|
11
|
+
# @param [AutomationObject::Driver::NokogiriAdapter::Driver] driver
|
12
|
+
# @param [Nokogiri::XML::Node] element
|
13
|
+
def initialize(driver, element)
|
14
|
+
@driver = driver
|
15
|
+
@subject = element
|
16
|
+
end
|
17
|
+
|
7
18
|
# Set or Get attribute
|
8
19
|
# @param key [String] key of element
|
9
20
|
# @param value [String, nil] set value or leave blank
|
10
21
|
# @return [String, nil]
|
11
22
|
def attribute(key, value = nil)
|
12
|
-
|
23
|
+
@subject[key] = value if value
|
24
|
+
@subject[key]
|
13
25
|
end
|
14
26
|
|
15
27
|
# @return [String] id of element
|
16
28
|
def id
|
17
|
-
|
29
|
+
@subject['id']
|
18
30
|
end
|
19
31
|
|
20
32
|
# @return [String] href of element
|
21
33
|
def href
|
22
|
-
|
34
|
+
@subject['href']
|
23
35
|
end
|
24
36
|
|
25
37
|
# Text of element
|
26
38
|
# @return [String, nil]
|
27
39
|
def text
|
28
|
-
|
40
|
+
@subject.content
|
41
|
+
end
|
42
|
+
|
43
|
+
# Content of element
|
44
|
+
# @return [String, nil]
|
45
|
+
def content
|
46
|
+
@subject.content
|
29
47
|
end
|
30
48
|
|
31
49
|
# Type into an element
|
32
50
|
# @return [void]
|
33
51
|
def send_keys(string)
|
34
|
-
|
52
|
+
@subject['value'] = @subject[key] + string if @subject['value'].is_a?(String)
|
53
|
+
|
54
|
+
@subject['value'] = value
|
35
55
|
end
|
36
56
|
|
37
57
|
# Clear the element field
|
38
58
|
# @return [void]
|
39
59
|
def clear
|
40
|
-
|
60
|
+
@subject['value'] = ''
|
41
61
|
end
|
42
62
|
|
43
63
|
# @return [Boolean]
|
44
64
|
def visible?
|
45
|
-
self.adapter.visible?
|
46
65
|
end
|
47
66
|
|
48
67
|
# @return [Boolean]
|
49
68
|
def invisible?
|
50
|
-
self.adapter.invisible?
|
51
69
|
end
|
52
70
|
|
53
71
|
# Get the location
|
54
72
|
# @return [Point]
|
55
73
|
def location
|
56
|
-
self.adapter.location
|
57
74
|
end
|
58
75
|
|
59
76
|
# Get the size of an element
|
60
77
|
# @return [Dimension]
|
61
78
|
def size
|
62
|
-
self.adapter.size
|
63
79
|
end
|
64
80
|
|
65
81
|
# Perform a submit action on an element
|
66
82
|
# @return [void]
|
67
83
|
def submit
|
68
|
-
|
84
|
+
form_element = find_form(@subject)
|
85
|
+
raise NoSuchElementError unless form_element
|
86
|
+
@driver.session.request(form.request_method, form.url, form.params, form_element.new_window?)
|
69
87
|
end
|
70
88
|
|
71
89
|
# Scroll the element into view
|
72
90
|
# @return [void]
|
73
91
|
def scroll_into_view
|
74
|
-
self.adapter.scroll_into_view
|
75
92
|
end
|
76
93
|
|
77
94
|
# Perform a click action on the element
|
78
95
|
# @return [void]
|
79
96
|
def click
|
80
|
-
|
97
|
+
@driver.session.request(:get, href, {}, attribute('target') == '_blank') if href && @subject['tag'] == 'a'
|
98
|
+
|
99
|
+
# In case it's a button inside the form
|
100
|
+
submit if find_form(@subject)
|
101
|
+
end
|
102
|
+
|
103
|
+
# @return [Numeric] x position of element
|
104
|
+
def x
|
105
|
+
0
|
106
|
+
end
|
107
|
+
|
108
|
+
# @return [Numeric] y position of element
|
109
|
+
def y
|
110
|
+
0
|
111
|
+
end
|
112
|
+
|
113
|
+
# @return [Numeric] width of element
|
114
|
+
def width
|
115
|
+
0
|
116
|
+
end
|
117
|
+
|
118
|
+
# @return [Numeric] height of element
|
119
|
+
def height
|
120
|
+
0
|
121
|
+
end
|
122
|
+
|
123
|
+
# @return [Point] :x, :y coordinates
|
124
|
+
def element_center
|
125
|
+
Point.new(x: 0, y: 0)
|
126
|
+
end
|
127
|
+
|
128
|
+
# @return [BoxCoordinates] :x1, :x2, :y1, :y2 coordinates of a box
|
129
|
+
def box_coordinates
|
130
|
+
BoxCoordinates.new(x1: 0, y1: 0, x2: 0, y2: 0)
|
131
|
+
end
|
132
|
+
|
133
|
+
# @param second_element_object [Object] element to compare to
|
134
|
+
# @param collision_tolerance [Numeric, FalseClass] pixel tolerance of collisions
|
135
|
+
# @return [Boolean] element collides with other
|
136
|
+
def collides_with_element?(_second_element_object, _collision_tolerance = false)
|
137
|
+
false
|
138
|
+
end
|
139
|
+
|
140
|
+
# Hover over element
|
141
|
+
# @return [void]
|
142
|
+
def hover
|
143
|
+
end
|
144
|
+
|
145
|
+
# Helper method to switch to this element's iframe
|
146
|
+
# @return [void]
|
147
|
+
def switch_to_iframe
|
148
|
+
# TODO: finish
|
149
|
+
end
|
150
|
+
|
151
|
+
private
|
152
|
+
|
153
|
+
# @return [AutomationObject::Driver:NokogiriAdapter::Form]
|
154
|
+
def find_form(element)
|
155
|
+
return nil unless element
|
156
|
+
|
157
|
+
return AutomationObject::Driver::NokogiriAdapter::Form.new(element) if element.name == 'form'
|
158
|
+
find_form(element.parent)
|
81
159
|
end
|
82
160
|
end
|
83
161
|
end
|
84
162
|
end
|
85
|
-
end
|
163
|
+
end
|