automation_object 0.0.4 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/lib/automation_object.rb +14 -72
  3. data/lib/automation_object/blue_print.rb +37 -100
  4. data/lib/automation_object/blue_print/composite/automatic_onload_modal.rb +28 -0
  5. data/lib/automation_object/blue_print/composite/base.rb +18 -0
  6. data/lib/automation_object/blue_print/composite/custom_method.rb +23 -0
  7. data/lib/automation_object/blue_print/composite/element.rb +20 -0
  8. data/lib/automation_object/blue_print/composite/element_array.rb +21 -0
  9. data/lib/automation_object/blue_print/composite/element_hash.rb +26 -0
  10. data/lib/automation_object/blue_print/composite/helpers/element_helper.rb +33 -0
  11. data/lib/automation_object/blue_print/composite/helpers/multiple_elements_helper.rb +18 -0
  12. data/lib/automation_object/blue_print/composite/hook.rb +31 -0
  13. data/lib/automation_object/blue_print/composite/hook_action.rb +84 -0
  14. data/lib/automation_object/blue_print/composite/hook_element_requirements.rb +39 -0
  15. data/lib/automation_object/blue_print/composite/modal.rb +56 -0
  16. data/lib/automation_object/blue_print/composite/screen.rb +61 -0
  17. data/lib/automation_object/blue_print/composite/top.rb +51 -0
  18. data/lib/automation_object/blue_print/composite/view.rb +48 -0
  19. data/lib/automation_object/blue_print/hash_adapter.rb +17 -0
  20. data/lib/automation_object/blue_print/hash_adapter/automatic_onload_modal.rb +35 -0
  21. data/lib/automation_object/blue_print/hash_adapter/composite.rb +93 -0
  22. data/lib/automation_object/blue_print/hash_adapter/custom_method.rb +30 -0
  23. data/lib/automation_object/blue_print/hash_adapter/element.rb +34 -0
  24. data/lib/automation_object/blue_print/hash_adapter/element_array.rb +36 -0
  25. data/lib/automation_object/blue_print/hash_adapter/element_hash.rb +43 -0
  26. data/lib/automation_object/blue_print/hash_adapter/helpers/element_helper.rb +59 -0
  27. data/lib/automation_object/blue_print/hash_adapter/helpers/multiple_elements_helper.rb +35 -0
  28. data/lib/automation_object/blue_print/hash_adapter/helpers/validation_error.rb +26 -0
  29. data/lib/automation_object/blue_print/hash_adapter/helpers/validation_helper.rb +99 -0
  30. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate.rb +23 -0
  31. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_allowed_keys.rb +31 -0
  32. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_element_presence_of.rb +55 -0
  33. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_instance_of.rb +39 -0
  34. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_modal_presence_of.rb +54 -0
  35. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_presence_of.rb +36 -0
  36. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_screen_presence_of.rb +55 -0
  37. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_view_presence_of.rb +52 -0
  38. data/lib/automation_object/blue_print/hash_adapter/hook.rb +35 -0
  39. data/lib/automation_object/blue_print/hash_adapter/hook_action.rb +134 -0
  40. data/lib/automation_object/blue_print/hash_adapter/hook_element_requirements.rb +64 -0
  41. data/lib/automation_object/blue_print/hash_adapter/modal.rb +52 -0
  42. data/lib/automation_object/blue_print/hash_adapter/screen.rb +91 -0
  43. data/lib/automation_object/blue_print/hash_adapter/top.rb +63 -0
  44. data/lib/automation_object/blue_print/hash_adapter/view.rb +29 -0
  45. data/lib/automation_object/blue_print/helpers/file_helper.rb +38 -0
  46. data/lib/automation_object/blue_print/yaml_adapter.rb +50 -0
  47. data/lib/automation_object/driver.rb +44 -0
  48. data/lib/automation_object/driver/appium_adapter/driver.rb +150 -0
  49. data/lib/automation_object/driver/appium_adapter/element.rb +118 -0
  50. data/lib/automation_object/driver/base.rb +11 -0
  51. data/lib/automation_object/driver/driver.rb +69 -245
  52. data/lib/automation_object/driver/element.rb +51 -210
  53. data/lib/automation_object/driver/helpers/selenium_driver_helper.rb +41 -0
  54. data/lib/automation_object/driver/helpers/selenium_element_helper.rb +138 -0
  55. data/lib/automation_object/driver/nokogiri_adapter/backup/driver.rb +83 -0
  56. data/lib/automation_object/driver/nokogiri_adapter/backup/element.rb +66 -0
  57. data/lib/automation_object/driver/nokogiri_adapter/backup/form.rb +29 -0
  58. data/lib/automation_object/driver/nokogiri_adapter/backup/helpers/driver_element_helper.rb +52 -0
  59. data/lib/automation_object/driver/nokogiri_adapter/backup/session.rb +115 -0
  60. data/lib/automation_object/driver/nokogiri_adapter/driver.rb +104 -0
  61. data/lib/automation_object/driver/nokogiri_adapter/element.rb +85 -0
  62. data/lib/automation_object/driver/nokogiri_adapter/error.rb +17 -0
  63. data/lib/automation_object/driver/selenium_adapter/driver.rb +143 -0
  64. data/lib/automation_object/driver/selenium_adapter/element.rb +116 -0
  65. data/lib/automation_object/dsl.rb +33 -0
  66. data/lib/automation_object/dsl/blue_print_adapter.rb +16 -0
  67. data/lib/automation_object/dsl/blue_print_adapter/composite.rb +54 -0
  68. data/lib/automation_object/dsl/blue_print_adapter/element.rb +14 -0
  69. data/lib/automation_object/dsl/blue_print_adapter/element_array.rb +14 -0
  70. data/lib/automation_object/dsl/blue_print_adapter/element_hash.rb +14 -0
  71. data/lib/automation_object/dsl/blue_print_adapter/modal.rb +23 -0
  72. data/lib/automation_object/dsl/blue_print_adapter/screen.rb +26 -0
  73. data/lib/automation_object/dsl/blue_print_adapter/top.rb +19 -0
  74. data/lib/automation_object/dsl/models.rb +18 -0
  75. data/lib/automation_object/dsl/proxies/element.rb +16 -0
  76. data/lib/automation_object/dsl/proxies/element_array.rb +16 -0
  77. data/lib/automation_object/dsl/proxies/element_hash.rb +16 -0
  78. data/lib/automation_object/dsl/proxies/helpers/composite_helper.rb +74 -0
  79. data/lib/automation_object/dsl/proxies/modal.rb +17 -0
  80. data/lib/automation_object/dsl/proxies/screen.rb +17 -0
  81. data/lib/automation_object/dsl/proxies/top.rb +17 -0
  82. data/lib/automation_object/framework.rb +79 -386
  83. data/lib/automation_object/helpers/composite.rb +95 -0
  84. data/lib/automation_object/helpers/composite_hook.rb +46 -0
  85. data/lib/automation_object/helpers/hash.rb +15 -0
  86. data/lib/automation_object/helpers/reflection_helper.rb +28 -0
  87. data/lib/automation_object/helpers/string.rb +27 -0
  88. data/lib/automation_object/proxies/mutex_proxy.rb +63 -0
  89. data/lib/automation_object/proxies/proxy.rb +20 -0
  90. data/lib/automation_object/proxies/throttle_proxy.rb +57 -0
  91. data/lib/automation_object/state.rb +37 -0
  92. data/lib/automation_object/state/blue_print_adapter.rb +16 -0
  93. data/lib/automation_object/state/blue_print_adapter/composite.rb +65 -0
  94. data/lib/automation_object/state/blue_print_adapter/element.rb +20 -0
  95. data/lib/automation_object/state/blue_print_adapter/element_array.rb +25 -0
  96. data/lib/automation_object/state/blue_print_adapter/element_hash.rb +31 -0
  97. data/lib/automation_object/state/blue_print_adapter/element_proxy.rb +28 -0
  98. data/lib/automation_object/state/blue_print_adapter/helpers/element_helper.rb +31 -0
  99. data/lib/automation_object/state/blue_print_adapter/helpers/screen_manager.rb +137 -0
  100. data/lib/automation_object/state/blue_print_adapter/helpers/window.rb +39 -0
  101. data/lib/automation_object/state/blue_print_adapter/hook.rb +56 -0
  102. data/lib/automation_object/state/blue_print_adapter/hook_action.rb +33 -0
  103. data/lib/automation_object/state/blue_print_adapter/hook_actions/action_loop.rb +35 -0
  104. data/lib/automation_object/state/blue_print_adapter/hook_actions/change_screen.rb +26 -0
  105. data/lib/automation_object/state/blue_print_adapter/hook_actions/change_to_previous_screen.rb +21 -0
  106. data/lib/automation_object/state/blue_print_adapter/hook_actions/close_modal.rb +31 -0
  107. data/lib/automation_object/state/blue_print_adapter/hook_actions/close_screen.rb +19 -0
  108. data/lib/automation_object/state/blue_print_adapter/hook_actions/element_requirement.rb +34 -0
  109. data/lib/automation_object/state/blue_print_adapter/hook_actions/new_screen.rb +37 -0
  110. data/lib/automation_object/state/blue_print_adapter/hook_actions/possible_screen_changes.rb +21 -0
  111. data/lib/automation_object/state/blue_print_adapter/hook_actions/reset_screen.rb +18 -0
  112. data/lib/automation_object/state/blue_print_adapter/hook_actions/show_modal.rb +26 -0
  113. data/lib/automation_object/state/blue_print_adapter/hook_actions/sleep.rb +18 -0
  114. data/lib/automation_object/state/blue_print_adapter/hook_actions/wait_for_elements.rb +20 -0
  115. data/lib/automation_object/state/blue_print_adapter/modal.rb +26 -0
  116. data/lib/automation_object/state/blue_print_adapter/screen.rb +32 -0
  117. data/lib/automation_object/state/blue_print_adapter/top.rb +45 -0
  118. data/lib/automation_object/state/error.rb +24 -0
  119. data/lib/automation_object/state/session.rb +38 -0
  120. data/lib/automation_object/step_definitions.rb +14 -0
  121. data/lib/automation_object/step_definitions/action.rb +21 -0
  122. data/lib/automation_object/step_definitions/cache.rb +23 -0
  123. data/lib/automation_object/step_definitions/element/actions.rb +87 -0
  124. data/lib/automation_object/step_definitions/element/regex.rb +24 -0
  125. data/lib/automation_object/step_definitions/element/steps.rb +67 -0
  126. data/lib/automation_object/step_definitions/parse.rb +39 -0
  127. data/lib/automation_object/version.rb +1 -1
  128. metadata +194 -110
  129. data/lib/automation_object/blue_print_validation/base_validation.rb +0 -44
  130. data/lib/automation_object/blue_print_validation/common_methods.rb +0 -106
  131. data/lib/automation_object/blue_print_validation/element_validation.rb +0 -198
  132. data/lib/automation_object/blue_print_validation/formatted_errors.rb +0 -41
  133. data/lib/automation_object/blue_print_validation/hook_validation.rb +0 -393
  134. data/lib/automation_object/blue_print_validation/key_value_constants.rb +0 -75
  135. data/lib/automation_object/blue_print_validation/modal_validation.rb +0 -37
  136. data/lib/automation_object/blue_print_validation/screen_modal_common_methods.rb +0 -119
  137. data/lib/automation_object/blue_print_validation/screen_validation.rb +0 -21
  138. data/lib/automation_object/blue_print_validation/validation_object.rb +0 -32
  139. data/lib/automation_object/driver/anonymous.rb +0 -27
  140. data/lib/automation_object/element/element.rb +0 -145
  141. data/lib/automation_object/element/element_array.rb +0 -12
  142. data/lib/automation_object/element/element_cell.rb +0 -126
  143. data/lib/automation_object/element/element_group.rb +0 -33
  144. data/lib/automation_object/element/element_hash.rb +0 -25
  145. data/lib/automation_object/element/element_helpers.rb +0 -29
  146. data/lib/automation_object/element/element_methods.rb +0 -134
  147. data/lib/automation_object/element/elements_helpers.rb +0 -204
  148. data/lib/automation_object/framework/events.rb +0 -8
  149. data/lib/automation_object/framework/helpers.rb +0 -101
  150. data/lib/automation_object/framework/print_objects.rb +0 -67
  151. data/lib/automation_object/framework/screen_monitor.rb +0 -55
  152. data/lib/automation_object/framework/screen_routing.rb +0 -310
  153. data/lib/automation_object/framework/window_helpers.rb +0 -181
  154. data/lib/automation_object/hash.rb +0 -6
  155. data/lib/automation_object/hook_helpers.rb +0 -27
  156. data/lib/automation_object/logger.rb +0 -179
  157. data/lib/automation_object/object.rb +0 -22
  158. data/lib/automation_object/screen/modal.rb +0 -8
  159. data/lib/automation_object/screen/screen.rb +0 -209
  160. data/lib/automation_object/screen/screen_hook_helpers.rb +0 -319
  161. data/lib/automation_object/screen/screen_modal_helpers.rb +0 -101
  162. data/lib/automation_object/screen/screen_prompt_helpers.rb +0 -21
  163. data/lib/automation_object/screen/screen_window_helpers.rb +0 -149
@@ -1,44 +0,0 @@
1
- module AutomationObject
2
- module BluePrintValidation
3
- module BaseValidation
4
- def validate_base
5
- error_messages = Array.new
6
-
7
- self.each { |base_key, base_value|
8
- #Check if valid base keys
9
- unless KeyValueConstants::BASE_PAIR_TYPES.keys.include?(base_key)
10
- error_message = "Base level key (#{base_key}) is not a valid key, available base level keys ("
11
- error_message << KeyValueConstants::BASE_PAIR_TYPES.keys.join(', ').to_s + ')'
12
- error_messages.push(FormattedErrors::format_message(error_message))
13
-
14
- next #skip if not a valid key since we are not going to check value
15
- end
16
-
17
- #Skip checking if nil, being nice
18
- next if base_value == nil
19
-
20
- unless base_value.is_a?(KeyValueConstants::BASE_PAIR_TYPES[base_key])
21
- error_message = "Base level key (#{base_key}) has an invalid value type, expecting: ("
22
- error_message << KeyValueConstants::BASE_PAIR_TYPES[base_key].to_s
23
- error_message << "), got: (#{base_value.class.to_s})"
24
- error_messages.push(FormattedErrors::format_message(error_message))
25
-
26
- next #Skip any additional validation on this
27
- end
28
-
29
- case base_key
30
- when 'default_screen'
31
- unless self.screen_exists?(self[base_key])
32
- error_message = "(#{base_key}) value has screen that does not exist (#{self[base_key]}), available screens ("
33
- error_message << self.get_screens.join(', ').to_s
34
- error_message << ')'
35
- error_messages.push(FormattedErrors::format_message(error_message))
36
- end
37
- end
38
- }
39
-
40
- return error_messages
41
- end
42
- end
43
- end
44
- end
@@ -1,106 +0,0 @@
1
- module AutomationObject
2
- module BluePrintValidation
3
- module CommonMethods
4
- def get_screens
5
- screens = Array.new
6
- return screens unless self.has_key?('screens')
7
- return screens unless self['screens'].class == Hash
8
-
9
- screens = self['screens'].keys
10
- return screens
11
- end
12
-
13
- def screen_exists?(screen_name)
14
- return self.get_screens.include?(screen_name)
15
- end
16
-
17
- def view_has_modal?(view_name, modal_name)
18
- return false unless self.view_exists?(view_name)
19
-
20
- view_configuration = self['views'][view_name]
21
- return self.get_modals(view_configuration).include?(modal_name)
22
- end
23
-
24
- def get_view_modals(view_name)
25
- modals = Array.new
26
- return modals unless self.has_key?('views')
27
- return modals unless self['views'].class == Hash
28
- return modals unless self['views'].has_key?(view_name)
29
-
30
- view_configuration = self['views'][view_name]
31
- return self.get_modals(view_configuration)
32
- end
33
-
34
- def screen_has_modal?(screen_name, modal_name)
35
- return false unless self.screen_exists?(screen_name)
36
-
37
- screen_configuration = self['screens'][screen_name]
38
- return self.get_modals(screen_configuration).include?(modal_name)
39
- end
40
-
41
- def get_screen_modals(screen_name)
42
- modals = Array.new
43
- return modals unless self.has_key?('screens')
44
- return modals unless self['screens'].class == Hash
45
- return modals unless self['screens'].has_key?(screen_name)
46
-
47
- screen_configuration = self['screens'][screen_name]
48
- return self.get_modals(screen_configuration)
49
- end
50
-
51
- def get_modals(configuration)
52
- modals = Array.new
53
-
54
- return modals unless configuration.class == Hash
55
- return modals unless configuration.has_key?('modals')
56
- return modals unless configuration['modals'].class == Hash
57
-
58
- modals = configuration['modals'].keys
59
- return modals
60
- end
61
-
62
- def screen_has_live?(screen_name)
63
- return false unless self.screen_exists?(screen_name)
64
-
65
- screen_configuration = self['screens'][screen_name]
66
- return false unless screen_configuration.class == Hash
67
-
68
- if screen_configuration.has_key?('live?')
69
- return true if screen_configuration['live?'].class == Hash
70
- return false
71
- end
72
-
73
- #Check if has views
74
- return false unless screen_configuration.has_key?('included_views')
75
- return false unless screen_configuration['included_views'].class == Array
76
-
77
- #No need to check if views doesn't exit
78
- return false unless self.has_key?('views')
79
- return false unless self['views'].class == Hash
80
-
81
- screen_configuration['included_views'].each { |included_view|
82
- return false unless self['views'].has_key?(included_view)
83
- return false unless self['views'][included_view].class == Hash
84
-
85
- view_configuration = self['views'][included_view]
86
- return true if view_configuration.has_key?('live?') and view_configuration['live?'].class == Hash
87
- }
88
-
89
- return false
90
- end
91
-
92
- def view_exists?(view_name)
93
- return self.get_views.include?(view_name)
94
- end
95
-
96
- def get_views
97
- views = Array.new
98
- return views unless self.has_key?('views')
99
- return views unless self['views'].class == Hash
100
-
101
- views = self['views'].keys
102
- return views
103
- end
104
- end
105
- end
106
- end
@@ -1,198 +0,0 @@
1
- module AutomationObject
2
- module BluePrintValidation
3
- module ElementValidation
4
- def validate_elements
5
- error_messages = Array.new
6
-
7
- elements = self.get_elements
8
-
9
- elements.each { |element|
10
- #Set level string and get it out of the way
11
- level_key_string = ''
12
- if element[:view_name]
13
- level_key_string = "(views/#{element[:view_name]}/elements)"
14
- elsif element[:modal_name]
15
- level_key_string = "(screens/#{element[:screen_name]}/modals/#{element[:modal_name]}/elements)"
16
- else
17
- level_key_string = "(screens/#{element[:screen_name]}/elements)"
18
- end
19
-
20
- unless element[:element_name].is_a?(String)
21
- error_message = "#{level_key_string} level key (#{element[:element_name]}) is an invalid key type, expecting: ("
22
- error_message << String.to_s
23
- error_message << "), got: (#{element[:element_name].class.to_s})"
24
- error_messages.push(FormattedErrors::format_message(error_message))
25
- end
26
-
27
- #Skip checking if nil, being nice
28
- next if element[:configuration] == nil
29
-
30
- unless element[:configuration].is_a?(Hash)
31
- error_message = "#{level_key_string} level key (#{element[:element_name]}) is an invalid value type, expecting: ("
32
- error_message << Hash.to_s
33
- error_message << "), got: (#{element[:configuration].class.to_s})"
34
- error_messages.push(FormattedErrors::format_message(error_message))
35
-
36
- next #Skip any additional validation on this
37
- end
38
-
39
- element[:configuration].each { |sub_element_key, sub_element_value|
40
- #Check if valid element keys
41
- unless KeyValueConstants::ELEMENT_PAIR_TYPES.keys.include?(sub_element_key)
42
- error_message = "#{level_key_string} level key (#{element[:element_name]}) sub key (#{sub_element_key}) "
43
- error_message << 'is not a valid key, available (elements) sub level keys ('
44
- error_message << KeyValueConstants::ELEMENT_PAIR_TYPES.keys.join(', ').to_s + ')'
45
- error_messages.push(FormattedErrors::format_message(error_message))
46
-
47
- next #skip if not a valid key since we are not going to check value
48
- end
49
-
50
- #Skip checking if nil, being nice
51
- next if sub_element_value == nil
52
-
53
- #Check sub element value
54
- unless sub_element_value.is_a?(KeyValueConstants::ELEMENT_PAIR_TYPES[sub_element_key])
55
- error_message = "#{level_key_string} level key (#{element[:element_name]}) sub key (#{sub_element_key}) "
56
- error_message << 'has an invalid value type, expected: ('
57
- error_message << KeyValueConstants::SCREEN_PAIR_TYPES[sub_element_key].to_s
58
- error_message << "), got: (#{sub_element_value.class.to_s})"
59
- error_messages.push(FormattedErrors::format_message(error_message))
60
-
61
- next #Skip any additional validation on this
62
- end
63
-
64
- case sub_element_key
65
- when 'define_elements_by'
66
- valid_element_methods = KeyValueConstants::ELEMENT_KEYS + self.get_element_custom_methods(element[:configuration])
67
-
68
- unless valid_element_methods.include?(sub_element_value)
69
- error_message = "#{level_key_string} level key (#{element[:element_name]}) sub key (#{sub_element_key}) "
70
- error_message << 'is not a valid element methods key. Available keys ('
71
- error_message << valid_element_methods.join(', ')
72
- error_message << ')'
73
- error_messages.push(FormattedErrors::format_message(error_message))
74
- end
75
- when 'custom_methods'
76
- sub_element_value.each { |custom_method_name, custom_method_configuration|
77
- unless custom_method_name.is_a?(String)
78
- error_message = "#{level_key_string} level key (#{element[:element_name]}) custom_methods sub key (#{custom_method_name}) "
79
- error_message << 'is not a valid key type, expected: ('
80
- error_message << String.to_s
81
- error_message << "), got: (#{custom_method_name.class.to_s})"
82
- error_messages.push(FormattedErrors::format_message(error_message))
83
- end
84
-
85
- unless custom_method_configuration.is_a?(Hash)
86
- error_message = "#{level_key_string} level key (#{element[:element_name]}) custom_methods sub key (#{custom_method_name}) "
87
- error_message << 'is not a valid key value type, expected: ('
88
- error_message << Hash.to_s
89
- error_message << "), got: (#{custom_method_configuration.class.to_s})"
90
- error_messages.push(FormattedErrors::format_message(error_message))
91
-
92
- next
93
- end
94
-
95
- custom_method_configuration.each { |custom_method_key, custom_method_value|
96
- unless KeyValueConstants::ELEMENT_CUSTOM_METHOD_PAIR_TYPES.keys.include?(custom_method_key)
97
- error_message = "#{level_key_string} level key (#{element[:element_name]}) custom_methods (#{custom_method_name}) method sub key (#{custom_method_key}) "
98
- error_message << 'is not a valid key, available (custom_methods) sub level keys ('
99
- error_message << KeyValueConstants::ELEMENT_CUSTOM_METHOD_PAIR_TYPES.keys.join(', ').to_s + ')'
100
- error_messages.push(FormattedErrors::format_message(error_message))
101
-
102
- next #skip if not a valid key since we are not going to check value
103
- end
104
-
105
- #Skip checking if nil, being nice
106
- next if custom_method_value == nil
107
-
108
- unless custom_method_value.is_a?(KeyValueConstants::ELEMENT_CUSTOM_METHOD_PAIR_TYPES[custom_method_key])
109
- error_message = "#{level_key_string} level key (#{element[:element_name]}) custom_methods (#{custom_method_name}) method sub key (#{custom_method_key}) "
110
- error_message << 'has an invalid value type, expected: ('
111
- error_message << KeyValueConstants::ELEMENT_CUSTOM_METHOD_PAIR_TYPES[custom_method_key].to_s
112
- error_message << "), got: (#{custom_method_value.class.to_s})"
113
- error_messages.push(FormattedErrors::format_message(error_message))
114
-
115
- next #Skip any additional validation on this
116
- end
117
-
118
- case custom_method_key
119
- when 'element_method'
120
- unless KeyValueConstants::ELEMENT_KEYS.include?(custom_method_value)
121
- error_message = "#{level_key_string} level key (#{element[:element_name]}) custom_methods (#{custom_method_name}) sub key (#{custom_method_key}) "
122
- error_message << 'is not a valid elements method. Available element methods ('
123
- error_message << KeyValueConstants::ELEMENT_KEYS.join(', ')
124
- error_messages.push(FormattedErrors::format_message(error_message))
125
- end
126
- end
127
- }
128
- }
129
- end
130
- }
131
- }
132
-
133
- return error_messages
134
- end
135
-
136
- def get_element_custom_methods(configuration)
137
- custom_methods = Array.new
138
- return custom_methods unless configuration.class == Hash
139
- return custom_methods unless configuration.has_key?('custom_methods')
140
- return custom_methods unless configuration['custom_methods'].class == Hash
141
-
142
- custom_methods = configuration['custom_methods'].keys
143
- return custom_methods
144
- end
145
-
146
- def get_elements
147
- elements = Array.new
148
-
149
- if self.has_key?('views') and self['views'].class == Hash
150
- self['views'].each { |view_name, view_configuration|
151
- next unless view_configuration.class == Hash
152
- next unless view_configuration.has_key?('elements')
153
- next unless view_configuration['elements'].class == Hash
154
-
155
- view_configuration['elements'].each { |view_element_name, view_element_configuration|
156
- element = {:view_name => view_name, :element_name => view_element_name,
157
- :configuration => view_element_configuration}
158
- elements.push(element)
159
- }
160
- }
161
- end
162
-
163
- if self.has_key?('screens') and self['screens'].class == Hash
164
- self['screens'].each { |screen_name, screen_configuration|
165
- next unless screen_configuration.class == Hash
166
-
167
- if screen_configuration.has_key?('elements') and screen_configuration['elements'].class == Hash
168
- screen_configuration['elements'].each { |screen_element_name, screen_element_configuration|
169
- element = {:screen_name => screen_name, :element_name => screen_element_name,
170
- :configuration => screen_element_configuration}
171
- elements.push(element)
172
- }
173
- end
174
-
175
- #Get elements from modals
176
- next unless screen_configuration.class == Hash
177
- next unless screen_configuration.has_key?('modals')
178
- next unless screen_configuration['modals'].class == Hash
179
-
180
- screen_configuration['modals'].each { |modal_name, modal_configuration|
181
- next unless modal_configuration.class == Hash
182
- next unless modal_configuration.has_key?('elements')
183
- next unless modal_configuration['elements'].class == Hash
184
-
185
- modal_configuration['elements'].each { |modal_element_name, modal_element_configuration|
186
- element = {:screen_name => screen_name, :modal_name => modal_name,
187
- :element_name => modal_element_name, :configuration => modal_element_configuration}
188
- elements.push(element)
189
- }
190
- }
191
- }
192
- end
193
-
194
- return elements
195
- end
196
- end
197
- end
198
- end
@@ -1,41 +0,0 @@
1
- module AutomationObject
2
- module BluePrintValidation
3
- class FormattedErrors
4
- MESSAGE_COLOR = :red
5
- SPECIFIC_VALUE_COLOR = :blue
6
-
7
- def self.array_to_message(error_messages)
8
- error_messages.each_with_index { |raw_message, index|
9
- error_messages[index] = (((index+1).to_s + '. ').colorize(MESSAGE_COLOR) + raw_message)
10
- error_messages[index] = "\n" + error_messages[index] if index == 0
11
- }
12
-
13
- formatted_message = error_messages.join("\n ----- \n")
14
- formatted_message << "\n ----- \n"
15
- return formatted_message
16
- end
17
-
18
- def self.format_message(error_message)
19
- specific_values = error_message.scan(/\([^\)]+\)/)
20
- replaced_string = error_message.gsub(/\([^\)]+\)/, '######')
21
- message_array = replaced_string.split('######')
22
-
23
- return error_message.colorize(MESSAGE_COLOR) if specific_values.length == 0
24
-
25
- formatted_message = ''
26
- message_array.each_with_index { |message, index|
27
- formatted_message << message.colorize(MESSAGE_COLOR)
28
-
29
- next if specific_values[index] == nil
30
- stripped_specific_value = specific_values[index].gsub(/\(/, '').gsub(/\)/, '')
31
- final_specific_value = '('.colorize(MESSAGE_COLOR)
32
- final_specific_value << stripped_specific_value.colorize(SPECIFIC_VALUE_COLOR)
33
- final_specific_value << ')'.colorize(MESSAGE_COLOR)
34
- formatted_message << final_specific_value
35
- }
36
-
37
- return formatted_message
38
- end
39
- end
40
- end
41
- end
@@ -1,393 +0,0 @@
1
- module AutomationObject
2
- module BluePrintValidation
3
- module HookValidation
4
- def validate_hooks
5
- error_messages = Array.new
6
-
7
- hooks = self.get_hooks
8
- hooks.each { |hook|
9
- #Set level string and get it out of the way
10
- level_key_string = self.get_hook_level(hook)
11
-
12
- #Skip checking if nil, being nice
13
- next if hook[:configuration] == nil
14
-
15
- unless hook[:configuration].is_a?(Hash)
16
- error_message = "(#{level_key_string}) hook key (#{hook[:hook_name]}) is an invalid value type, expecting: ("
17
- error_message << Hash.to_s
18
- error_message << "), got: (#{hook[:configuration].class.to_s})"
19
- error_messages.push(FormattedErrors::format_message(error_message))
20
-
21
- next #Skip any additional validation on this
22
- end
23
-
24
- #before_load has no sub actions so go straight to validate_hook_action and skip this validation
25
- if hook[:hook_name] == 'before_load'
26
- error_messages += self.validate_hook_action(hook, hook[:hook_name], hook[:configuration])
27
- next
28
- end
29
-
30
- hook[:configuration].each { |hook_action, hook_action_configuration|
31
- #Check if valid element keys
32
- hook_pair_types = KeyValueConstants::HOOK_PAIR_TYPES.clone
33
- hook_pair_types.delete('elements') unless hook[:hook_name] == 'live?'
34
-
35
- unless hook_pair_types.keys.include?(hook_action)
36
- error_message = "(#{level_key_string}) level key (#{hook[:hook_name]}) sub key (#{hook_action}) "
37
- error_message << 'is not a valid key, available hook sub level keys ('
38
- error_message << hook_pair_types.keys.join(', ').to_s + ')'
39
- error_messages.push(FormattedErrors::format_message(error_message))
40
-
41
- next #skip if not a valid key since we are not going to check value
42
- end
43
-
44
- #Skip checking if nil, being nice
45
- next if hook_action_configuration == nil
46
-
47
- #Check sub element value
48
- unless hook_action_configuration.is_a?(KeyValueConstants::HOOK_PAIR_TYPES[hook_action])
49
- error_message = "(#{level_key_string}) level key (#{hook[:hook_name]}) sub key (#{hook_action}) "
50
- error_message << 'has an invalid value type, expected: ('
51
- error_message << KeyValueConstants::HOOK_PAIR_TYPES[hook_action].to_s
52
- error_message << "), got: (#{hook_action_configuration.class.to_s})"
53
- error_messages.push(FormattedErrors::format_message(error_message))
54
-
55
- next #Skip any additional validation on this
56
- end
57
-
58
- error_messages += self.validate_hook_action(hook, hook_action, hook_action_configuration)
59
- }
60
- }
61
-
62
- return error_messages
63
- end
64
-
65
- def validate_hook_action(hook, action, hook_action_configuration)
66
- error_messages = Array.new
67
- return error_messages if hook_action_configuration == nil #Being nice
68
-
69
- level_key_string = self.get_hook_level(hook, action)
70
-
71
- #Skip if elements action and use validate_elements_hook
72
- if action == 'elements'
73
- return self.validate_elements_hook(hook, action, hook_action_configuration)
74
- end
75
-
76
- unless hook_action_configuration.is_a?(Hash)
77
- error_message = "(#{level_key_string}) hook action is an invalid value type, expecting: ("
78
- error_message << Hash.to_s
79
- error_message << "), got: (#{hook_action_configuration.class.to_s})"
80
- error_messages.push(FormattedErrors::format_message(error_message))
81
-
82
- return error_messages #Skip any additional validation on this
83
- end
84
-
85
- hook_action_configuration.each { |sub_action_key, sub_action_value|
86
- #Check if valid sub hook action keys
87
- unless KeyValueConstants::HOOK_ACTION_PAIR_TYPES.keys.include?(sub_action_key)
88
- error_message = "(#{level_key_string}) level sub key (#{sub_action_key}) "
89
- error_message << 'is not a valid key, available (hook action) sub level keys ('
90
- error_message << KeyValueConstants::HOOK_ACTION_PAIR_TYPES.keys.join(', ').to_s + ')'
91
- error_messages.push(FormattedErrors::format_message(error_message))
92
-
93
- next #skip if not a valid key since we are not going to check value
94
- end
95
-
96
- #Skip checking if nil, being nice
97
- next if sub_action_value == nil
98
-
99
- #Check sub hook action value
100
- unless sub_action_value.is_a?(KeyValueConstants::HOOK_ACTION_PAIR_TYPES[sub_action_key])
101
- error_message = "(#{level_key_string}) level sub key (#{sub_action_key}) "
102
- error_message << 'has an invalid value type, expected: ('
103
- error_message << KeyValueConstants::HOOK_ACTION_PAIR_TYPES[sub_action_key].to_s
104
- error_message << "), got: (#{sub_action_key.class.to_s})"
105
- error_messages.push(FormattedErrors::format_message(error_message))
106
-
107
- next #Skip any additional validation on this
108
- end
109
-
110
- #wait_for_elements test with validate_elements_hook, same set up as live?/elements
111
- if sub_action_key == 'wait_for_elements'
112
- error_messages += self.validate_elements_hook(hook, action, sub_action_key, sub_action_value)
113
- next
114
- end
115
-
116
- case sub_action_key
117
- when 'show_modal'
118
- if hook[:view_name]
119
- modal_exists = self.view_has_modal?(hook[:view_name], sub_action_value)
120
- else
121
- modal_exists = self.screen_has_modal?(hook[:screen_name], sub_action_value)
122
- end
123
-
124
- unless modal_exists
125
- error_message = "(#{level_key_string}) level sub key (#{sub_action_key}) value (#{sub_action_value}) "
126
- error_message << 'modal does not exist in '
127
-
128
- if hook[:view_name]
129
- error_message << "view (#{hook[:view_name]}), available modals ("
130
- error_message << self.get_view_modals(hook[:view_name]).join(', ')
131
- error_message << ')'
132
- else
133
- error_message << "screen (#{hook[:screen_name]}), available modals ("
134
- error_message << self.get_screen_modals(hook[:screen_name]).join(', ')
135
- error_message << ')'
136
- end
137
-
138
- error_messages.push(FormattedErrors::format_message(error_message))
139
- end
140
- when 'change_screen'
141
- unless self.screen_exists?(sub_action_value)
142
- error_message = "(#{level_key_string}/#{sub_action_key}) value (#{sub_action_value}) is not a defined screen. Available screens ("
143
- error_message << self.get_screens.join(', ')
144
- error_message << ')'
145
- error_messages.push(FormattedErrors::format_message(error_message))
146
- end
147
- end
148
- }
149
-
150
- return error_messages
151
- end
152
-
153
- def validate_elements_hook(hook, action, sub_action_key = false, hook_action_configuration)
154
- error_messages = Array.new
155
- return error_messages if hook_action_configuration == nil
156
-
157
- if action == 'before_load'
158
- action = "#{sub_action_key}" if sub_action_key.is_a?(String)
159
- else
160
- action = action + "/#{sub_action_key}" if sub_action_key.is_a?(String)
161
- end
162
-
163
- level_key_string = self.get_hook_level(hook, action)
164
-
165
- unless hook_action_configuration.is_a?(Array)
166
- error_message = "(#{level_key_string}) level key is an invalid value type, expecting: ("
167
- error_message << Array.to_s
168
- error_message << "), got: (#{hook_action_configuration.class.to_s})"
169
- error_messages.push(FormattedErrors::format_message(error_message))
170
-
171
- return error_messages #Skip any further validation
172
- end
173
-
174
- hook_action_configuration.each_with_index { |element_hash, index|
175
- unless element_hash.is_a?(Hash)
176
- error_message = "(#{level_key_string}/#{index.to_s}) level key is an invalid value type, expecting: ("
177
- error_message << Hash.to_s
178
- error_message << "), got: (#{element_hash.class.to_s})"
179
- error_messages.push(FormattedErrors::format_message(error_message))
180
-
181
- next #Skip any additional validation on this
182
- end
183
-
184
- unless element_hash.has_key?('element_name')
185
- error_message = "(#{level_key_string}/#{index.to_s}) level key Hash requires the element_name key"
186
- error_message << Hash.to_s
187
- error_message << "), got: (#{element_hash.class.to_s})"
188
- error_messages.push(FormattedErrors::format_message(error_message))
189
- end
190
-
191
- acceptable_keys = KeyValueConstants::ELEMENT_KEYS + ['element_name']
192
- acceptable_keys += self.get_element_custom_methods_via_hook(hook, element_hash['element_name'])
193
- element_hash.each { |sub_element_key, sub_element_value|
194
- unless acceptable_keys.include?(sub_element_key)
195
- error_message = "(#{level_key_string}/#{index.to_s}) level sub key (#{sub_element_key}) "
196
- error_message << 'is not a valid key, available sub level keys ('
197
- error_message << acceptable_keys.join(', ').to_s + ')'
198
- error_messages.push(FormattedErrors::format_message(error_message))
199
-
200
- next #skip if not a valid key since we are not going to check value
201
- end
202
- }
203
- }
204
-
205
- return error_messages
206
- end
207
-
208
- def get_element_custom_methods_via_hook(hook, element_name)
209
- custom_methods = Array.new
210
-
211
- if hook[:screen_name]
212
- return custom_methods unless self.has_key?('screens')
213
- return custom_methods unless self['screens'].class == Hash
214
- return custom_methods unless self['screens'].has_key?(hook[:screen_name])
215
-
216
- configuration = self['screens'][hook[:screen_name]]
217
- else
218
- return custom_methods unless self.has_key?('views')
219
- return custom_methods unless self['views'].class == Hash
220
- return custom_methods unless self['views'].has_key?(hook[:view_name])
221
-
222
- configuration = self['views'][hook[:view_name]]
223
- end
224
-
225
- if hook[:modals]
226
- return custom_methods unless configuration.has_key?('modals')
227
- return custom_methods unless configuration['modals'].class == Hash
228
- return custom_methods unless configuration['modals'].has_key?(hook[:modal_name])
229
-
230
- configuration = configuration['modals'][hook[:modal_name]]
231
- end
232
-
233
- return custom_methods unless configuration.class == Hash
234
- return custom_methods unless configuration.has_key?('elements')
235
- return custom_methods unless configuration['elements'].class == Hash
236
- return custom_methods unless configuration['elements'].has_key?(element_name)
237
-
238
- element_configuration = configuration['elements'][element_name]
239
-
240
- return custom_methods unless element_configuration.class == Hash
241
- return custom_methods unless element_configuration.has_key?('custom_methods')
242
- return custom_methods unless element_configuration['custom_methods'].class == Hash
243
-
244
- return element_configuration['custom_methods'].keys
245
- end
246
-
247
- def get_hook_level(hook, hook_action = false)
248
- level_key_string = ''
249
- if hook[:view_name]
250
- level_key_string << "views/#{hook[:view_name]}"
251
- else
252
- level_key_string << "screens/#{hook[:screen_name]}"
253
- end
254
-
255
- level_key_string << "/modals/#{hook[:modal_name]}" if hook[:modal_name]
256
- level_key_string << "/elements/#{hook[:element_name]}" if hook[:element_name]
257
-
258
- level_key_string << "/#{hook[:hook_name]}" if hook[:hook_name]
259
- level_key_string << "/#{hook_action}" if hook_action and hook_action != 'before_load'
260
-
261
- return level_key_string
262
- end
263
-
264
- def get_hooks
265
- hooks = Array.new
266
-
267
- if self.has_key?('views') and self['views'].class == Hash
268
- self['views'].each { |view_name, view_configuration|
269
- next unless view_configuration.class == Hash
270
-
271
- view_configuration.each { |sub_view_key, sub_view_configuration|
272
- next unless KeyValueConstants::HOOK_KEYS.include?(sub_view_key)
273
-
274
- hook = {:view_name => view_name, :hook_name => sub_view_key, :configuration => sub_view_configuration}
275
- hooks.push(hook)
276
- }
277
-
278
- #Check for Modals
279
- if view_configuration.has_key?('modals') and view_configuration['modals'].class == Hash
280
- view_configuration['modals'].each { |modal_name, modal_configuration|
281
- next unless modal_configuration.class == Hash
282
-
283
- modal_configuration.each { |sub_modal_key, sub_modal_configuration|
284
- next unless KeyValueConstants::HOOK_KEYS.include?(sub_modal_key)
285
-
286
- hook = {:view_name => view_name, :modal_name => modal_name,
287
- :hook_name => sub_modal_key, :configuration => sub_modal_configuration}
288
- hooks.push(hook)
289
- }
290
-
291
- next unless modal_configuration.has_key?('elements')
292
- next unless modal_configuration['elements'].class == Hash
293
-
294
- modal_configuration['elements'].each { |modal_element_name, modal_element_configuration|
295
- next unless modal_element_configuration.class == Hash
296
-
297
- modal_element_configuration.each { |sub_modal_element_key, sub_modal_element_configuration|
298
- next unless KeyValueConstants::ELEMENT_KEYS.include?(sub_modal_element_key)
299
-
300
- hook = {:view_name => view_name, :modal_name => modal_name,
301
- :element_name => modal_element_name, :hook_name => sub_modal_element_key,
302
- :configuration => sub_modal_element_configuration}
303
- hooks.push(hook)
304
- }
305
- }
306
- }
307
- end
308
-
309
- #Check for element hooks
310
- next unless view_configuration.has_key?('elements')
311
- next unless view_configuration['elements'].class == Hash
312
-
313
- view_configuration['elements'].each { |element_name, element_configuration|
314
- next unless element_configuration.class == Hash
315
-
316
- element_configuration.each { |sub_element_key, sub_element_configuration|
317
- next unless KeyValueConstants::ELEMENT_KEYS.include?(sub_element_key)
318
-
319
- hook = {:view_name => view_name, :element_name => element_name,
320
- :hook_name => sub_element_key, :configuration => sub_element_configuration}
321
- hooks.push(hook)
322
- }
323
- }
324
- }
325
- end
326
-
327
- return hooks unless self.has_key?('screens')
328
- return hooks unless self['screens'].class == Hash
329
-
330
- self['screens'].each { |screen_name, screen_configuration|
331
- next unless screen_configuration.class == Hash
332
-
333
- screen_configuration.each { |sub_screen_key, sub_screen_configuration|
334
- next unless KeyValueConstants::HOOK_KEYS.include?(sub_screen_key)
335
-
336
- hook = {:screen_name => screen_name, :hook_name => sub_screen_key,
337
- :configuration => sub_screen_configuration}
338
- hooks.push(hook)
339
- }
340
-
341
- #Check for Modals
342
- if screen_configuration.has_key?('modals') and screen_configuration['modals'].class == Hash
343
- screen_configuration['modals'].each { |modal_name, modal_configuration|
344
- next unless modal_configuration.class == Hash
345
-
346
- modal_configuration.each { |sub_modal_key, sub_modal_configuration|
347
- next unless KeyValueConstants::HOOK_KEYS.include?(sub_modal_key)
348
-
349
- hook = {:screen_name => screen_name, :modal_name => modal_name,
350
- :hook_name => sub_modal_key, :configuration => sub_modal_configuration}
351
- hooks.push(hook)
352
- }
353
-
354
- next unless modal_configuration.has_key?('elements')
355
- next unless modal_configuration['elements'].class == Hash
356
-
357
- modal_configuration['elements'].each { |modal_element_name, modal_element_configuration|
358
- next unless modal_element_configuration.class == Hash
359
-
360
- modal_element_configuration.each { |sub_modal_element_key, sub_modal_element_configuration|
361
- next unless KeyValueConstants::ELEMENT_KEYS.include?(sub_modal_element_key)
362
-
363
- hook = {:screen_name => screen_name, :modal_name => modal_name,
364
- :element_name => modal_element_name, :hook_name => sub_modal_element_key,
365
- :configuration => sub_modal_element_configuration}
366
- hooks.push(hook)
367
- }
368
- }
369
- }
370
- end
371
-
372
- #Check for element hooks
373
- next unless screen_configuration.has_key?('elements')
374
- next unless screen_configuration['elements'].class == Hash
375
-
376
- screen_configuration['elements'].each { |element_name, element_configuration|
377
- next unless element_configuration.class == Hash
378
-
379
- element_configuration.each { |sub_element_key, sub_element_configuration|
380
- next unless KeyValueConstants::ELEMENT_KEYS.include?(sub_element_key)
381
-
382
- hook = {:screen_name => screen_name, :element_name => element_name,
383
- :hook_name => sub_element_key, :configuration => sub_element_configuration}
384
- hooks.push(hook)
385
- }
386
- }
387
- }
388
-
389
- return hooks
390
- end
391
- end
392
- end
393
- end