automation_object 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/automation_object.rb +22 -11
- data/lib/automation_object/blue_print.rb +13 -12
- data/lib/automation_object/blue_print/composite/automatic_onload_modal.rb +9 -8
- data/lib/automation_object/blue_print/composite/base.rb +5 -4
- data/lib/automation_object/blue_print/composite/custom_method.rb +8 -7
- data/lib/automation_object/blue_print/composite/element.rb +6 -5
- data/lib/automation_object/blue_print/composite/element_array.rb +6 -5
- data/lib/automation_object/blue_print/composite/element_hash.rb +7 -6
- data/lib/automation_object/blue_print/composite/helpers/element_helper.rb +7 -7
- data/lib/automation_object/blue_print/composite/helpers/multiple_elements_helper.rb +5 -4
- data/lib/automation_object/blue_print/composite/hook.rb +9 -11
- data/lib/automation_object/blue_print/composite/hook_action.rb +25 -24
- data/lib/automation_object/blue_print/composite/hook_element_requirements.rb +14 -13
- data/lib/automation_object/blue_print/composite/modal.rb +11 -21
- data/lib/automation_object/blue_print/composite/screen.rb +22 -16
- data/lib/automation_object/blue_print/composite/top.rb +13 -12
- data/lib/automation_object/blue_print/composite/view.rb +27 -16
- data/lib/automation_object/blue_print/hash_adapter.rb +15 -11
- data/lib/automation_object/blue_print/hash_adapter/automatic_onload_modal.rb +12 -11
- data/lib/automation_object/blue_print/hash_adapter/composite.rb +28 -25
- data/lib/automation_object/blue_print/hash_adapter/custom_method.rb +11 -10
- data/lib/automation_object/blue_print/hash_adapter/element.rb +10 -9
- data/lib/automation_object/blue_print/hash_adapter/element_array.rb +10 -9
- data/lib/automation_object/blue_print/hash_adapter/element_hash.rb +11 -10
- data/lib/automation_object/blue_print/hash_adapter/helpers/element_helper.rb +20 -25
- data/lib/automation_object/blue_print/hash_adapter/helpers/multiple_elements_helper.rb +15 -14
- data/lib/automation_object/blue_print/hash_adapter/helpers/validation_error.rb +9 -8
- data/lib/automation_object/blue_print/hash_adapter/helpers/validation_helper.rb +19 -24
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate.rb +8 -5
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_allowed_keys.rb +7 -8
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_element_presence_of.rb +28 -23
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_instance_of.rb +12 -13
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_modal_presence_of.rb +27 -23
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_presence_of.rb +9 -8
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_screen_presence_of.rb +27 -23
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_view_presence_of.rb +25 -21
- data/lib/automation_object/blue_print/hash_adapter/hook.rb +14 -11
- data/lib/automation_object/blue_print/hash_adapter/hook_action.rb +45 -47
- data/lib/automation_object/blue_print/hash_adapter/hook_element_requirements.rb +24 -28
- data/lib/automation_object/blue_print/hash_adapter/modal.rb +14 -13
- data/lib/automation_object/blue_print/hash_adapter/screen.rb +23 -22
- data/lib/automation_object/blue_print/hash_adapter/top.rb +16 -15
- data/lib/automation_object/blue_print/hash_adapter/view.rb +58 -4
- data/lib/automation_object/blue_print/yaml_adapter.rb +33 -34
- data/lib/automation_object/driver.rb +15 -13
- data/lib/automation_object/driver/appium_adapter/driver.rb +47 -46
- data/lib/automation_object/driver/appium_adapter/element.rb +29 -96
- data/lib/automation_object/driver/base.rb +4 -2
- data/lib/automation_object/driver/common_selenium/driver.rb +60 -0
- data/lib/automation_object/driver/common_selenium/element.rb +107 -0
- data/lib/automation_object/driver/common_selenium/element_geometry.rb +86 -0
- data/lib/automation_object/driver/driver.rb +60 -30
- data/lib/automation_object/driver/element.rb +70 -15
- data/lib/automation_object/driver/nokogiri_adapter/driver.rb +88 -34
- data/lib/automation_object/driver/nokogiri_adapter/element.rb +94 -16
- data/lib/automation_object/driver/nokogiri_adapter/error.rb +29 -8
- data/lib/automation_object/driver/nokogiri_adapter/{backup/form.rb → form.rb} +19 -6
- data/lib/automation_object/driver/nokogiri_adapter/request.rb +17 -0
- data/lib/automation_object/driver/nokogiri_adapter/session.rb +94 -0
- data/lib/automation_object/driver/nokogiri_adapter/window.rb +86 -0
- data/lib/automation_object/driver/selenium_adapter/driver.rb +36 -45
- data/lib/automation_object/driver/selenium_adapter/element.rb +15 -85
- data/lib/automation_object/dsl.rb +11 -28
- data/lib/automation_object/dsl/_base.rb +70 -0
- data/lib/automation_object/dsl/_proxy.rb +24 -0
- data/lib/automation_object/dsl/element.rb +34 -0
- data/lib/automation_object/dsl/element_array.rb +34 -0
- data/lib/automation_object/dsl/element_hash.rb +34 -0
- data/lib/automation_object/dsl/modal.rb +43 -0
- data/lib/automation_object/dsl/screen.rb +45 -0
- data/lib/automation_object/dsl/top.rb +25 -0
- data/lib/automation_object/framework.rb +28 -38
- data/lib/automation_object/helpers/composite.rb +30 -27
- data/lib/automation_object/helpers/composite_hook.rb +16 -15
- data/lib/automation_object/{blue_print/helpers/file_helper.rb → helpers/file.rb} +12 -12
- data/lib/automation_object/helpers/hash.rb +6 -5
- data/lib/automation_object/helpers/kernel.rb +11 -0
- data/lib/automation_object/helpers/{reflection_helper.rb → reflection.rb} +9 -8
- data/lib/automation_object/helpers/string.rb +25 -15
- data/lib/automation_object/{proxies → proxy}/mutex_proxy.rb +18 -21
- data/lib/automation_object/proxy/proxy.rb +23 -0
- data/lib/automation_object/proxy/throttle_proxy.rb +52 -0
- data/lib/automation_object/state.rb +11 -29
- data/lib/automation_object/state/{blue_print_adapter/composite.rb → composite/_base.rb} +35 -25
- data/lib/automation_object/state/{blue_print_adapter/helpers/element_helper.rb → composite/_common_element.rb} +11 -11
- data/lib/automation_object/state/composite/element.rb +22 -0
- data/lib/automation_object/state/composite/element_array.rb +27 -0
- data/lib/automation_object/state/composite/element_hash.rb +33 -0
- data/lib/automation_object/state/composite/element_proxy.rb +33 -0
- data/lib/automation_object/state/composite/helpers/window.rb +61 -0
- data/lib/automation_object/state/composite/helpers/window_manager.rb +60 -0
- data/lib/automation_object/state/composite/hook.rb +56 -0
- data/lib/automation_object/state/{blue_print_adapter → composite}/hook_action.rb +10 -8
- data/lib/automation_object/state/composite/hook_actions/action_loop.rb +36 -0
- data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/change_screen.rb +7 -5
- data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/change_to_previous_screen.rb +7 -5
- data/lib/automation_object/state/composite/hook_actions/close_modal.rb +29 -0
- data/lib/automation_object/state/composite/hook_actions/close_screen.rb +19 -0
- data/lib/automation_object/state/composite/hook_actions/element_requirement.rb +32 -0
- data/lib/automation_object/state/composite/hook_actions/new_screen.rb +35 -0
- data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/possible_screen_changes.rb +8 -7
- data/lib/automation_object/state/composite/hook_actions/reset_screen.rb +14 -0
- data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/show_modal.rb +7 -5
- data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/sleep.rb +4 -2
- data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/wait_for_elements.rb +7 -5
- data/lib/automation_object/state/composite/modal.rb +45 -0
- data/lib/automation_object/state/composite/screen.rb +58 -0
- data/lib/automation_object/state/composite/top.rb +51 -0
- data/lib/automation_object/state/error.rb +45 -6
- data/lib/automation_object/state/session.rb +25 -23
- data/lib/automation_object/step_definitions.rb +5 -3
- data/lib/automation_object/step_definitions/element.rb +77 -0
- data/lib/automation_object/step_definitions/element_array.rb +135 -0
- data/lib/automation_object/step_definitions/element_hash.rb +126 -0
- data/lib/automation_object/step_definitions/screen.rb +62 -0
- data/lib/automation_object/step_definitions/{cache.rb → support/cache.rb} +8 -6
- data/lib/automation_object/step_definitions/support/element_array.rb +40 -0
- data/lib/automation_object/step_definitions/support/element_hash.rb +41 -0
- data/lib/automation_object/step_definitions/{parse.rb → support/parse.rb} +8 -6
- data/lib/automation_object/version.rb +2 -1
- metadata +203 -103
- data/lib/automation_object/driver/helpers/selenium_driver_helper.rb +0 -41
- data/lib/automation_object/driver/helpers/selenium_element_helper.rb +0 -138
- data/lib/automation_object/driver/nokogiri_adapter/backup/driver.rb +0 -83
- data/lib/automation_object/driver/nokogiri_adapter/backup/element.rb +0 -66
- data/lib/automation_object/driver/nokogiri_adapter/backup/helpers/driver_element_helper.rb +0 -52
- data/lib/automation_object/driver/nokogiri_adapter/backup/session.rb +0 -115
- data/lib/automation_object/dsl/blue_print_adapter.rb +0 -16
- data/lib/automation_object/dsl/blue_print_adapter/composite.rb +0 -54
- data/lib/automation_object/dsl/blue_print_adapter/element.rb +0 -14
- data/lib/automation_object/dsl/blue_print_adapter/element_array.rb +0 -14
- data/lib/automation_object/dsl/blue_print_adapter/element_hash.rb +0 -14
- data/lib/automation_object/dsl/blue_print_adapter/modal.rb +0 -23
- data/lib/automation_object/dsl/blue_print_adapter/screen.rb +0 -26
- data/lib/automation_object/dsl/blue_print_adapter/top.rb +0 -19
- data/lib/automation_object/dsl/models.rb +0 -18
- data/lib/automation_object/dsl/proxies/element.rb +0 -16
- data/lib/automation_object/dsl/proxies/element_array.rb +0 -16
- data/lib/automation_object/dsl/proxies/element_hash.rb +0 -16
- data/lib/automation_object/dsl/proxies/helpers/composite_helper.rb +0 -74
- data/lib/automation_object/dsl/proxies/modal.rb +0 -17
- data/lib/automation_object/dsl/proxies/screen.rb +0 -17
- data/lib/automation_object/dsl/proxies/top.rb +0 -17
- data/lib/automation_object/proxies/proxy.rb +0 -20
- data/lib/automation_object/proxies/throttle_proxy.rb +0 -57
- data/lib/automation_object/state/blue_print_adapter.rb +0 -16
- data/lib/automation_object/state/blue_print_adapter/element.rb +0 -20
- data/lib/automation_object/state/blue_print_adapter/element_array.rb +0 -25
- data/lib/automation_object/state/blue_print_adapter/element_hash.rb +0 -31
- data/lib/automation_object/state/blue_print_adapter/element_proxy.rb +0 -28
- data/lib/automation_object/state/blue_print_adapter/helpers/screen_manager.rb +0 -137
- data/lib/automation_object/state/blue_print_adapter/helpers/window.rb +0 -39
- data/lib/automation_object/state/blue_print_adapter/hook.rb +0 -56
- data/lib/automation_object/state/blue_print_adapter/hook_actions/action_loop.rb +0 -35
- data/lib/automation_object/state/blue_print_adapter/hook_actions/close_modal.rb +0 -31
- data/lib/automation_object/state/blue_print_adapter/hook_actions/close_screen.rb +0 -19
- data/lib/automation_object/state/blue_print_adapter/hook_actions/element_requirement.rb +0 -34
- data/lib/automation_object/state/blue_print_adapter/hook_actions/new_screen.rb +0 -37
- data/lib/automation_object/state/blue_print_adapter/hook_actions/reset_screen.rb +0 -18
- data/lib/automation_object/state/blue_print_adapter/modal.rb +0 -26
- data/lib/automation_object/state/blue_print_adapter/screen.rb +0 -32
- data/lib/automation_object/state/blue_print_adapter/top.rb +0 -45
- data/lib/automation_object/step_definitions/action.rb +0 -21
- data/lib/automation_object/step_definitions/element/actions.rb +0 -87
- data/lib/automation_object/step_definitions/element/regex.rb +0 -24
- data/lib/automation_object/step_definitions/element/steps.rb +0 -67
@@ -0,0 +1,135 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'support/parse'
|
3
|
+
require_relative 'support/element_array'
|
4
|
+
|
5
|
+
# Description: Provides step definitions related to element arrays
|
6
|
+
|
7
|
+
# For: Calling an element array method
|
8
|
+
# Examples:
|
9
|
+
# - I click on the first "home_screen" "about_button" element array
|
10
|
+
# - I hover over all "home_screen" "about_button" element array
|
11
|
+
# - I click on 0..9 "home_screen" "about_button" element array
|
12
|
+
# - I click on a random "home_screen" "about_button" element array
|
13
|
+
When(%r(^I (\w+|%\{[\w\d]+\})?(?: on| over)?(?: the| a)? (%\{[\w\d]+\}|all|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element array$/)) do |*args|
|
14
|
+
method, key, low_range, high_range, screen, element = AutomationObject::StepDefinitions::Parse.new(args).get
|
15
|
+
|
16
|
+
AutomationObject::StepDefinitions::ElementArray.iterate_and_do(
|
17
|
+
screen, element, key, low_range, high_range
|
18
|
+
) do |sub_element|
|
19
|
+
sub_element.send(method)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# For: Typing into element array field
|
24
|
+
# Examples:
|
25
|
+
# - I type "blah" into the first "home_screen" "text_field" element array
|
26
|
+
When(%r(^I type "([\w\s]+|%\{[\w\d]+\})" in(?:to| to)? (?:the )?(%\{[\w\d]+\}|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element array$/)) do |*args|
|
27
|
+
text, key, low_range, high_range, screen, element = AutomationObject::StepDefinitions::Parse.new(args).get
|
28
|
+
|
29
|
+
AutomationObject::StepDefinitions::ElementArray.iterate_and_do(
|
30
|
+
screen, element, key, low_range, high_range
|
31
|
+
) do |sub_element|
|
32
|
+
sub_element.send_keys(text)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# For: Scrolling element array item(s) into focus
|
37
|
+
# Examples:
|
38
|
+
# - I scroll to the first "home_screen" "logo_button" element array
|
39
|
+
When(%r(^I (?:scroll |focus )(?:to |through )(?:the )?(%\{[\w\d]+\}|all|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element array$/)) do |*args|
|
40
|
+
key, low_range, high_range, screen, element = AutomationObject::StepDefinitions::Parse.new(args).get
|
41
|
+
|
42
|
+
AutomationObject::StepDefinitions::ElementArray.iterate_and_do(
|
43
|
+
screen, element, key, low_range, high_range, &:scroll_into_view
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
# For: Saving value from element array for use later
|
48
|
+
# Examples:
|
49
|
+
# - I save "text" as "unique_value" from the first "home_screen" "logo_button" element array
|
50
|
+
When(%r(^I save "(\w+|%\{[\w\d]+\})" as "([\w\d]+)" from (?:the )?(%\{[\w\d]+\}|all|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element array$/)) do |*args|
|
51
|
+
method, value_key, key, low_range, high_range, screen, element = AutomationObject::StepDefinitions::Parse.new(args).get
|
52
|
+
|
53
|
+
AutomationObject::StepDefinitions::ElementArray.iterate_and_do(
|
54
|
+
screen, element, key, low_range, high_range
|
55
|
+
) do |sub_element|
|
56
|
+
value = sub_element.send(method)
|
57
|
+
AutomationObject::StepDefinitions::Cache.set(value_key, value)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# For: Testing the element arrays size
|
62
|
+
# Examples:
|
63
|
+
# - the "home_screen" "title" element array should be greater than 0
|
64
|
+
Then(%r(^(?:the )?"([\w\d]+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element array should(n't|not)? (?:be )?(larger th[ae]n|greater th[ae]n|less th[ae]n|smaller th[ae]n|equals?) (?:to )?(\d+)$/)) do |*args|
|
65
|
+
screen, element, negative, comparison, expected_value = AutomationObject::StepDefinitions::Parse.new(args).get
|
66
|
+
|
67
|
+
element_array = AutomationObject::Framework.get.send(screen).send(element)
|
68
|
+
assert element_array.is_a?(Array)
|
69
|
+
|
70
|
+
if comparison =~ /larger th[ae]n|greater th[ae]n/
|
71
|
+
if negative
|
72
|
+
refute expected_value < element_array.length
|
73
|
+
else
|
74
|
+
assert expected_value < element_array.length
|
75
|
+
end
|
76
|
+
elsif comparison =~ /smaller th[ae]n|less th[ae]n/
|
77
|
+
if negative
|
78
|
+
refute expected_value > element_array.length
|
79
|
+
else
|
80
|
+
assert expected_value > element_array.length
|
81
|
+
end
|
82
|
+
elsif comparison =~ /equals?/
|
83
|
+
if negative
|
84
|
+
refute_equals expected_value, element_array.length
|
85
|
+
else
|
86
|
+
assert_equals expected_value, element_array.length
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# For: Testing if the element method value equals a given value
|
92
|
+
# Examples:
|
93
|
+
# - the first "home_screen" "title" element array "text" should equal "Home"
|
94
|
+
# - the last "home_screen" "title" element array "text" shouldn't equal "Home"
|
95
|
+
# - the random "home_screen" "title" element array "text" should not equal "Home"
|
96
|
+
# - the 0..9 "home_screen" "title" element array "text" should equal "Home"
|
97
|
+
# - the all "home_screen" "title" element array "text" should not equal "Home"
|
98
|
+
Then(%r(^(?:the )?(%\{\w+\}|all|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element array "(\w+|%\{[\w\d]+\})" should?(n't| not)? equal "(\w+|%\{[\w\d]+\})"$/)) do |*args|
|
99
|
+
key, low_range, high_range, screen, element, method, negative, expected_value = AutomationObject::StepDefinitions::Parse.new(args).get
|
100
|
+
|
101
|
+
AutomationObject::StepDefinitions::ElementArray.iterate_and_do(
|
102
|
+
screen, element, key, low_range, high_range
|
103
|
+
) do |sub_element|
|
104
|
+
value = sub_element.send(method)
|
105
|
+
|
106
|
+
if negative
|
107
|
+
refute_equals expected_value, value
|
108
|
+
else
|
109
|
+
assert_equals expected_value, value
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# For: Testing if the element arrays uniqueness
|
115
|
+
# Examples:
|
116
|
+
# - the "home_screen" "title" element array "text" should be unique
|
117
|
+
# - the "home_screen" "title" element array "text" should not be unique
|
118
|
+
# - the "home_screen" "title" element array "text" shouldn't be unique
|
119
|
+
Then(%r(^(?:the )?"([\w\d]+|%\{[\w\d]+\})" "([\w\d]+|%\{[\w\d]+\})" element array "([\w\d]+|%\{[\w\d]+\})" should(n't| not)? be unique$/)) do |*args|
|
120
|
+
screen, element, method, negative = AutomationObject::StepDefinitions::Parse.new(args).get
|
121
|
+
|
122
|
+
element_array = AutomationObject::Framework.get.send(screen).send(element)
|
123
|
+
assert element_array.is_a?(Array)
|
124
|
+
|
125
|
+
values = []
|
126
|
+
element_array.each do |sub_element|
|
127
|
+
values.push(sub_element.send(method))
|
128
|
+
end
|
129
|
+
|
130
|
+
if negative
|
131
|
+
refute_equals values.uniq, values
|
132
|
+
else
|
133
|
+
assert_equals values.uniq, values
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'support/parse'
|
3
|
+
require_relative 'support/element_hash'
|
4
|
+
|
5
|
+
# Description: Provides step definitions related to element hashes
|
6
|
+
|
7
|
+
# For: Calling an element hash method
|
8
|
+
# Examples:
|
9
|
+
# - I click on the first "home_screen" "about_button" element hash
|
10
|
+
When(%r(^I (\w+|%\{[\w\d]+\})?(?: on| over)?(?: the| a)? (%\{[\w\d]+\}|all|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element hash/)) do |*args|
|
11
|
+
method, key, low_range, high_range, screen, element = AutomationObject::StepDefinitions::Parse.new(args).get
|
12
|
+
|
13
|
+
AutomationObject::StepDefinitions::ElementHash.iterate_and_do(
|
14
|
+
screen, element, key, low_range, high_range
|
15
|
+
) do |sub_element|
|
16
|
+
sub_element.send(method)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# For: Typing into element hash field
|
21
|
+
# Examples:
|
22
|
+
# - I type "blah" into the first "home_screen" "text_field" element hash
|
23
|
+
When(%r(^I type "([\w\s]+|%\{[\w\d]+\})" in(?:to| to)? (?:the )?(%\{[\w\d]+\}|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element hash/)) do |*args|
|
24
|
+
text, key, low_range, high_range, screen, element = AutomationObject::StepDefinitions::Parse.new(args).get
|
25
|
+
|
26
|
+
AutomationObject::StepDefinitions::ElementHash.iterate_and_do(
|
27
|
+
screen, element, key, low_range, high_range
|
28
|
+
) do |sub_element|
|
29
|
+
sub_element.send_keys(text)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# For: Scrolling element hash item(s) into focus
|
34
|
+
# Examples:
|
35
|
+
# - I scroll to the first "home_screen" "logo_button" element hash
|
36
|
+
When(%r(^I (?:scroll |focus )(?:to |through )(?:the )?(%\{[\w\d]+\}|all|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element hash/)) do |*args|
|
37
|
+
key, low_range, high_range, screen, element = AutomationObject::StepDefinitions::Parse.new(args).get
|
38
|
+
|
39
|
+
AutomationObject::StepDefinitions::ElementHash.iterate_and_do(
|
40
|
+
screen, element, key, low_range, high_range, &:scroll_into_view
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
# For: Saving value from element hash for use later
|
45
|
+
# Examples:
|
46
|
+
# - I save "text" as "unique_value" from the first "home_screen" "logo_button" element hash
|
47
|
+
When(%r(^I save "(\w+|%\{[\w\d]+\})" as "([\w\d]+)" from (?:the )?(%\{[\w\d]+\}|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element hash/)) do |*args|
|
48
|
+
method, value_key, key, low_range, high_range, screen, element = AutomationObject::StepDefinitions::Parse.new(args).get
|
49
|
+
|
50
|
+
AutomationObject::StepDefinitions::ElementHash.iterate_and_do(
|
51
|
+
screen, element, key, low_range, high_range
|
52
|
+
) do |sub_element|
|
53
|
+
value = sub_element.send(method)
|
54
|
+
AutomationObject::StepDefinitions::Cache.set(value_key, value)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# For: Testing the element hashes size
|
59
|
+
# Examples:
|
60
|
+
# - the "home_screen" "title" element hash should be greater than 0
|
61
|
+
Then(%r(^(?:the )?"([\w\d]+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element hash should(n't|not)? (?:be )?(larger th[ae]n|greater th[ae]n|less th[ae]n|smaller th[ae]n|equals?) (?:to )?(\d+)$/)) do |*args|
|
62
|
+
screen, element, negative, comparison, expected_value = AutomationObject::StepDefinitions::Parse.new(args).get
|
63
|
+
|
64
|
+
element_hash = AutomationObject::Framework.get.send(screen).send(element)
|
65
|
+
assert element_hash.is_a?(Hash)
|
66
|
+
|
67
|
+
if comparison =~ /larger th[ae]n|greater th[ae]n/
|
68
|
+
if negative
|
69
|
+
refute expected_value < element_hash.keys.length
|
70
|
+
else
|
71
|
+
assert expected_value < element_hash.keys.length
|
72
|
+
end
|
73
|
+
elsif comparison =~ /smaller th[ae]n|less th[ae]n/
|
74
|
+
if negative
|
75
|
+
refute expected_value > element_hash.keys.length
|
76
|
+
else
|
77
|
+
assert expected_value > element_hash.keys.length
|
78
|
+
end
|
79
|
+
elsif comparison =~ /equals?/
|
80
|
+
if negative
|
81
|
+
refute_equals expected_value, element_hash.keys.length
|
82
|
+
else
|
83
|
+
assert_equals expected_value, element_hash.keys.length
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# For: Testing if the element hash value equals a given value
|
89
|
+
# Examples:
|
90
|
+
# - the first "home_screen" "title" element hash "text" should equal "Home"
|
91
|
+
Then(%r(^(?:the )?(%\{\w+\}|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element hash "(\w+|%\{[\w\d]+\})" should ?(n't |not )?equal "(\w+|%\{[\w\d]+\})"$/)) do |*args|
|
92
|
+
key, low_range, high_range, screen, element, method, negative, expected_value = AutomationObject::StepDefinitions::Parse.new(args).get
|
93
|
+
|
94
|
+
AutomationObject::StepDefinitions::ElementHash.iterate_and_do(
|
95
|
+
screen, element, key, low_range, high_range
|
96
|
+
) do |sub_element|
|
97
|
+
value = sub_element.send(method)
|
98
|
+
|
99
|
+
if negative
|
100
|
+
refute_equals expected_value, value
|
101
|
+
else
|
102
|
+
assert_equals expected_value, value
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# For: Testing if the element hashes uniqueness
|
108
|
+
# Examples:
|
109
|
+
# - the "home_screen" "title" element hash "text" should be unique
|
110
|
+
Then(%r(^(?:the )?"([\w\d]+|%\{[\w\d]+\})" "([\w\d]+|%\{[\w\d]+\})" element hash "([\w\d]+|%\{[\w\d]+\})" should(n't|not)? be unique$/)) do |*args|
|
111
|
+
screen, element, method, negative = AutomationObject::StepDefinitions::Parse.new(args).get
|
112
|
+
|
113
|
+
element_hash = AutomationObject::Framework.get.send(screen).send(element)
|
114
|
+
assert element_hash.is_a?(Hash)
|
115
|
+
|
116
|
+
values = []
|
117
|
+
element_hash.each_value do |sub_element|
|
118
|
+
values.push(sub_element.send(method))
|
119
|
+
end
|
120
|
+
|
121
|
+
if negative
|
122
|
+
refute_equals values.uniq, values
|
123
|
+
else
|
124
|
+
assert_equals values.uniq, values
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'support/parse'
|
3
|
+
|
4
|
+
# Description: Provides step definitions related to screens
|
5
|
+
|
6
|
+
# For: Close the current screen or given screen
|
7
|
+
# Examples:
|
8
|
+
# - I close the "contact" screen
|
9
|
+
# - I close the screen
|
10
|
+
# - I destroy the screen
|
11
|
+
Then(%r(^I (?:close|destroy) the ("([\w\s]+|%\{[\w\d]+\})")? ?screen$/)) do |*args|
|
12
|
+
_unparsed_name, name = AutomationObject::StepDefinitions::Parse.new(args).get
|
13
|
+
|
14
|
+
if name
|
15
|
+
AutomationObject::Framework.get.screen(name).close
|
16
|
+
else
|
17
|
+
AutomationObject::Framework.get.current_screen.close
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# For: Navigating back on a given or current screen
|
22
|
+
# Examples:
|
23
|
+
# - I navigate back on the screen
|
24
|
+
# - I navigate back on the "contact" screen
|
25
|
+
Then(%r(^I (?:navigate|go) back (?:on )?(?:the )?("([\w\s]+|%\{[\w\d]+\})")? ?screen$/)) do
|
26
|
+
_unparsed_name, name = AutomationObject::StepDefinitions::Parse.new(args).get
|
27
|
+
|
28
|
+
if name
|
29
|
+
AutomationObject::Framework.get.screen(name).back
|
30
|
+
else
|
31
|
+
AutomationObject::Framework.get.current_screen.back
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# For: Switch/Focus screen
|
36
|
+
# Examples:
|
37
|
+
# - I switch to the "home" screen
|
38
|
+
# - I focus the "contact" screen
|
39
|
+
Then(%r(^I (?:switch|focus) (?:to )?(?:the )?"([\w\s]+|%\{[\w\d]+\})" screen$/)) do |*args|
|
40
|
+
screen = AutomationObject::StepDefinitions::Parse.new(args).get
|
41
|
+
AutomationObject::Framework.get.focus(screen)
|
42
|
+
end
|
43
|
+
|
44
|
+
# For: Setting the current screen's width or given screen
|
45
|
+
# Examples:
|
46
|
+
# - I set the screen size to 1000x2000
|
47
|
+
# - I set the "home" screen size to 1000x2000
|
48
|
+
# - I set the screen width to 1000
|
49
|
+
# - I set the screen height to 2000
|
50
|
+
Then(%r(^I set the ("([\w\s]+|%\{[\w\d]+\})")? ?screen (size|width|height) to (\d+|(\d+)x(\d+))$/)) do |*args|
|
51
|
+
_unparsed_screen, screen, dimension, size, width, height = AutomationObject::StepDefinitions::Parse.new(args).get
|
52
|
+
|
53
|
+
screen = if screen
|
54
|
+
AutomationObject::Framework.get.screen(screen)
|
55
|
+
else
|
56
|
+
AutomationObject::Framework.get.current_screen
|
57
|
+
end
|
58
|
+
|
59
|
+
screen.size(width.to_i, height.to_i) if width && height
|
60
|
+
screen.width(size) if dimension == 'width' && size
|
61
|
+
screen.height(size) if dimension == 'height' && size
|
62
|
+
end
|
@@ -1,10 +1,12 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Class for caching values between steps
|
2
3
|
module AutomationObject
|
3
4
|
module StepDefinitions
|
5
|
+
# Cache module for temporary storage of vars
|
4
6
|
module Cache
|
5
|
-
|
7
|
+
module_function
|
6
8
|
|
7
|
-
#Singleton hash, create new if needed
|
9
|
+
# Singleton hash, create new if needed
|
8
10
|
# @return [Hash] hash of values saved or new hash
|
9
11
|
def values
|
10
12
|
return @values if @values
|
@@ -12,12 +14,12 @@ module AutomationObject
|
|
12
14
|
end
|
13
15
|
|
14
16
|
def get(key)
|
15
|
-
|
17
|
+
values[key]
|
16
18
|
end
|
17
19
|
|
18
20
|
def set(key, value)
|
19
|
-
|
21
|
+
values[key] = value
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
23
|
-
end
|
25
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module AutomationObject
|
3
|
+
module StepDefinitions
|
4
|
+
# Element array module for iterating through an array
|
5
|
+
module ElementArray
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def iterate_and_do(screen, element, key, low_range, high_range)
|
9
|
+
element_array = AutomationObject::Framework.get.send(screen).send(element)
|
10
|
+
assert element_array.is_a?(Array)
|
11
|
+
|
12
|
+
return range(element_array, low_range, high_range) if low_range && high_range
|
13
|
+
|
14
|
+
case key
|
15
|
+
when 'all'
|
16
|
+
element_array.each do |sub_element|
|
17
|
+
yield sub_element
|
18
|
+
end
|
19
|
+
when 'random'
|
20
|
+
yield element_array[rand(0..(element_array.length - 1))]
|
21
|
+
when 'first'
|
22
|
+
yield element_array[0]
|
23
|
+
when 'last'
|
24
|
+
yield element_array[element_array.length - 1]
|
25
|
+
else
|
26
|
+
yield element_array[key.to_i]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def range(element_array, low_range, high_range)
|
33
|
+
low_range.to_i..high_range.to_i.each do |i|
|
34
|
+
assert element_array.length > i
|
35
|
+
yield element_array[i]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module AutomationObject
|
3
|
+
module StepDefinitions
|
4
|
+
# Element hash module for iterating through an hash
|
5
|
+
module ElementHash
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def iterate_and_do(screen, element, key, low_range, high_range)
|
9
|
+
element_hash = AutomationObject::Framework.get.send(screen).send(element)
|
10
|
+
assert element_hash.is_a?(Hash)
|
11
|
+
|
12
|
+
return range(element_hash, low_range, high_range) if low_range && high_range
|
13
|
+
|
14
|
+
case key
|
15
|
+
when 'all'
|
16
|
+
element_hash.each_value do |sub_element|
|
17
|
+
yield sub_element
|
18
|
+
end
|
19
|
+
when 'random'
|
20
|
+
yield element_hash[element_hash.keys[rand(0..(element_hash.keys.length - 1))]]
|
21
|
+
when 'first'
|
22
|
+
yield element_hash[element_hash.keys[0]]
|
23
|
+
when 'last'
|
24
|
+
yield element_hash[element_hash.keys[element_hash.keys.length - 1]]
|
25
|
+
else
|
26
|
+
yield element_hash[key.to_s]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def range(element_hash, low_range, high_range)
|
33
|
+
low_range.to_i..high_range.to_i.each do |i|
|
34
|
+
assert element_hash.keys.length > i
|
35
|
+
|
36
|
+
block.call element_hash[element_hash.keys[i]]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require_relative 'cache'
|
2
3
|
|
3
4
|
module AutomationObject
|
4
5
|
module StepDefinitions
|
6
|
+
# Class to parse arguments passed through step definitions
|
5
7
|
class Parse
|
6
8
|
# @param args [Array] input args from step definition
|
7
9
|
def initialize(args)
|
@@ -10,11 +12,11 @@ module AutomationObject
|
|
10
12
|
|
11
13
|
def get
|
12
14
|
parsed_args = []
|
13
|
-
|
15
|
+
@args.each do |arg|
|
14
16
|
parsed_args.push(parse(arg))
|
15
17
|
end
|
16
18
|
|
17
|
-
|
19
|
+
parsed_args
|
18
20
|
end
|
19
21
|
|
20
22
|
private
|
@@ -25,15 +27,15 @@ module AutomationObject
|
|
25
27
|
def parse(string)
|
26
28
|
parsed_string = string
|
27
29
|
|
28
|
-
string.scan(/%\{(\w+)\}/)
|
30
|
+
string.scan(/%\{(\w+)\}/) do |cache_key|
|
29
31
|
cached_value = AutomationObject::StepDefinitions::Cache.get(cache_key)
|
30
32
|
next unless cached_value
|
31
33
|
|
32
34
|
parsed_string.gsub("%{#{cache_key}}", cached_value)
|
33
|
-
|
35
|
+
end
|
34
36
|
|
35
|
-
|
37
|
+
parsed_string
|
36
38
|
end
|
37
39
|
end
|
38
40
|
end
|
39
|
-
end
|
41
|
+
end
|