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,39 @@
|
|
1
|
+
require_relative 'validate'
|
2
|
+
|
3
|
+
module AutomationObject
|
4
|
+
module BluePrint
|
5
|
+
module HashAdapter
|
6
|
+
module Validators
|
7
|
+
#Validator that tests that a element is defined when it is called elsewhere through a hook
|
8
|
+
class ValidateInstanceOf < Validate
|
9
|
+
# @param args [Hash] arguments for the validation class
|
10
|
+
def initialize(args)
|
11
|
+
@key = args.fetch :key
|
12
|
+
#Convert to array of instances for consistency
|
13
|
+
@should_be_instances_of = (args.fetch(:args).is_a?(Array)) ? args.fetch(:args) : [args.fetch(:args)]
|
14
|
+
end
|
15
|
+
|
16
|
+
# Validates the composite object and throws errors on failure
|
17
|
+
# @param composite_object [Object] Composite object to be tested.
|
18
|
+
# @return [nil] no return on exceptions on failure
|
19
|
+
def validate(composite_object)
|
20
|
+
#Get the hash value from the composite object
|
21
|
+
target_value = composite_object.hash[@key]
|
22
|
+
|
23
|
+
#Skip empty or non-existent
|
24
|
+
return unless target_value
|
25
|
+
|
26
|
+
@should_be_instances_of.each { |should_be_instance_of|
|
27
|
+
return if target_value.is_a?(should_be_instance_of)
|
28
|
+
}
|
29
|
+
|
30
|
+
error_message = "Invalid Type: #{target_value.class}, at: #{composite_object.location}[#{@key}]."
|
31
|
+
error_message << " Allowed Type(s): #{@should_be_instances_of}"
|
32
|
+
|
33
|
+
self.error_messages.push(error_message)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_modal_presence_of.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative 'validate'
|
2
|
+
|
3
|
+
module AutomationObject
|
4
|
+
module BluePrint
|
5
|
+
module HashAdapter
|
6
|
+
module Validators
|
7
|
+
#Validator that tests that a modal is defined when it is called elsewhere through a hook
|
8
|
+
class ValidateModalPresenceOf < Validate
|
9
|
+
# @param args [Hash] arguments for the validation class
|
10
|
+
def initialize(args)
|
11
|
+
@key = args.fetch :key
|
12
|
+
end
|
13
|
+
|
14
|
+
# Validates the composite object and throws errors on failure
|
15
|
+
# @param composite_object [Object] Composite object to be tested.
|
16
|
+
# @return [nil] no return on exceptions on failure
|
17
|
+
def validate(composite_object)
|
18
|
+
#Get the hash value from the composite object
|
19
|
+
target_value = composite_object.hash[@key]
|
20
|
+
target_values = (target_value.is_a?(Array)) ? target_value : [target_value]
|
21
|
+
|
22
|
+
return unless target_value
|
23
|
+
|
24
|
+
valid_modals = self.find_modals(composite_object)
|
25
|
+
|
26
|
+
target_values.each { |modal|
|
27
|
+
modal = modal.to_sym
|
28
|
+
next if valid_modals.include?(modal)
|
29
|
+
|
30
|
+
error_message = "Invalid Modal: #{modal}, at: #{composite_object.location}[#{@key}]."
|
31
|
+
error_message << " Valid Modal(s): #{valid_modals}"
|
32
|
+
self.error_messages.push(error_message)
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
#Traverses up a composite tree to find :modals in a hash
|
37
|
+
# @param composite_object [Object] composite object to traverse up
|
38
|
+
# @return [Array<Symbol>] array of modal names
|
39
|
+
def find_modals(composite_object)
|
40
|
+
#Using the hash instead of the method because lower nodes will get validated
|
41
|
+
#before composite is finished building
|
42
|
+
if composite_object.hash[:modals].is_a?(Hash)
|
43
|
+
return composite_object.hash[:modals].keys #Should be Hash with modal names as the keys
|
44
|
+
elsif composite_object.parent
|
45
|
+
return self.find_modals(composite_object.parent)
|
46
|
+
end
|
47
|
+
|
48
|
+
return []
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative 'validate'
|
2
|
+
|
3
|
+
module AutomationObject
|
4
|
+
module BluePrint
|
5
|
+
module HashAdapter
|
6
|
+
module Validators
|
7
|
+
#Validates tests the a key exists on a composite hash
|
8
|
+
class ValidatePresenceOf < Validate
|
9
|
+
# @param args [Hash] arguments for the validation class
|
10
|
+
def initialize(args)
|
11
|
+
@key = args.fetch :key
|
12
|
+
|
13
|
+
options = args.fetch :args, {}
|
14
|
+
options = (options.is_a?(Hash)) ? options : {}
|
15
|
+
@unless_presence_of = options.fetch :unless_presence_of, nil
|
16
|
+
end
|
17
|
+
|
18
|
+
# Validates the composite object and throws errors on failure
|
19
|
+
# @param composite_object [Object] Composite object to be tested.
|
20
|
+
# @return [nil] no return on exceptions on failure
|
21
|
+
def validate(composite_object)
|
22
|
+
#Get the hash value from the composite object
|
23
|
+
return if composite_object.hash.has_key?(@key)
|
24
|
+
|
25
|
+
#Do unless_presence_of check
|
26
|
+
if @unless_presence_of
|
27
|
+
return if composite_object.hash.has_key?(@unless_presence_of)
|
28
|
+
end
|
29
|
+
|
30
|
+
self.error_messages.push("Required Key Missing: #{@key}, at: #{composite_object.location}.")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_screen_presence_of.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative 'validate'
|
2
|
+
|
3
|
+
module AutomationObject
|
4
|
+
module BluePrint
|
5
|
+
module HashAdapter
|
6
|
+
module Validators
|
7
|
+
#Validator that tests that a screen is defined when it is called elsewhere through a hook
|
8
|
+
class ValidateScreenPresenceOf < Validate
|
9
|
+
# @param args [Hash] arguments for the validation class
|
10
|
+
def initialize(args)
|
11
|
+
@key = args.fetch :key
|
12
|
+
end
|
13
|
+
|
14
|
+
# Validates the composite object and throws errors on failure
|
15
|
+
# @param composite_object [Object] Composite object to be tested.
|
16
|
+
# @return [nil] no return on exceptions on failure
|
17
|
+
def validate(composite_object)
|
18
|
+
#Get the hash value from the composite object
|
19
|
+
target_value = composite_object.hash[@key]
|
20
|
+
|
21
|
+
return unless target_value
|
22
|
+
|
23
|
+
target_values = (target_value.is_a?(Array)) ? target_value : [target_value]
|
24
|
+
|
25
|
+
valid_screens = self.find_screens(composite_object)
|
26
|
+
|
27
|
+
target_values.each { |screen|
|
28
|
+
screen = screen.to_sym
|
29
|
+
next if valid_screens.include?(screen)
|
30
|
+
|
31
|
+
error_message = "Invalid Screen: #{screen}, at: #{composite_object.location}[#{@key}]."
|
32
|
+
error_message << " Valid Screen(s): #{valid_screens}"
|
33
|
+
self.error_messages.push(error_message)
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
#Traverses up a composite tree to find :screens in a hash
|
38
|
+
# @param composite_object [Object] composite object to traverse up
|
39
|
+
# @return [Array<Symbol>] array of screen names
|
40
|
+
def find_screens(composite_object)
|
41
|
+
#Using the hash instead of the method because lower nodes will get validated
|
42
|
+
#before composite is finished building
|
43
|
+
if composite_object.hash[:screens].is_a?(Hash)
|
44
|
+
return composite_object.hash[:screens].keys #Should be Hash with screen names as the keys
|
45
|
+
elsif composite_object.parent
|
46
|
+
return self.find_screens(composite_object.parent)
|
47
|
+
end
|
48
|
+
|
49
|
+
return []
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_view_presence_of.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require_relative 'validate'
|
2
|
+
|
3
|
+
module AutomationObject
|
4
|
+
module BluePrint
|
5
|
+
module HashAdapter
|
6
|
+
module Validators
|
7
|
+
#Validator that tests that a view is defined when it is called elsewhere through a hook
|
8
|
+
class ValidateViewPresenceOf < Validate
|
9
|
+
# @param args [Hash] arguments for the validation class
|
10
|
+
def initialize(args)
|
11
|
+
@key = args.fetch :key
|
12
|
+
end
|
13
|
+
|
14
|
+
# Validates the composite object and throws errors on failure
|
15
|
+
# @param composite_object [Object] Composite object to be tested.
|
16
|
+
# @return [nil] no return on exceptions on failure
|
17
|
+
def validate(composite_object)
|
18
|
+
#Get the hash value from the composite object
|
19
|
+
target_value = composite_object.hash[@key]
|
20
|
+
target_values = (target_value.is_a?(Array)) ? target_value : [target_value]
|
21
|
+
|
22
|
+
return unless target_value
|
23
|
+
|
24
|
+
valid_views = self.find_views(composite_object)
|
25
|
+
|
26
|
+
target_values.each { |view|
|
27
|
+
view = view.to_sym
|
28
|
+
next if valid_views.include?(view)
|
29
|
+
|
30
|
+
error_message = "Invalid View: #{view}, at: #{composite_object.location}[#{@key}]."
|
31
|
+
error_message << " Valid Views(s): #{valid_views}"
|
32
|
+
self.error_messages.push(error_message)
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
#Need to traverse up the composite tree and find views
|
37
|
+
def find_views(composite_object)
|
38
|
+
#Using the hash instead of the method because lower nodes will get validated
|
39
|
+
#before composite is finished building
|
40
|
+
if composite_object.hash[:views].is_a?(Hash)
|
41
|
+
return composite_object.hash[:views].keys #Should be Hash with view names as the keys
|
42
|
+
elsif composite_object.parent
|
43
|
+
return self.find_views(composite_object.parent)
|
44
|
+
end
|
45
|
+
|
46
|
+
return []
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#Require parent class
|
2
|
+
require_relative 'composite'
|
3
|
+
|
4
|
+
require_relative 'hook_action'
|
5
|
+
require_relative 'hook_element_requirements'
|
6
|
+
|
7
|
+
module AutomationObject
|
8
|
+
module BluePrint
|
9
|
+
module HashAdapter
|
10
|
+
#Hook composite
|
11
|
+
class Hook < Composite
|
12
|
+
#Call the live? method so that it creates the needed Array of ElementRequirement interfaces
|
13
|
+
before_create :live?
|
14
|
+
|
15
|
+
#Relationships
|
16
|
+
has_one :before, interface: HookAction
|
17
|
+
has_one :after, interface: HookAction
|
18
|
+
|
19
|
+
#Validations
|
20
|
+
validates_keys allowed_keys: [:before, :live?, :after]
|
21
|
+
|
22
|
+
# @return [Array<HookElementRequirements>] array of element requirements
|
23
|
+
def live?
|
24
|
+
return @live if @live
|
25
|
+
|
26
|
+
children = self.hash[:live?]
|
27
|
+
children = (children.is_a?(Array)) ? children : Array.new
|
28
|
+
|
29
|
+
@live = self.create_array_children(:live, children, {interface: HookElementRequirements, location: self.location + '[live?]'})
|
30
|
+
return @live
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
#Require parent class
|
2
|
+
require_relative 'composite'
|
3
|
+
require_relative 'hook_element_requirements'
|
4
|
+
|
5
|
+
module AutomationObject
|
6
|
+
module BluePrint
|
7
|
+
module HashAdapter
|
8
|
+
#Hook action composite
|
9
|
+
class HookAction < Composite
|
10
|
+
#Call the wait_for_elements method to generate the children
|
11
|
+
before_create :wait_for_elements
|
12
|
+
|
13
|
+
#Validations
|
14
|
+
validates_keys allowed_keys: [:new_screen, :show_modal, :close_screen, :change_screen,
|
15
|
+
:sleep, :wait_for_elements, :change_to_previous_screen, :close_modal, :reset_screen,
|
16
|
+
:possible_screen_changes]
|
17
|
+
|
18
|
+
validates :change_screen, instance_of: [String, Symbol], screen_presence_of: true
|
19
|
+
validates :new_screen, instance_of: [String, Symbol], screen_presence_of: true
|
20
|
+
validates :change_to_previous_screen, instance_of: TrueClass
|
21
|
+
validates :close_modal, instance_of: TrueClass
|
22
|
+
validates :close_screen, instance_of: TrueClass
|
23
|
+
validates :possible_screen_changes, instance_of: String, screen_presence_of: true
|
24
|
+
validates :reset_screen, instance_of: TrueClass
|
25
|
+
validates :show_modal, instance_of: String, modal_presence_of: true
|
26
|
+
validates :sleep, instance_of: Numeric
|
27
|
+
validates :wait_for_elements, instance_of: Array
|
28
|
+
|
29
|
+
#Get the order to run the hook in
|
30
|
+
# @return [Array<Symbol>] list of hook methods to run in given order
|
31
|
+
def hook_order
|
32
|
+
return self.hash.keys
|
33
|
+
end
|
34
|
+
|
35
|
+
#Get length of hook actions
|
36
|
+
# @return [Integer] length of hook actions
|
37
|
+
def length
|
38
|
+
return self.hash.keys.length
|
39
|
+
end
|
40
|
+
|
41
|
+
#See if hook actions are empty
|
42
|
+
# @return [Boolean] if hook actions are empty
|
43
|
+
def empty?
|
44
|
+
return !(self.hash.keys.length > 0)
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [Symbol, nil] screen to change to
|
48
|
+
def change_screen
|
49
|
+
change_screen = self.hash[:change_screen]
|
50
|
+
|
51
|
+
case change_screen
|
52
|
+
when Symbol, String
|
53
|
+
return change_screen.to_sym
|
54
|
+
else
|
55
|
+
return nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# @return [Symbol, nil] new screen
|
60
|
+
def new_screen
|
61
|
+
new_screen = self.hash[:new_screen]
|
62
|
+
|
63
|
+
case new_screen
|
64
|
+
when Symbol, String
|
65
|
+
return new_screen.to_sym
|
66
|
+
else
|
67
|
+
return nil
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# @return [Boolean]
|
72
|
+
def close_screen
|
73
|
+
return self.hash[:close_screen] ||= false
|
74
|
+
end
|
75
|
+
|
76
|
+
# @return [Boolean]
|
77
|
+
def close_modal
|
78
|
+
return self.hash[:close_modal] ||= false
|
79
|
+
end
|
80
|
+
|
81
|
+
# @return [Boolean]
|
82
|
+
def change_to_previous_screen
|
83
|
+
return self.hash[:change_to_previous_screen] ||= false
|
84
|
+
end
|
85
|
+
|
86
|
+
# @return [Symbol, nil]
|
87
|
+
def show_modal
|
88
|
+
show_modal = self.hash[:show_modal]
|
89
|
+
|
90
|
+
case show_modal
|
91
|
+
when Symbol, String
|
92
|
+
return show_modal.to_sym
|
93
|
+
else
|
94
|
+
return nil
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# @return [Array]
|
99
|
+
def possible_screen_changes
|
100
|
+
if self.hash[:possible_screen_changes].is_a?(Array)
|
101
|
+
return self.hash[:possible_screen_changes].map { |value| value.to_sym }
|
102
|
+
else
|
103
|
+
return Array.new
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
#@return [Boolean] reset the screen?
|
108
|
+
def reset_screen
|
109
|
+
return self.hash[:reset_screen] ||= false
|
110
|
+
end
|
111
|
+
|
112
|
+
#@return [Numeric] amount of time to sleep
|
113
|
+
def sleep
|
114
|
+
return self.hash[:sleep] ||= 0
|
115
|
+
end
|
116
|
+
|
117
|
+
#Custom method for array of children instead of Hash
|
118
|
+
# @return [Array<HookElementRequirements>] array of wait for element children
|
119
|
+
def wait_for_elements
|
120
|
+
return @wait_for_elements if @wait_for_elements
|
121
|
+
wait_for_elements = self.hash[:wait_for_elements]
|
122
|
+
|
123
|
+
children = (wait_for_elements.is_a?(Array)) ? wait_for_elements : Array.new
|
124
|
+
@wait_for_elements = self.create_array_children(:wait_for_elements, children,
|
125
|
+
{interface: HookElementRequirements,
|
126
|
+
location: self.location + '[wait_for_elements]'
|
127
|
+
})
|
128
|
+
|
129
|
+
return @wait_for_elements
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#Require parent class
|
2
|
+
require_relative 'composite'
|
3
|
+
|
4
|
+
module AutomationObject
|
5
|
+
module BluePrint
|
6
|
+
module HashAdapter
|
7
|
+
#Hook Element Requirements-level composite
|
8
|
+
class HookElementRequirements < Composite
|
9
|
+
#Valdiations
|
10
|
+
validates :element_name, presence_of: true, instance_of: [String, Symbol], element_presence_of: true
|
11
|
+
validates :exists?, presence_of: true, instance_of: [FalseClass, TrueClass]
|
12
|
+
|
13
|
+
#Get the order to run the hook in
|
14
|
+
# @return [Array<Symbol>] list of hook methods to run in given order
|
15
|
+
def hook_order
|
16
|
+
hook_order = [:exists?] #Always put exists? first
|
17
|
+
|
18
|
+
self.hash.keys.each { |hook_name|
|
19
|
+
hook_order.push(hook_name) unless [:element_name, :exists?].include?(hook_name)
|
20
|
+
}
|
21
|
+
|
22
|
+
return hook_order
|
23
|
+
end
|
24
|
+
|
25
|
+
#Get element requirement
|
26
|
+
# @param name [Symbol] name of requested requirement
|
27
|
+
def requirement(name)
|
28
|
+
return self.hash[name] ||= nil
|
29
|
+
end
|
30
|
+
|
31
|
+
#Get name of the element
|
32
|
+
# @return [Symbol] name of element
|
33
|
+
def element_name
|
34
|
+
element_name = self.hash[:element_name]
|
35
|
+
|
36
|
+
case element_name
|
37
|
+
when Symbol, String
|
38
|
+
return element_name.to_sym
|
39
|
+
else
|
40
|
+
return nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
#Convience for getting element blueprints
|
45
|
+
# @return [AutomationObject::BluePrint::HashAdapter::Element]
|
46
|
+
def element_blueprints(composite_object = nil)
|
47
|
+
unless composite_object
|
48
|
+
composite_object = self
|
49
|
+
end
|
50
|
+
|
51
|
+
#Traverse!
|
52
|
+
if composite_object.hash[:elements].is_a?(Hash)
|
53
|
+
|
54
|
+
return composite_object.elements[self.element_name]
|
55
|
+
elsif composite_object.parent
|
56
|
+
return self.element_blueprints(composite_object.parent)
|
57
|
+
end
|
58
|
+
|
59
|
+
return nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|