bugsnag-maze-runner 9.0.0 → 11.4.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 (106) hide show
  1. checksums.yaml +4 -4
  2. data/bin/bb-failed-sessions +94 -0
  3. data/bin/benchmarks-to-datadog +191 -0
  4. data/bin/download-logs +1 -1
  5. data/bin/maze-runner +64 -11
  6. data/bin/purge-projects +1 -1
  7. data/bin/upload-app +1 -1
  8. data/lib/features/steps/app_automator_steps.rb +27 -185
  9. data/lib/features/steps/breadcrumb_steps.rb +1 -1
  10. data/lib/features/steps/browser_steps.rb +4 -0
  11. data/lib/features/steps/error_config_steps.rb +16 -0
  12. data/lib/features/steps/error_reporting_steps.rb +0 -8
  13. data/lib/features/steps/multipart_request_steps.rb +3 -3
  14. data/lib/features/steps/network_steps.rb +1 -1
  15. data/lib/features/steps/payload_steps.rb +3 -13
  16. data/lib/features/steps/platform_dependent_steps.rb +204 -0
  17. data/lib/features/steps/request_assertion_steps.rb +39 -8
  18. data/lib/features/steps/session_tracking_steps.rb +0 -2
  19. data/lib/features/steps/span_steps.rb +184 -0
  20. data/lib/features/steps/trace_steps.rb +52 -189
  21. data/lib/features/steps/value_steps.rb +5 -0
  22. data/lib/features/support/cucumber_types.rb +1 -1
  23. data/lib/features/support/error_config_support.rb +39 -0
  24. data/lib/features/support/internal_hooks.rb +95 -51
  25. data/lib/features/support/span_support.rb +101 -0
  26. data/lib/maze/api/appium/app_manager.rb +118 -0
  27. data/lib/maze/api/appium/device_manager.rb +131 -0
  28. data/lib/maze/api/appium/file_manager.rb +69 -8
  29. data/lib/maze/api/appium/manager.rb +25 -0
  30. data/lib/maze/api/appium/ui_manager.rb +98 -0
  31. data/lib/maze/api/cucumber/scenario.rb +12 -0
  32. data/lib/maze/api/exit_code.rb +2 -0
  33. data/lib/maze/api/model/otel_attribute.rb +69 -0
  34. data/lib/maze/api/model/otel_attribute_type.rb +36 -0
  35. data/lib/maze/api/model/span.rb +44 -0
  36. data/lib/maze/api/model/span_kind.rb +16 -0
  37. data/lib/maze/api/model/span_set.rb +66 -0
  38. data/lib/maze/appium_server.rb +1 -2
  39. data/lib/maze/aws/sam.rb +12 -12
  40. data/lib/maze/aws_public_ip.rb +15 -13
  41. data/lib/maze/client/appium/base_client.rb +85 -12
  42. data/lib/maze/client/appium/bb_client.rb +35 -18
  43. data/lib/maze/client/appium/bb_devices.rb +59 -23
  44. data/lib/maze/client/appium/bs_client.rb +9 -10
  45. data/lib/maze/client/appium/bs_devices.rb +17 -39
  46. data/lib/maze/client/appium/session_metadata.rb +18 -0
  47. data/lib/maze/client/appium.rb +1 -8
  48. data/lib/maze/client/bb_api_client.rb +7 -3
  49. data/lib/maze/client/bb_client_utils.rb +56 -0
  50. data/lib/maze/client/selenium/base_client.rb +60 -1
  51. data/lib/maze/client/selenium/bb_browsers.yml +18 -39
  52. data/lib/maze/client/selenium/bb_client.rb +17 -15
  53. data/lib/maze/client/selenium/bs_browsers.yml +47 -62
  54. data/lib/maze/client/selenium/bs_client.rb +28 -38
  55. data/lib/maze/configuration.rb +50 -20
  56. data/lib/maze/docker.rb +0 -1
  57. data/lib/maze/driver/appium.rb +164 -62
  58. data/lib/maze/driver/browser.rb +39 -11
  59. data/lib/maze/error_monitor/assert_error_middleware.rb +25 -0
  60. data/lib/maze/error_monitor/config.rb +59 -0
  61. data/lib/maze/error_monitor/selenium_error_middleware.rb +43 -0
  62. data/lib/maze/errors.rb +1 -1
  63. data/lib/maze/helper.rb +10 -1
  64. data/lib/maze/hooks/appium_hooks.rb +22 -34
  65. data/lib/maze/hooks/logger_hooks.rb +28 -0
  66. data/lib/maze/interactive_cli.rb +9 -7
  67. data/lib/maze/loggers/file_logger.rb +32 -0
  68. data/lib/maze/loggers/log_util.rb +59 -0
  69. data/lib/maze/loggers/logger.rb +61 -0
  70. data/lib/maze/loggers/stdout_logger.rb +34 -0
  71. data/lib/maze/maze_output.rb +49 -8
  72. data/lib/maze/option/parser.rb +22 -23
  73. data/lib/maze/option/processor.rb +34 -34
  74. data/lib/maze/option/validator.rb +41 -15
  75. data/lib/maze/option.rb +3 -6
  76. data/lib/maze/plugins/datadog_metrics_plugin.rb +2 -1
  77. data/lib/maze/plugins/global_retry_plugin.rb +1 -1
  78. data/lib/maze/plugins/logging_scenarios_plugin.rb +19 -0
  79. data/lib/maze/repeaters/bugsnag_repeater.rb +1 -3
  80. data/lib/maze/repeaters/hub_repeater.rb +33 -0
  81. data/lib/maze/repeaters/request_repeater.rb +0 -1
  82. data/lib/maze/request_list.rb +22 -1
  83. data/lib/maze/retry_handler.rb +3 -23
  84. data/lib/maze/runner.rb +1 -1
  85. data/lib/maze/schemas/config_validator.rb +30 -0
  86. data/lib/maze/schemas/error_validator.rb +13 -0
  87. data/lib/maze/schemas/trace_validator.rb +65 -68
  88. data/lib/maze/schemas/validator.rb +31 -41
  89. data/lib/maze/schemas/validator_base.rb +152 -0
  90. data/lib/maze/server.rb +63 -5
  91. data/lib/maze/servlets/command_servlet.rb +27 -16
  92. data/lib/maze/servlets/error_config_servlet.rb +66 -0
  93. data/lib/maze/servlets/idempotent_command_servlet.rb +86 -0
  94. data/lib/maze/servlets/reflective_servlet.rb +23 -1
  95. data/lib/maze/servlets/servlet.rb +24 -4
  96. data/lib/maze.rb +3 -2
  97. data/lib/utils/selenium_money_patch.rb +3 -2
  98. metadata +138 -55
  99. data/lib/features/steps/deprecated_steps.rb +0 -8
  100. data/lib/features/steps/document_server_steps.rb +0 -7
  101. data/lib/maze/bugsnag_config.rb +0 -49
  102. data/lib/maze/client/appium/bs_legacy_client.rb +0 -31
  103. data/lib/maze/document_server.rb +0 -46
  104. data/lib/maze/logger.rb +0 -117
  105. data/lib/maze/plugins/bugsnag_reporting_plugin.rb +0 -56
  106. data/lib/maze/repeaters/aspecto_repeater.rb +0 -34
@@ -5,7 +5,7 @@
5
5
  #
6
6
  # @step_input element_id [String] The locator id
7
7
  Given('the element {string} is present') do |element_id|
8
- present = Maze.driver.wait_for_element(element_id)
8
+ present = Maze::Api::Appium::UiManager.new.wait_for_element(element_id)
9
9
  raise Maze::Error::AppiumElementNotFoundError.new("The element #{element_id} could not be found", element_id) unless present
10
10
  end
11
11
 
@@ -15,7 +15,7 @@ end
15
15
  # @step_input element_id [String] The locator id
16
16
  # @step_input timeout [Int] The number of seconds to wait before timing out
17
17
  Given('the element {string} is present within {int} seconds') do |element_id, timeout|
18
- present = Maze.driver.wait_for_element(element_id, timeout)
18
+ present = Maze::Api::Appium::UiManager.new.wait_for_element(element_id, timeout)
19
19
  raise Maze::Error::AppiumElementNotFoundError.new("The element #{element_id} could not be found", element_id) unless present
20
20
  end
21
21
 
@@ -24,211 +24,53 @@ end
24
24
  #
25
25
  # @step_input element_id [String] The locator id
26
26
  When('I click the element {string}') do |element_id|
27
- Maze.driver.click_element(element_id)
27
+ Maze::Api::Appium::UiManager.new.click_element(element_id)
28
28
  end
29
29
 
30
- # Sends the app to the background indefinitely
31
- # Requires a running Appium driver
32
- When('I send the app to the background') do
33
- Maze.driver.background_app(-1)
34
- end
35
-
36
- # Sends the app to the background for a number of seconds
30
+ # Clicks a given element if present
37
31
  # Requires a running Appium driver
38
32
  #
39
- # @step_input timeout [Integer] The amount of time the app is in the background in seconds
40
- When('I send the app to the background for {int} second(s)') do |timeout|
41
- Maze.driver.background_app(timeout)
33
+ # @step_input element_id [String] The locator id
34
+ When('I click the element {string} if present') do |element_id|
35
+ Maze::Api::Appium::UiManager.new.click_element_if_present(element_id)
42
36
  end
43
37
 
44
- # Clears a given element
38
+ # Touches the screen at the given coordinates
45
39
  # Requires a running Appium driver
46
40
  #
47
41
  # @step_input element_id [String] The locator id
48
- When('I clear the element {string}') do |element_id|
49
- Maze.driver.clear_element(element_id)
42
+ When('I touch the screen at {int},{int}') do |x, y|
43
+ Maze::Api::Appium::UiManager.new.touch_at(x, y)
50
44
  end
51
45
 
52
- # Sends keys to a given element
46
+ # Touches the screen at the given coordinates a number of times
53
47
  # Requires a running Appium driver
54
48
  #
55
- # @step_input keys [String] The keys to send to the element
56
49
  # @step_input element_id [String] The locator id
57
- When('I send the keys {string} to the element {string}') do |keys, element_id|
58
- Maze.driver.send_keys_to_element(element_id, keys)
50
+ When('I touch the screen at {int},{int} {int} time(s)') do |x, y, times|
51
+ times.times do
52
+ Maze::Api::Appium::UiManager.new.touch_at(x, y)
53
+ sleep 1
54
+ end
59
55
  end
60
56
 
61
- # Set the device orientation to either portrait or landscape
57
+ # Sends the app to the background indefinitely
62
58
  # Requires a running Appium driver
63
- When('I set the device orientation to {orientation}') do |orientation|
64
- Maze.driver.set_rotation orientation
65
- end
66
-
67
- # Tests that the given payload value is correct for the target BrowserStack platform.
68
- # This step will assume the expected and payload values are strings.
69
- # If the step is invoked when a remote BrowserStack device is not in use this step will fail.
70
- #
71
- # The DataTable used for this step should have `ios` and `android` in the same row as their expected value:
72
- # | android | Java.lang.RuntimeException |
73
- # | ios | NSException |
74
- #
75
- # If the expected value is set to "@skip", the check should be skipped
76
- # If the expected value is set to "@null", the check will be for null
77
- # If the expected value is set to "@not_null", the check will be for a non-null value
78
- #
79
- # @step_input request_type [String] The type of request (error, session, build, etc)
80
- # @step_input field_path [String] The field to test
81
- # @step_input platform_values [DataTable] A table of acceptable values for each platform
82
- Then('the {request_type} payload field {string} equals the platform-dependent string:') do |request_type, field_path, platform_values|
83
- test_string_platform_values(request_type, field_path, platform_values)
84
- end
85
-
86
- # See `the error payload field {string} equals the platform-dependent string:`
87
- #
88
- # @step_input field_path [String] The field to test, prepended with "events.0"
89
- # @step_input platform_values [DataTable] A table of acceptable values for each platform
90
- Then('the event {string} equals the platform-dependent string:') do |field_path, platform_values|
91
- test_string_platform_values('error', "events.0.#{field_path}", platform_values)
92
- end
93
-
94
- # Tests that the given payload value is correct for the target BrowserStack platform.
95
- # This step will assume the expected and payload values are numeric.
96
- # If the step is invoked when a remote BrowserStack device is not in use this step will fail.
97
- #
98
- # The DataTable used for this step should have `ios` and `android` in the same row as their expected value:
99
- # | android | 1 |
100
- # | ios | 5.5 |
101
- #
102
- # If the expected value is set to "@skip", the check should be skipped
103
- # If the expected value is set to "@null", the check will be for null
104
- # If the expected value is set to "@not_null", the check will be for a non-null value
105
- #
106
- # @step_input request_type [String] The type of request (error, session, build, etc)
107
- # @step_input field_path [String] The field to test
108
- # @step_input platform_values [DataTable] A table of acceptable values for each platform
109
- Then('the {request_type} payload field {string} equals the platform-dependent numeric:') do |request_type, field_path, platform_values|
110
- test_numeric_platform_values(request_type, field_path, platform_values)
111
- end
112
-
113
- # See `the payload field {string} equals the platform-dependent numeric:`
114
- #
115
- # @step_input field_path [String] The field to test, prepended with "events.0"
116
- # @step_input platform_values [DataTable] A table of acceptable values for each platform
117
- Then('the event {string} equals the platform-dependent numeric:') do |field_path, platform_values|
118
- test_numeric_platform_values('error', "events.0.#{field_path}", platform_values)
119
- end
120
-
121
- # Tests that the given payload value is correct for the target BrowserStack platform.
122
- # This step will assume the expected and payload values are booleans.
123
- # If the step is invoked when a remote BrowserStack device is not in use this step will fail.
124
- #
125
- # The DataTable used for this step should have `ios` and `android` in the same row as their expected value:
126
- # | android | 1 |
127
- # | ios | 5 |
128
- #
129
- # If the expected value is set to "@skip", the check should be skipped
130
- # If the expected value is set to "@null", the check will be for null
131
- # If the expected value is set to "@not_null", the check will be for a non-null value
132
- #
133
- # @step_input request_type [String] The type of request (error, session, build, etc)
134
- # @step_input field_path [String] The field to test
135
- # @step_input platform_values [DataTable] A table of acceptable values for each platform
136
- Then('the {request_type} payload field {string} equals the platform-dependent boolean:') do |request_type, field_path, platform_values|
137
- test_boolean_platform_values(request_type, field_path, platform_values)
138
- end
139
-
140
- # See `the payload field {string} equals the platform-dependent boolean:`
141
- #
142
- # @step_input field_path [String] The field to test, prepended with "events.0"
143
- # @step_input platform_values [DataTable] A table of acceptable values for each platform
144
- Then('the event {string} equals the platform-dependent boolean:') do |field_path, platform_values|
145
- test_boolean_platform_values('error', "events.0.#{field_path}", platform_values)
146
- end
147
-
148
- # See `the payload field {string} equals the platform-dependent string:`
149
- #
150
- # @step_input field_path [String] The field to test, prepended with "events.0.exceptions.0."
151
- # @step_input platform_values [DataTable] A table of acceptable values for each platform
152
- Then('the exception {string} equals the platform-dependent string:') do |field_path, platform_values|
153
- test_string_platform_values('error', "events.0.exceptions.0.#{field_path}", platform_values)
154
- end
155
-
156
- # See `the payload field {string} equals the platform-dependent string:`
157
- #
158
- # @step_input field_path [String] The field to test, prepended with "events.0.exceptions.0.stacktrace.#!{num}"
159
- # @step_input num [Integer] The index of the stack frame to test
160
- # @step_input platform_values [DataTable] A table of acceptable values for each platform
161
- Then('the {string} of stack frame {int} equals the platform-dependent string:') do |field_path, num, platform_values|
162
- test_string_platform_values('error', "events.0.exceptions.0.stacktrace.#{num}.#{field_path}", platform_values)
59
+ When('I send the app to the background') do
60
+ Maze::Api::Appium::AppManager.new.background(-1)
163
61
  end
164
62
 
165
- # Sends keys to a given element, clearing it first
63
+ # Sends the app to the background for a number of seconds
166
64
  # Requires a running Appium driver
167
65
  #
168
- # @step_input keys [String] The keys to send to the element
169
- # @step_input element_id [String] The locator id
170
- When('I clear and send the keys {string} to the element {string}') do |keys, element_id|
171
- Maze.driver.clear_and_send_keys_to_element(element_id, keys)
172
- end
173
-
174
- def get_expected_platform_value(platform_values)
175
- os = Maze::Helper.get_current_platform
176
- expected_value = Hash[platform_values.raw][os.downcase]
177
- raise("There is no expected value for the current platform \"#{os}\"") if expected_value.nil?
178
-
179
- expected_value
180
- end
181
-
182
- def should_skip_platform_check(expected_value)
183
- expected_value.eql?('@skip')
184
- end
185
-
186
- def test_string_platform_values(request_type, field_path, platform_values)
187
- expected_value = get_expected_platform_value(platform_values)
188
- return if should_skip_platform_check(expected_value)
189
-
190
- list = Maze::Server.list_for(request_type)
191
- payload_value = Maze::Helper.read_key_path(list.current[:body], field_path)
192
- assert_equal_with_nullability(expected_value, payload_value)
193
- end
194
-
195
- def test_boolean_platform_values(request_type, field_path, platform_values)
196
- expected_value = get_expected_platform_value(platform_values)
197
- return if should_skip_platform_check(expected_value)
198
-
199
- expected_bool = case expected_value.downcase
200
- when 'true'
201
- true
202
- when 'false'
203
- false
204
- else
205
- expected_value
206
- end
207
- list = Maze::Server.list_for(request_type)
208
- payload_value = Maze::Helper.read_key_path(list.current[:body], field_path)
209
- assert_equal_with_nullability(expected_bool, payload_value)
66
+ # @step_input timeout [Integer] The amount of time the app is in the background in seconds
67
+ When('I send the app to the background for {int} second(s)') do |timeout|
68
+ Maze::Api::Appium::AppManager.new.background(timeout)
210
69
  end
211
70
 
212
- def test_numeric_platform_values(request_type, field_path, platform_values)
213
- expected_value = get_expected_platform_value(platform_values)
214
- return if should_skip_platform_check(expected_value)
215
-
216
- list = Maze::Server.list_for(request_type)
217
- payload_value = Maze::Helper.read_key_path(list.current[:body], field_path)
218
-
219
- # Need to do a little more processing here to allow floats
220
- special_value = expected_value.eql?('@null') || expected_value.eql?('@not_null')
221
- expectation = special_value ? expected_value : expected_value.to_f
222
- assert_equal_with_nullability(expectation, payload_value)
71
+ # Set the device orientation to either portrait or landscape
72
+ # Requires a running Appium driver
73
+ When('I set the device orientation to {orientation}') do |orientation|
74
+ Maze::Api::Appium::DeviceManager.new.set_rotation orientation
223
75
  end
224
76
 
225
- def assert_equal_with_nullability(expected_value, payload_value)
226
- case expected_value
227
- when '@null'
228
- Maze.check.nil(payload_value)
229
- when '@not_null'
230
- Maze.check.not_nil(payload_value)
231
- else
232
- Maze.check.equal(expected_value, payload_value)
233
- end
234
- end
@@ -74,7 +74,7 @@ end
74
74
  # @step_input json_fixture [String] A path to the JSON fixture to compare against
75
75
  Then('the event contains a breadcrumb matching the JSON fixture in {string}') do |json_fixture|
76
76
  breadcrumbs = Maze::Helper.read_key_path(Maze::Server.errors.current[:body], 'events.0.breadcrumbs')
77
- expected = JSON.parse(open(json_fixture, &:read))
77
+ expected = JSON.parse(File.open(json_fixture, &:read))
78
78
  match = breadcrumbs.any? { |breadcrumb| Maze::Compare.value(expected, breadcrumb).equal? }
79
79
  Maze.check.true(match, 'No breadcrumbs in the event matched the given breadcrumb')
80
80
  end
@@ -8,6 +8,10 @@ When('I navigate to the URL {string}') do |path|
8
8
  $logger.error("#{exception.class} occurred during navigation attempt with message: #{exception.message}")
9
9
  $logger.error("Restarting driver and retrying navigation to: #{path}")
10
10
  Maze.driver.restart_driver
11
+ if Maze.config.reset_on_navigation_failure
12
+ $logger.info 'Resetting request lists as Maze.config.reset_on_navigation_failure is set'
13
+ Maze::Server.reset!
14
+ end
11
15
  Maze.driver.navigate.to path
12
16
  # If a further error occurs it will get thrown as normal
13
17
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @!group Error config steps
4
+
5
+ #
6
+ # Shortcut to waiting to receive requests for error configs
7
+ #
8
+ # @step_input count [Integer] Number of error config requests expected
9
+ Then('I wait for {int} error config(s) to be requested') do |count|
10
+ step "I wait to receive #{count} error config requests"
11
+ end
12
+
13
+ Then('I prepare an error config with:') do |table|
14
+ Maze.check.equal(%w[type name value], table.column_names, 'Error config table expects column headers "type", "name" and "value"')
15
+ ErrorConfigSupport.prepare_error_config(table.hashes)
16
+ end
@@ -136,14 +136,6 @@ Then('the event {string} equals {float} to {int} decimal place(s)') do |field, f
136
136
  step "the error payload field \"events.0.#{field}\" equals #{float_value} to #{places} decimal places"
137
137
  end
138
138
 
139
- # Tests whether a value in the first event entry equals an integer.
140
- #
141
- # @step_input field [String] The relative location of the value to test
142
- # @step_input value [Integer] The integer to test against
143
- Then('the event {string} equals {int}') do |field, value|
144
- step "the error payload field \"events.0.#{field}\" equals #{value}"
145
- end
146
-
147
139
  # Tests whether a value in the first event entry starts with a string.
148
140
  #
149
141
  # @step_input field [String] The relative location of the value to test
@@ -78,7 +78,7 @@ Then('the {request_type} multipart body does not match the JSON file in {string}
78
78
  payload_list = Maze::Server.list_for request_type
79
79
  raw_payload_value = payload_list.current[:body]
80
80
  payload_value = parse_multipart_body(raw_payload_value)
81
- expected_value = JSON.parse(open(json_path, &:read))
81
+ expected_value = JSON.parse(File.open(json_path, &:read))
82
82
  result = Maze::Compare.value(expected_value, payload_value)
83
83
  Maze.check.false(result.equal?, "Payload:\n#{payload_value}\nExpected:#{expected_value}")
84
84
  end
@@ -93,7 +93,7 @@ Then('the {request_type} multipart body matches the JSON file in {string}') do |
93
93
  payload_list = Maze::Server.list_for request_type
94
94
  raw_payload_value = payload_list.current[:body]
95
95
  payload_value = parse_multipart_body(raw_payload_value)
96
- expected_value = JSON.parse(open(json_path, &:read))
96
+ expected_value = JSON.parse(File.open(json_path, &:read))
97
97
  result = Maze::Compare.value(expected_value, payload_value)
98
98
  Maze.check.true(result.equal?, "The payload field '#{result.keypath}' does not match the fixture:\n #{result.reasons.join('\n')}")
99
99
  end
@@ -108,7 +108,7 @@ Then('the {request_type} multipart field {string} matches the JSON file in {stri
108
108
  Maze.check.true(File.exist?(json_path), "'#{json_path}' does not exist")
109
109
  payload_list = Maze::Server.list_for request_type
110
110
  payload_value = JSON.parse(payload_list.current[:body][field_path].to_s)
111
- expected_value = JSON.parse(open(json_path, &:read))
111
+ expected_value = JSON.parse(File.open(json_path, &:read))
112
112
  result = Maze::Compare.value(expected_value, payload_value)
113
113
  Maze.check.true(result.equal?, "The multipart field '#{result.keypath}' does not match the fixture:\n #{result.reasons.join('\n')}")
114
114
  end
@@ -95,7 +95,7 @@ end
95
95
  # @step_input url [String] The URL to open.
96
96
  When('I open the URL {string}') do |url|
97
97
  begin
98
- URI.open(url, &:read)
98
+ URI(url).open(&:read)
99
99
  rescue OpenURI::HTTPError
100
100
  $logger.debug $!.inspect
101
101
  end
@@ -8,7 +8,7 @@
8
8
  # @step_input fixture_path [String] Path to a JSON fixture
9
9
  Then('the {request_type} payload body does not match the JSON fixture in {string}') do |request_type, fixture_path|
10
10
  payload_value = Maze::Server.list_for(request_type).current[:body]
11
- expected_value = JSON.parse(open(fixture_path, &:read))
11
+ expected_value = JSON.parse(File.open(fixture_path, &:read))
12
12
  result = Maze::Compare.value(expected_value, payload_value)
13
13
  Maze.check.false(result.equal?, "Payload:\n#{payload_value}\nExpected:#{expected_value}")
14
14
  end
@@ -19,7 +19,7 @@ end
19
19
  # @step_input fixture_path [String] Path to a JSON fixture
20
20
  Then('the {request_type} payload body matches the JSON fixture in {string}') do |request_type, fixture_path|
21
21
  payload_value = Maze::Server.list_for(request_type).current[:body]
22
- expected_value = JSON.parse(open(fixture_path, &:read))
22
+ expected_value = JSON.parse(File.open(fixture_path, &:read))
23
23
  result = Maze::Compare.value(expected_value, payload_value)
24
24
  Maze.check.true(result.equal?,
25
25
  "The payload field '#{result.keypath}' does not match the fixture:\n #{result.reasons.join('\n')}")
@@ -34,7 +34,7 @@ Then('the {request_type}(|a b) payload field {string} matches the JSON fixture i
34
34
  do |request_type, field_path, fixture_path|
35
35
  list = Maze::Server.list_for(request_type)
36
36
  payload_value = Maze::Helper.read_key_path(list.current[:body], field_path)
37
- expected_value = JSON.parse(open(fixture_path, &:read))
37
+ expected_value = JSON.parse(File.open(fixture_path, &:read))
38
38
  result = Maze::Compare.value(expected_value, payload_value)
39
39
  Maze.check.true(result.equal?,
40
40
  "The payload field '#{result.keypath}' does not match the fixture:\n #{result.reasons.join('\n')}")
@@ -76,16 +76,6 @@ Then('the {request_type} payload field {string} is not null') do |request_type,
76
76
  Maze.check.not_nil(Maze::Helper.read_key_path(list.current[:body], field_path))
77
77
  end
78
78
 
79
- # Tests that a payload element equals an integer.
80
- #
81
- # @step_input request_type [String] The type of request (error, session, build, etc)
82
- # @step_input field_path [String] Path to the tested element
83
- # @step_input int_value [Integer] The value to test against
84
- Then('the {request_type} payload field {string} equals {int}') do |request_type, field_path, int_value|
85
- Maze.check.equal(int_value,
86
- Maze::Helper.read_key_path(Maze::Server.list_for(request_type).current[:body], field_path))
87
- end
88
-
89
79
  # Tests that a payload element equals a float.
90
80
  #
91
81
  # @step_input request_type [String] The type of request (error, session, build, etc)
@@ -0,0 +1,204 @@
1
+ # @!group Platform dependent steps
2
+
3
+ # Tests that the given payload value is correct for the target BrowserStack platform.
4
+ # This step will assume the expected and payload values are strings.
5
+ # If the step is invoked when a remote BrowserStack device is not in use this step will fail.
6
+ #
7
+ # The DataTable used for this step should have `ios` and `android` in the same row as their expected value:
8
+ # | android | Java.lang.RuntimeException |
9
+ # | ios | NSException |
10
+ #
11
+ # If the expected value is set to "@skip", the check should be skipped
12
+ # If the expected value is set to "@null", the check will be for null
13
+ # If the expected value is set to "@not_null", the check will be for a non-null value
14
+ #
15
+ # @step_input request_type [String] The type of request (error, session, build, etc)
16
+ # @step_input field_path [String] The field to test
17
+ # @step_input platform_values [DataTable] A table of acceptable values for each platform
18
+ Then('the {request_type} payload field {string} equals the platform-dependent string:') do |request_type, field_path, platform_values|
19
+ test_string_platform_values(request_type, field_path, platform_values)
20
+ end
21
+
22
+ # See `the error payload field {string} equals the platform-dependent string:`
23
+ #
24
+ # @step_input field_path [String] The field to test, prepended with "events.0"
25
+ # @step_input platform_values [DataTable] A table of acceptable values for each platform
26
+ Then('the event {string} equals the platform-dependent string:') do |field_path, platform_values|
27
+ test_string_platform_values('error', "events.0.#{field_path}", platform_values)
28
+ end
29
+
30
+ # Tests that the given payload value is correct for the target BrowserStack platform.
31
+ # This step will assume the expected and payload values are numeric.
32
+ # If the step is invoked when a remote BrowserStack device is not in use this step will fail.
33
+ #
34
+ # The DataTable used for this step should have `ios` and `android` in the same row as their expected value:
35
+ # | android | 1 |
36
+ # | ios | 5.5 |
37
+ #
38
+ # If the expected value is set to "@skip", the check should be skipped
39
+ # If the expected value is set to "@null", the check will be for null
40
+ # If the expected value is set to "@not_null", the check will be for a non-null value
41
+ #
42
+ # @step_input request_type [String] The type of request (error, session, build, etc)
43
+ # @step_input field_path [String] The field to test
44
+ # @step_input platform_values [DataTable] A table of acceptable values for each platform
45
+ Then('the {request_type} payload field {string} equals the platform-dependent numeric:') do |request_type, field_path, platform_values|
46
+ test_numeric_platform_values(request_type, field_path, platform_values)
47
+ end
48
+
49
+ # See `the payload field {string} equals the platform-dependent numeric:`
50
+ #
51
+ # @step_input field_path [String] The field to test, prepended with "events.0"
52
+ # @step_input platform_values [DataTable] A table of acceptable values for each platform
53
+ Then('the event {string} equals the platform-dependent numeric:') do |field_path, platform_values|
54
+ test_numeric_platform_values('error', "events.0.#{field_path}", platform_values)
55
+ end
56
+
57
+ # Tests that the given payload value is correct for the target BrowserStack platform.
58
+ # This step will assume the expected and payload values are booleans.
59
+ # If the step is invoked when a remote BrowserStack device is not in use this step will fail.
60
+ #
61
+ # The DataTable used for this step should have `ios` and `android` in the same row as their expected value:
62
+ # | android | 1 |
63
+ # | ios | 5 |
64
+ #
65
+ # If the expected value is set to "@skip", the check should be skipped
66
+ # If the expected value is set to "@null", the check will be for null
67
+ # If the expected value is set to "@not_null", the check will be for a non-null value
68
+ #
69
+ # @step_input request_type [String] The type of request (error, session, build, etc)
70
+ # @step_input field_path [String] The field to test
71
+ # @step_input platform_values [DataTable] A table of acceptable values for each platform
72
+ Then('the {request_type} payload field {string} equals the platform-dependent boolean:') do |request_type, field_path, platform_values|
73
+ test_boolean_platform_values(request_type, field_path, platform_values)
74
+ end
75
+
76
+ # See `the payload field {string} equals the platform-dependent boolean:`
77
+ #
78
+ # @step_input field_path [String] The field to test, prepended with "events.0"
79
+ # @step_input platform_values [DataTable] A table of acceptable values for each platform
80
+ Then('the event {string} equals the platform-dependent boolean:') do |field_path, platform_values|
81
+ test_boolean_platform_values('error', "events.0.#{field_path}", platform_values)
82
+ end
83
+
84
+ # See `the payload field {string} equals the platform-dependent string:`
85
+ #
86
+ # @step_input field_path [String] The field to test, prepended with "events.0.exceptions.0."
87
+ # @step_input platform_values [DataTable] A table of acceptable values for each platform
88
+ Then('the exception {string} equals the platform-dependent string:') do |field_path, platform_values|
89
+ test_string_platform_values('error', "events.0.exceptions.0.#{field_path}", platform_values)
90
+ end
91
+
92
+ # See `the payload field {string} equals the platform-dependent string:`
93
+ #
94
+ # @step_input field_path [String] The field to test, prepended with "events.0.exceptions.0.stacktrace.#!{num}"
95
+ # @step_input num [Integer] The index of the stack frame to test
96
+ # @step_input platform_values [DataTable] A table of acceptable values for each platform
97
+ Then('the {string} of stack frame {int} equals the platform-dependent string:') do |field_path, num, platform_values|
98
+ test_string_platform_values('error', "events.0.exceptions.0.stacktrace.#{num}.#{field_path}", platform_values)
99
+ end
100
+
101
+ #
102
+ # Equality check routines
103
+ #
104
+ def test_string_platform_values(request_type, field_path, platform_values)
105
+ expected_value = get_expected_platform_value(platform_values)
106
+ return if should_skip_platform_check(expected_value)
107
+
108
+ list = Maze::Server.list_for(request_type)
109
+ payload_value = Maze::Helper.read_key_path(list.current[:body], field_path)
110
+ assert_equal_with_nullability(expected_value, payload_value)
111
+ end
112
+
113
+ def test_boolean_platform_values(request_type, field_path, platform_values)
114
+ expected_value = get_expected_platform_value(platform_values)
115
+ return if should_skip_platform_check(expected_value)
116
+
117
+ expected_bool = case expected_value.downcase
118
+ when 'true'
119
+ true
120
+ when 'false'
121
+ false
122
+ else
123
+ expected_value
124
+ end
125
+ list = Maze::Server.list_for(request_type)
126
+ payload_value = Maze::Helper.read_key_path(list.current[:body], field_path)
127
+ assert_equal_with_nullability(expected_bool, payload_value)
128
+ end
129
+
130
+ def test_numeric_platform_values(request_type, field_path, platform_values)
131
+ expected_value = get_expected_platform_value(platform_values)
132
+ return if should_skip_platform_check(expected_value)
133
+
134
+ list = Maze::Server.list_for(request_type)
135
+ payload_value = Maze::Helper.read_key_path(list.current[:body], field_path)
136
+
137
+ # Need to do a little more processing here to allow floats
138
+ special_value = expected_value.eql?('@null') || expected_value.eql?('@not_null')
139
+ expectation = special_value ? expected_value : expected_value.to_f
140
+ assert_equal_with_nullability(expectation, payload_value)
141
+ end
142
+
143
+ def assert_equal_with_nullability(expected_value, payload_value)
144
+ case expected_value
145
+ when '@null'
146
+ Maze.check.nil(payload_value)
147
+ when '@not_null'
148
+ Maze.check.not_nil(payload_value)
149
+ else
150
+ Maze.check.equal(expected_value, payload_value)
151
+ end
152
+ end
153
+
154
+ def get_expected_platform_value(platform_values)
155
+ os = Maze::Helper.get_current_platform
156
+ expected_value = Hash[platform_values.raw][os.downcase]
157
+ raise("There is no expected value for the current platform \"#{os}\"") if expected_value.nil?
158
+
159
+ expected_value
160
+ end
161
+
162
+ def should_skip_platform_check(expected_value)
163
+ expected_value.eql?('@skip')
164
+ end
165
+
166
+ # @step_input request_type [String] The type of request (error, session, build, etc)
167
+ # @step_input field_path [String] The field to test
168
+ # @step_input platform_values [DataTable] A table of acceptable regexes for each platform
169
+ Then('the {request_type} payload field {string} matches the platform-dependent regex:') do |request_type, field_path, platform_regexes|
170
+ match_string_platform_regexes(request_type, field_path, platform_regexes)
171
+ end
172
+
173
+ # See `the error payload field {string} equals the platform-dependent string:`
174
+ #
175
+ # @step_input field_path [String] The field to test, prepended with "events.0"
176
+ # @step_input platform_values [DataTable] A table of acceptable values for each platform
177
+ Then('the event {string} matches the platform-dependent regex:') do |field_path, platform_regexes|
178
+ match_string_platform_regexes('error', "events.0.#{field_path}", platform_regexes)
179
+ end
180
+
181
+ # @step_input field_path [String] The field to test, prepended with "events.0.exceptions.0."
182
+ # @step_input platform_values [DataTable] A table of acceptable regexes for each platform
183
+ Then('the exception {string} matches the platform-dependent regex:') do |field_path, platform_regexes|
184
+ match_string_platform_regexes('error', "events.0.exceptions.0.#{field_path}", platform_regexes)
185
+ end
186
+
187
+ # @step_input field_path [String] The field to test, prepended with "events.0.exceptions.0.stacktrace.#!{num}"
188
+ # @step_input num [Integer] The index of the stack frame to test
189
+ # @step_input platform_values [DataTable] A table of acceptable values for each platform
190
+ Then('the {string} of stack frame {int} matches the platform-dependent regex:') do |field_path, num, platform_regexes|
191
+ match_string_platform_regexes('error', "events.0.exceptions.0.stacktrace.#{num}.#{field_path}", platform_regexes)
192
+ end
193
+
194
+ #
195
+ # Regex match routines
196
+ #
197
+ def match_string_platform_regexes(request_type, field_path, platform_values)
198
+ expected_regex = get_expected_platform_value(platform_values)
199
+ return if should_skip_platform_check(expected_regex)
200
+ list = Maze::Server.list_for(request_type)
201
+ payload_value = Maze::Helper.read_key_path(list.current[:body], field_path)
202
+
203
+ Maze.check.match(expected_regex, payload_value)
204
+ end
@@ -29,16 +29,24 @@ def assert_received_requests(request_count, list, list_name, precise = true, max
29
29
  count_now >= request_count
30
30
  end
31
31
 
32
+ invalid_requests = Maze::Server.invalid_requests.size_remaining
33
+ invalid_requests_message = if invalid_requests > 0
34
+ "\nNote: #{invalid_requests} invalid requests have been received in this scenario.\n"
35
+ else
36
+ ""
37
+ end
38
+
32
39
  unless received
33
40
  raise Test::Unit::AssertionFailedError.new <<-MESSAGE
34
- Expected #{request_count} #{list_name} but received #{list.size_remaining} within the #{timeout}s timeout.
35
- This could indicate that:
36
- - Bugsnag crashed with a fatal error.
37
- - Bugsnag did not make the requests that it should have done.
38
- - The requests were made, but not deemed to be valid (e.g. missing integrity header).
39
- - The requests made were prevented from being received due to a network or other infrastructure issue.
40
- Please check the Maze Runner and device logs to confirm.)
41
- MESSAGE
41
+ Expected #{request_count} #{list_name} but received #{list.size_remaining} within the #{timeout}s timeout.
42
+ #{invalid_requests_message}
43
+ This could indicate that:
44
+ - Bugsnag crashed with a fatal error.
45
+ - Bugsnag did not make the requests that it should have done.
46
+ - The requests were made, but not deemed to be valid (e.g. missing integrity header).
47
+ - The requests made were prevented from being received due to a network or other infrastructure issue.
48
+ Please check the Maze Runner and device logs to confirm.
49
+ MESSAGE
42
50
  end
43
51
 
44
52
  if precise
@@ -131,6 +139,15 @@ Then('I discard the oldest {request_type}') do |request_type|
131
139
  Maze::Server.list_for(request_type).next
132
140
  end
133
141
 
142
+ # Moves to the end of the request list
143
+ #
144
+ # @step_input request_type [String] The type of request (error, session, build, etc)
145
+ Then('I discard all {request_type}') do |request_type|
146
+ raise "No #{request_type} to discard" if Maze::Server.list_for(request_type).current.nil?
147
+
148
+ Maze::Server.list_for(request_type).end
149
+ end
150
+
134
151
  Then('the received errors match:') do |table|
135
152
  # Checks that each request matches one of the event fields
136
153
  requests = Maze::Server.errors.remaining
@@ -149,3 +166,17 @@ Then('the received errors match:') do |table|
149
166
  end
150
167
  Maze.check.equal(requests.size, match_count, 'Unexpected number of requests matched the received payloads')
151
168
  end
169
+
170
+ # Verifies that a request was sent via a given method.
171
+ # Currently only supported with the reflective servlet.
172
+ #
173
+ # @step_input request_type [String] The type of request (error, session, build, etc)
174
+ # @step_input method [String] The request method expected (GET, POST, etc)
175
+ Then('the {request_type} request method equals {string}') do |request_type, method|
176
+ list = Maze::Server.list_for(request_type)
177
+ payload = list.current
178
+ if payload[:method].nil?
179
+ raise Test::Unit::AssertionFailedError.new("#{request_type} request had no receipt method listed")
180
+ end
181
+ Maze.check.equal(method, payload[:method], "Expected #{request_type} request method to be #{method}")
182
+ end