automation_object 0.0.4 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,85 @@
|
|
1
|
+
module AutomationObject
|
2
|
+
module Driver
|
3
|
+
module NokogiriAdapter
|
4
|
+
#Element for nokogiri
|
5
|
+
#Conforms to Element interface for an XML source using Nokogiri
|
6
|
+
class Element
|
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)
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [String] id of element
|
16
|
+
def id
|
17
|
+
self.adapter.id
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [String] href of element
|
21
|
+
def href
|
22
|
+
self.adapter.href
|
23
|
+
end
|
24
|
+
|
25
|
+
# Text of element
|
26
|
+
# @return [String, nil]
|
27
|
+
def text
|
28
|
+
self.adapter.text
|
29
|
+
end
|
30
|
+
|
31
|
+
# Type into an element
|
32
|
+
# @return [void]
|
33
|
+
def send_keys(string)
|
34
|
+
self.adapter.send_keys(string)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Clear the element field
|
38
|
+
# @return [void]
|
39
|
+
def clear
|
40
|
+
self.adapter.clear
|
41
|
+
end
|
42
|
+
|
43
|
+
# @return [Boolean]
|
44
|
+
def visible?
|
45
|
+
self.adapter.visible?
|
46
|
+
end
|
47
|
+
|
48
|
+
# @return [Boolean]
|
49
|
+
def invisible?
|
50
|
+
self.adapter.invisible?
|
51
|
+
end
|
52
|
+
|
53
|
+
# Get the location
|
54
|
+
# @return [Point]
|
55
|
+
def location
|
56
|
+
self.adapter.location
|
57
|
+
end
|
58
|
+
|
59
|
+
# Get the size of an element
|
60
|
+
# @return [Dimension]
|
61
|
+
def size
|
62
|
+
self.adapter.size
|
63
|
+
end
|
64
|
+
|
65
|
+
# Perform a submit action on an element
|
66
|
+
# @return [void]
|
67
|
+
def submit
|
68
|
+
self.adapter.submit
|
69
|
+
end
|
70
|
+
|
71
|
+
# Scroll the element into view
|
72
|
+
# @return [void]
|
73
|
+
def scroll_into_view
|
74
|
+
self.adapter.scroll_into_view
|
75
|
+
end
|
76
|
+
|
77
|
+
# Perform a click action on the element
|
78
|
+
# @return [void]
|
79
|
+
def click
|
80
|
+
self.adapter.click
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module AutomationObject
|
2
|
+
module Driver
|
3
|
+
#Emulate Selenium errors
|
4
|
+
#http://www.rubydoc.info/gems/selenium-webdriver/Selenium/WebDriver/Error
|
5
|
+
module NokogiriAdapter
|
6
|
+
#
|
7
|
+
class WebDriverError < StandardError;
|
8
|
+
end
|
9
|
+
class NoSuchElementError < WebDriverError;
|
10
|
+
end
|
11
|
+
class NoSuchWindowError < WebDriverError;
|
12
|
+
end
|
13
|
+
class NoSuchDocumentError < WebDriverError;
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require_relative '../../proxies/proxy'
|
2
|
+
require_relative '../helpers/selenium_driver_helper'
|
3
|
+
|
4
|
+
require_relative '../element'
|
5
|
+
require_relative 'element'
|
6
|
+
|
7
|
+
module AutomationObject
|
8
|
+
module Driver
|
9
|
+
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
|
16
|
+
|
17
|
+
# @param driver [Selenium::WebDriver::Driver] Selenium Web Driver
|
18
|
+
def initialize(driver)
|
19
|
+
@subject = driver
|
20
|
+
end
|
21
|
+
|
22
|
+
# Navigates current window to a given url
|
23
|
+
# @param url [String] navigate to the following url
|
24
|
+
# @return [void]
|
25
|
+
def get(url)
|
26
|
+
@subject.navigate.to(url)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Set timeout wait
|
30
|
+
# @param timeout [Integer] the timeout in seconds
|
31
|
+
# @return [void]
|
32
|
+
def set_wait(timeout = nil)
|
33
|
+
timeout = 0 unless timeout
|
34
|
+
@subject.manage.timeouts.implicit_wait = timeout
|
35
|
+
end
|
36
|
+
|
37
|
+
# @param selector_type [Symbol] selector type (:css, :xpath, etc...)
|
38
|
+
# @param selector_path [String] path to element
|
39
|
+
# @return [Boolean] exists or not
|
40
|
+
def exists?(selector_type, selector_path)
|
41
|
+
exists = false
|
42
|
+
|
43
|
+
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
|
50
|
+
end
|
51
|
+
rescue Exception => e
|
52
|
+
end
|
53
|
+
|
54
|
+
return exists
|
55
|
+
end
|
56
|
+
|
57
|
+
# @param selector_type [Symbol] selector type, :css, :xpath, etc...
|
58
|
+
# @param selector_path [String] path to element
|
59
|
+
# @return [Object] element
|
60
|
+
def find_element(selector_type, selector_path)
|
61
|
+
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))
|
64
|
+
end
|
65
|
+
|
66
|
+
# @param selector_type [Symbol] selector type, :css, :xpath, etc...
|
67
|
+
# @param selector_path [String] path to element
|
68
|
+
# @return [Object] element
|
69
|
+
def find_elements(selector_type, selector_path)
|
70
|
+
elements = @subject.find_elements(selector_type, selector_path)
|
71
|
+
|
72
|
+
elements.map { |element|
|
73
|
+
AutomationObject::Driver::Element.new(Element.new(driver: self, element: element))
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
#Accept prompt either in browser or mobile
|
78
|
+
def accept_prompt
|
79
|
+
alert = @subject.switch_to.alert
|
80
|
+
alert.accept
|
81
|
+
@subject.switch_to.default_content
|
82
|
+
end
|
83
|
+
|
84
|
+
#Dismiss the prompt
|
85
|
+
def dismiss_prompt
|
86
|
+
alert = @subject.switch_to.alert
|
87
|
+
alert.dismiss
|
88
|
+
@subject.switch_to.default_content
|
89
|
+
end
|
90
|
+
|
91
|
+
# Check if browser, more useful for Appium but can be generic here
|
92
|
+
# @return [Boolean] whether or not browser is being used
|
93
|
+
def is_browser?
|
94
|
+
true
|
95
|
+
end
|
96
|
+
|
97
|
+
#Window Handles
|
98
|
+
# @return [Array<String>] array of window handle ids
|
99
|
+
def window_handles
|
100
|
+
@subject.window_handles
|
101
|
+
end
|
102
|
+
|
103
|
+
#Current window handle
|
104
|
+
# @return [String] handle id
|
105
|
+
def window_handle
|
106
|
+
@subject.window_handle
|
107
|
+
end
|
108
|
+
|
109
|
+
#Set current window handle to, will switch windows
|
110
|
+
# @param handle_value [String] window handle value
|
111
|
+
def window_handle=(handle_value)
|
112
|
+
@subject.switch_to.window(handle_value)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Run script in browser to check if document in JS is complete
|
116
|
+
# @return [Boolean] document is complete
|
117
|
+
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)
|
134
|
+
end
|
135
|
+
|
136
|
+
# Destroy the driver
|
137
|
+
def quit
|
138
|
+
@subject.quit
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require_relative '../helpers/selenium_element_helper'
|
2
|
+
|
3
|
+
module AutomationObject
|
4
|
+
module Driver
|
5
|
+
module SeleniumAdapter
|
6
|
+
#Element proxy for Selenium
|
7
|
+
#Conform Selenium element interface to what's expected of the Driver Port
|
8
|
+
class Element < AutomationObject::Proxies::Proxy
|
9
|
+
include AutomationObject::Driver::SeleniumElementHelper
|
10
|
+
|
11
|
+
def initialize(args)
|
12
|
+
@driver = args.fetch :driver
|
13
|
+
@subject = args.fetch :element
|
14
|
+
end
|
15
|
+
|
16
|
+
# Set or Get attribute
|
17
|
+
# @param key [String] key of element
|
18
|
+
# @param value [String, nil] set value or leave blank
|
19
|
+
# @return [String, nil]
|
20
|
+
def attribute(key, value = nil)
|
21
|
+
@subject.attribute(key, value)
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [String] id of element
|
25
|
+
def id
|
26
|
+
@subject.id
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [String] href of element
|
30
|
+
def href
|
31
|
+
@subject.attribute('href')
|
32
|
+
end
|
33
|
+
|
34
|
+
# Text of element
|
35
|
+
# @return [String, nil]
|
36
|
+
def text
|
37
|
+
@subject.text
|
38
|
+
end
|
39
|
+
|
40
|
+
# Type into an element
|
41
|
+
# @return [void]
|
42
|
+
def send_keys(string)
|
43
|
+
@subject.send_keys(string)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Clear the element field
|
47
|
+
# @return [void]
|
48
|
+
def clear
|
49
|
+
@subject.clear
|
50
|
+
end
|
51
|
+
|
52
|
+
# @return [Boolean]
|
53
|
+
def visible?
|
54
|
+
@subject.displayed?
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [Boolean]
|
58
|
+
def invisible?
|
59
|
+
!@subject.displayed?
|
60
|
+
end
|
61
|
+
|
62
|
+
# Get the location
|
63
|
+
# @return [Point]
|
64
|
+
def location
|
65
|
+
@subject.location
|
66
|
+
end
|
67
|
+
|
68
|
+
# Get the size of an element
|
69
|
+
# @return [Dimension]
|
70
|
+
def size
|
71
|
+
@subject.size
|
72
|
+
end
|
73
|
+
|
74
|
+
# Perform a submit action on an element
|
75
|
+
# @return [void]
|
76
|
+
def submit
|
77
|
+
@subject.submit
|
78
|
+
end
|
79
|
+
|
80
|
+
# Scroll the element into view
|
81
|
+
# @return [void]
|
82
|
+
def scroll_into_view
|
83
|
+
@subject.location_once_scrolled_into_view
|
84
|
+
|
85
|
+
element_location = self.location
|
86
|
+
scroll_position = @driver.scroll_position
|
87
|
+
|
88
|
+
middle_y_bounds = scroll_position[:y] + @driver.inner_window_height/2
|
89
|
+
|
90
|
+
if middle_y_bounds > element_location.y
|
91
|
+
#Add
|
92
|
+
y_difference = middle_y_bounds - element_location.y
|
93
|
+
scroll_y_position = scroll_position[:y] - y_difference
|
94
|
+
else
|
95
|
+
#Subtract
|
96
|
+
y_difference = element_location.y - middle_y_bounds
|
97
|
+
scroll_y_position = scroll_position[:y] + y_difference
|
98
|
+
end
|
99
|
+
|
100
|
+
#Get the element to halfway
|
101
|
+
scroll_x_position = element_location.x.to_f
|
102
|
+
|
103
|
+
javascript_string = "return window.scroll(#{scroll_x_position}, #{scroll_y_position});"
|
104
|
+
@driver.execute_script(javascript_string)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Perform a click action on the element
|
108
|
+
# @return [void]
|
109
|
+
def click
|
110
|
+
self.scroll_into_view
|
111
|
+
@subject.click
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module AutomationObject
|
2
|
+
#Dsl Port
|
3
|
+
module Dsl
|
4
|
+
extend self
|
5
|
+
|
6
|
+
# @return [AutomationObject::Dsl::Module]
|
7
|
+
def adapter
|
8
|
+
return @adapter if @adapter
|
9
|
+
self.adapter = :blue_print
|
10
|
+
@adapter
|
11
|
+
end
|
12
|
+
|
13
|
+
# Sets adapter const will append _adapter if needed
|
14
|
+
# @param adapter_name [String] name of adapter wanted for composite creation
|
15
|
+
def adapter=(adapter_name)
|
16
|
+
adapter_name = adapter_name.to_s
|
17
|
+
adapter_name << '_adapter' unless adapter_name.match(/_adapter$/)
|
18
|
+
adapter_const = adapter_name.pascalize
|
19
|
+
|
20
|
+
require_relative "dsl/#{adapter_name}"
|
21
|
+
@adapter = AutomationObject::Dsl.const_get("#{adapter_const}")
|
22
|
+
end
|
23
|
+
|
24
|
+
# Creates/returns composite and attaches the State to the composite
|
25
|
+
# @return [AutomationObject::Dsl::Models::Top]
|
26
|
+
def new(args={})
|
27
|
+
composite = self.adapter.build(args)
|
28
|
+
composite.state = args.fetch(:state)
|
29
|
+
|
30
|
+
return composite
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative 'blue_print_adapter/top'
|
2
|
+
|
3
|
+
module AutomationObject
|
4
|
+
module Dsl
|
5
|
+
#BluePrint adapter for building DSL framework
|
6
|
+
#Follows similar pattern to BluePrint::HashAdapter composite
|
7
|
+
module BluePrintAdapter
|
8
|
+
# @param args [Hash] expects :blue_prints, :state
|
9
|
+
# @return [AutomationObject::Dsl::Models::Top]
|
10
|
+
def self.build(args={})
|
11
|
+
blue_print_adapter = Top.new(blue_prints: args.fetch(:blue_prints))
|
12
|
+
return blue_print_adapter.build
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module AutomationObject
|
2
|
+
module Dsl
|
3
|
+
module BluePrintAdapter
|
4
|
+
#Base class for the DSL BluePrint adapter composite
|
5
|
+
#BluePrintAdapter uses the BluePrint composite to create the proxy/model composite in the DSL
|
6
|
+
class Composite
|
7
|
+
class << self;
|
8
|
+
attr_accessor :implemented_proxy
|
9
|
+
end
|
10
|
+
|
11
|
+
# @param args [Hash] arguments, expects :blue_prints
|
12
|
+
def initialize(args={})
|
13
|
+
@blue_prints = args.fetch :blue_prints
|
14
|
+
end
|
15
|
+
|
16
|
+
# Build and return the DSL composite
|
17
|
+
# @return [Object] composite for the given level
|
18
|
+
def build
|
19
|
+
proxy = self.class.implemented_proxy.new
|
20
|
+
|
21
|
+
self.class.has_many_relationships.each { |name, composite_class|
|
22
|
+
@blue_prints.send(name).each { |child_key, child_blue_prints|
|
23
|
+
child_composite = composite_class.new(blue_prints: child_blue_prints)
|
24
|
+
child_proxy = child_composite.build
|
25
|
+
|
26
|
+
type = name.to_s.gsub(/e?s$/, '').to_sym #Unpluralize
|
27
|
+
proxy.add(name: child_key, type: type, object: child_proxy)
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
return proxy
|
32
|
+
end
|
33
|
+
|
34
|
+
#Declare which proxy is being used by the given BluePrint::Adapter composite class
|
35
|
+
# @param proxy_class [Class] proxy class used by the given composite
|
36
|
+
def self.implements_proxy(proxy_class)
|
37
|
+
self.implemented_proxy = proxy_class
|
38
|
+
end
|
39
|
+
|
40
|
+
#Has many children relationship for the composite
|
41
|
+
# @param children_name [Symbol] name of the children, should be a BluePrint method
|
42
|
+
# @param args [Hash] additional arguments, expects interface
|
43
|
+
def self.has_many(children_name, args)
|
44
|
+
self.has_many_relationships[children_name] = args.fetch(:interface)
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [Hash] relationships for the composite
|
48
|
+
def self.has_many_relationships
|
49
|
+
@has_many_relationships ||= Hash.new
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|