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,41 +0,0 @@
|
|
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
|
@@ -1,138 +0,0 @@
|
|
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
|
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
require 'rest_client'
|
3
|
-
|
4
|
-
require_relative 'session'
|
5
|
-
require_relative 'element'
|
6
|
-
require_relative 'helpers/driver_element_helper'
|
7
|
-
|
8
|
-
module AutomationObject::Driver::NokogiriAdapter
|
9
|
-
#Driver proxy for Nokogiri(XML)
|
10
|
-
#Create driver interface that conforms to Driver port
|
11
|
-
#Works differently than Appium/Selenium, not a proxy, but creates the functionality of the driver
|
12
|
-
class Driver
|
13
|
-
include DriverElementHelper
|
14
|
-
|
15
|
-
attr_accessor :current_url
|
16
|
-
|
17
|
-
def initialize(*args)
|
18
|
-
@session = Session.new
|
19
|
-
end
|
20
|
-
|
21
|
-
def navigate
|
22
|
-
self
|
23
|
-
end
|
24
|
-
|
25
|
-
def to(url)
|
26
|
-
@session.get(url)
|
27
|
-
end
|
28
|
-
|
29
|
-
def back
|
30
|
-
@session.back
|
31
|
-
end
|
32
|
-
|
33
|
-
def quit
|
34
|
-
@session.quit
|
35
|
-
end
|
36
|
-
|
37
|
-
def close
|
38
|
-
@session.close
|
39
|
-
end
|
40
|
-
|
41
|
-
def current_url
|
42
|
-
@session.current_url
|
43
|
-
end
|
44
|
-
|
45
|
-
def window_handles
|
46
|
-
@session.window_handles
|
47
|
-
end
|
48
|
-
|
49
|
-
def window_handle
|
50
|
-
@session.window_handle
|
51
|
-
end
|
52
|
-
|
53
|
-
def window_handle=(handle_value)
|
54
|
-
@session.window_handle = handle_value
|
55
|
-
end
|
56
|
-
|
57
|
-
def new_window
|
58
|
-
@session.new_window
|
59
|
-
end
|
60
|
-
|
61
|
-
def xml
|
62
|
-
@session.xml
|
63
|
-
end
|
64
|
-
|
65
|
-
def title
|
66
|
-
title = ''
|
67
|
-
title_element = self.find_element(:xpath, '//title')
|
68
|
-
if title_element
|
69
|
-
title = title_element.text
|
70
|
-
end
|
71
|
-
|
72
|
-
return title
|
73
|
-
end
|
74
|
-
|
75
|
-
def get(url, params = {})
|
76
|
-
@session.get(url, params)
|
77
|
-
end
|
78
|
-
|
79
|
-
def post(url, params = {})
|
80
|
-
@session.post(url, params)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require_relative 'form'
|
2
|
-
|
3
|
-
module AutomationObject::Driver::NokogiriAdapter
|
4
|
-
#Element class for Nokogiri/XML
|
5
|
-
class Element < AutomationObject::Proxies::Proxy
|
6
|
-
def initialize(args)
|
7
|
-
@driver = args.fetch :driver
|
8
|
-
@subject = args.fetch :element
|
9
|
-
end
|
10
|
-
|
11
|
-
# @return [String] id of element
|
12
|
-
def id
|
13
|
-
@subject['id']
|
14
|
-
end
|
15
|
-
|
16
|
-
# @return [String] href of element
|
17
|
-
def href
|
18
|
-
@subject['href']
|
19
|
-
end
|
20
|
-
|
21
|
-
# @return [String] text of element
|
22
|
-
def text
|
23
|
-
@subject['content']
|
24
|
-
end
|
25
|
-
|
26
|
-
# @return [String] content of element
|
27
|
-
def content
|
28
|
-
@subject['content']
|
29
|
-
end
|
30
|
-
|
31
|
-
def attribute(key, value = nil)
|
32
|
-
@subject[key] = value if value
|
33
|
-
return @subject[key]
|
34
|
-
end
|
35
|
-
|
36
|
-
def click
|
37
|
-
url = self.href
|
38
|
-
if self.attribute('target') == '_blank'
|
39
|
-
@driver.new_window
|
40
|
-
end
|
41
|
-
|
42
|
-
@driver.get(url)
|
43
|
-
end
|
44
|
-
|
45
|
-
def send_keys(text)
|
46
|
-
@subject['value'] = text
|
47
|
-
end
|
48
|
-
|
49
|
-
def submit
|
50
|
-
form = find_form(@subject)
|
51
|
-
raise 'Unable to find form' unless form_element
|
52
|
-
|
53
|
-
@driver.send(form.request_method, form.params)
|
54
|
-
end
|
55
|
-
|
56
|
-
private
|
57
|
-
|
58
|
-
# @return [AutomationObject::Driver:NokogiriAdapter::Form]
|
59
|
-
def find_form(element)
|
60
|
-
return nil unless element
|
61
|
-
|
62
|
-
return AutomationObject::Driver::NokogiriAdapter::Form.new(element) if element.name == 'form'
|
63
|
-
return find_form(element.parent)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require_relative '../error'
|
2
|
-
|
3
|
-
module AutomationObject
|
4
|
-
module Driver
|
5
|
-
module NokogiriAdapter
|
6
|
-
module DriverElementHelper
|
7
|
-
# @param selector_type [Symbol] selector type, :css, :xpath, etc...
|
8
|
-
# @param selector_path [String] path to element
|
9
|
-
# @return [Element] element
|
10
|
-
def find_element(selector_type, selector_path)
|
11
|
-
elements = self.get_elements(selector_type, selector_path)
|
12
|
-
raise NoSuchElementError if elements.length == 0
|
13
|
-
|
14
|
-
return AutomationObject::Driver::NokogiriAdapter::Element.new(driver: self, element: elements.first)
|
15
|
-
end
|
16
|
-
|
17
|
-
# @param selector_type [Symbol] selector type, :css, :xpath, etc...
|
18
|
-
# @param selector_path [String] path to element
|
19
|
-
# @return [Array<Element>] elements
|
20
|
-
def find_elements(selector_type, selector_path)
|
21
|
-
elements = self.get_elements(selector_type, selector_path)
|
22
|
-
return elements.map { |element|
|
23
|
-
AutomationObject::Driver::NokogiriAdapter::Element.new(driver: self, element: element)
|
24
|
-
}
|
25
|
-
end
|
26
|
-
|
27
|
-
# @param selector_type [Symbol] selector type, :css, :xpath, etc...
|
28
|
-
# @param selector_path [String] path to element
|
29
|
-
# @return [Boolean] element exists?
|
30
|
-
def exists?(selector_type, selector_path)
|
31
|
-
elements = self.get_elements(selector_type, selector_path)
|
32
|
-
return (elements.length > 0) ? true : false
|
33
|
-
end
|
34
|
-
|
35
|
-
protected
|
36
|
-
|
37
|
-
def get_elements(selector_type, selector_path)
|
38
|
-
case selector_type
|
39
|
-
when :xpath
|
40
|
-
elements = self.xml.xpath(selector_path)
|
41
|
-
when :css
|
42
|
-
elements = self.xml.css(selector_path)
|
43
|
-
else
|
44
|
-
raise ArgumentError, "#{selector_type} selector type not implemented. Only :css, :xpath"
|
45
|
-
end
|
46
|
-
|
47
|
-
return elements
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,115 +0,0 @@
|
|
1
|
-
require 'securerandom'
|
2
|
-
require_relative 'error'
|
3
|
-
|
4
|
-
module AutomationObject::Driver::NokogiriAdapter
|
5
|
-
#Class for creating/maintaining XML session
|
6
|
-
#Trying to replicate some functionality of Selenium like multiple windows, etc...
|
7
|
-
class Session
|
8
|
-
attr_accessor :window_handles, :window_handle, :current_url, :url_history
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
self.create_session
|
12
|
-
end
|
13
|
-
|
14
|
-
def create_session
|
15
|
-
self.current_url = nil
|
16
|
-
self.url_history = {self.window_handle => Array.new}
|
17
|
-
self.window_handles = [self.window_handle]
|
18
|
-
|
19
|
-
@windows_xml = Hash.new
|
20
|
-
|
21
|
-
return nil
|
22
|
-
end
|
23
|
-
|
24
|
-
def new_window
|
25
|
-
self.window_handles.push(SecureRandom.hex(16))
|
26
|
-
self.url_history[self.window_handles.last] = Array.new
|
27
|
-
self.window_handle = self.window_handles.last
|
28
|
-
end
|
29
|
-
|
30
|
-
# @return [String] current window handle
|
31
|
-
def window_handle
|
32
|
-
@window_handle ||= SecureRandom.hex(16)
|
33
|
-
end
|
34
|
-
|
35
|
-
#Switch window handles
|
36
|
-
# @param handle_value [String] handle value of window to switch to
|
37
|
-
def window_handle=(handle_value)
|
38
|
-
unless self.window_handles.include?(handle_value)
|
39
|
-
raise NoSuchWindowError
|
40
|
-
end
|
41
|
-
|
42
|
-
#Array returns nil if length is 0, so no need for if
|
43
|
-
self.current_url = self.url_history[handle_value].last
|
44
|
-
|
45
|
-
@window_handle = handle_value
|
46
|
-
end
|
47
|
-
|
48
|
-
def xml(xml = nil)
|
49
|
-
@windows_xml[self.window_handle] = xml if xml
|
50
|
-
|
51
|
-
unless @windows_xml[self.window_handle]
|
52
|
-
raise NoSuchDocumentError
|
53
|
-
end
|
54
|
-
|
55
|
-
return @windows_xml[self.window_handle]
|
56
|
-
end
|
57
|
-
|
58
|
-
# Get url, will set xml to current window handle
|
59
|
-
# @param url [String] url to get xml for
|
60
|
-
# @return [Object] nokogiri object
|
61
|
-
def get(url, params = {})
|
62
|
-
request(:get, url, params)
|
63
|
-
end
|
64
|
-
|
65
|
-
# Post url, will set xml to current window handle
|
66
|
-
# @param url [String] url to get xml for
|
67
|
-
# @return [Object] nokogiri object
|
68
|
-
def post(url, params = {})
|
69
|
-
request(:post, url, params)
|
70
|
-
end
|
71
|
-
|
72
|
-
# Request url, will set xml to current window handle
|
73
|
-
# @param url [String] url to get xml for
|
74
|
-
# @return [Object] nokogiri object
|
75
|
-
def request(type, url, params)
|
76
|
-
if url.valid_url? == false and self.current_url == nil
|
77
|
-
raise ArgumentError, "Expecting get argument url to be a valid_url?, got #{url}"
|
78
|
-
elsif url.valid_url? == false and self.current_url
|
79
|
-
url = self.current_url.join_url(url)
|
80
|
-
end
|
81
|
-
|
82
|
-
client_resource = RestClient::Resource.new(url, :ssl_version => 'SSLv23_client')
|
83
|
-
response = client_resource.send(type)
|
84
|
-
|
85
|
-
self.current_url = url
|
86
|
-
self.url_history[self.window_handle].push(url)
|
87
|
-
self.xml(Nokogiri::HTML.parse(response))
|
88
|
-
end
|
89
|
-
|
90
|
-
def back
|
91
|
-
current_url_index = self.url_history[self.window_handle].index(self.current_url)
|
92
|
-
return if current_url_index == 0
|
93
|
-
|
94
|
-
self.url_history[self.window_handle].delete_at(current_url_index)
|
95
|
-
url = self.url_history[self.window_handle].delete_at(current_url_index - 1) #get will insert url anyways
|
96
|
-
|
97
|
-
self.get(url)
|
98
|
-
end
|
99
|
-
|
100
|
-
def close
|
101
|
-
#Just reset everything if only one "window" is open
|
102
|
-
return self.create_session if self.window_handles.length == 1
|
103
|
-
|
104
|
-
@windows_xml.delete(self.window_handle)
|
105
|
-
self.url_history.delete(self.window_handle)
|
106
|
-
self.window_handles.delete(self.window_handle)
|
107
|
-
self.window_handle = self.window_handles.first
|
108
|
-
end
|
109
|
-
|
110
|
-
#Just reset the session
|
111
|
-
def quit
|
112
|
-
self.create_session
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|