ruby_raider 3.13.0 → 4.0.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.
Files changed (239) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ffmpeg/build.sh +208 -0
  3. data/.github/ffmpeg/check.sh +72 -0
  4. data/.github/ffmpeg/frames.rb +34 -0
  5. data/.github/ffmpeg/probe.sh +17 -0
  6. data/.github/workflows/ffmpeg.yml +160 -0
  7. data/.github/workflows/runtime.yml +38 -0
  8. data/.github/workflows/system_tests.yml +1 -23
  9. data/.reek.yml +1 -0
  10. data/.rspec +1 -0
  11. data/Gemfile +2 -0
  12. data/README.md +172 -70
  13. data/RELEASE.md +29 -0
  14. data/bin/raider +5 -0
  15. data/lib/commands/scaffolding_commands.rb +2 -25
  16. data/lib/commands/utility_commands.rb +23 -3
  17. data/lib/generators/automation/automation_generator.rb +0 -5
  18. data/lib/generators/automation/templates/component.tt +1 -0
  19. data/lib/generators/automation/templates/home.tt +2 -2
  20. data/lib/generators/automation/templates/login.tt +6 -26
  21. data/lib/generators/automation/templates/page.tt +23 -18
  22. data/lib/generators/automation/templates/partials/home_page_selector.tt +1 -2
  23. data/lib/generators/automation/templates/partials/initialize_selector.tt +0 -8
  24. data/lib/generators/automation/templates/partials/pdp_page_selector.tt +1 -2
  25. data/lib/generators/automation/templates/partials/url_methods.tt +8 -2
  26. data/lib/generators/automation/templates/partials/visit_method.tt +0 -5
  27. data/lib/generators/automation/templates/pdp.tt +1 -9
  28. data/lib/generators/common_generator.rb +0 -2
  29. data/lib/generators/generator.rb +12 -19
  30. data/lib/generators/helper_generator.rb +21 -19
  31. data/lib/generators/infrastructure/templates/azure_pipelines.tt +1 -1
  32. data/lib/generators/infrastructure/templates/github.tt +2 -3
  33. data/lib/generators/infrastructure/templates/github_appium.tt +0 -8
  34. data/lib/generators/invoke_generators.rb +4 -23
  35. data/lib/generators/menu_generator.rb +1 -9
  36. data/lib/generators/rspec/templates/accessibility_spec.tt +1 -9
  37. data/lib/generators/rspec/templates/spec.tt +8 -24
  38. data/lib/generators/template_renderer/partial_cache.rb +3 -1
  39. data/lib/generators/template_renderer.rb +1 -1
  40. data/lib/generators/templates/common/gemfile.tt +3 -10
  41. data/lib/generators/templates/common/git_ignore.tt +0 -5
  42. data/lib/generators/templates/common/partials/mobile_config.tt +3 -1
  43. data/lib/generators/templates/common/partials/web_config.tt +10 -1
  44. data/lib/generators/templates/common/rakefile.tt +0 -15
  45. data/lib/generators/templates/common/read_me.tt +363 -257
  46. data/lib/generators/templates/common/rubocop.tt +0 -2
  47. data/lib/generators/templates/helpers/driver_helper.tt +8 -0
  48. data/lib/generators/templates/helpers/gesture_helper.tt +78 -0
  49. data/lib/generators/templates/helpers/network_helper.tt +521 -0
  50. data/lib/generators/templates/helpers/partials/quit_driver.tt +0 -2
  51. data/lib/generators/templates/helpers/partials/screenshot.tt +0 -2
  52. data/lib/generators/templates/helpers/partials/selenium_driver.tt +5 -2
  53. data/lib/generators/templates/helpers/screenshot_helper.tt +490 -0
  54. data/lib/generators/templates/helpers/spec_helper.tt +39 -29
  55. data/lib/generators/templates/helpers/trace_helper.tt +240 -95
  56. data/lib/generators/templates/helpers/video_helper.tt +4 -10
  57. data/lib/ruby_raider/ffmpeg.rb +38 -11
  58. data/lib/ruby_raider/runtime/actionability.rb +129 -0
  59. data/lib/ruby_raider/runtime/actionable.rb +49 -0
  60. data/lib/ruby_raider/runtime/by_role.rb +55 -0
  61. data/lib/ruby_raider/runtime/config.rb +79 -0
  62. data/lib/ruby_raider/runtime/context.rb +38 -0
  63. data/lib/ruby_raider/runtime/errors.rb +69 -0
  64. data/lib/ruby_raider/runtime/finders.rb +73 -0
  65. data/lib/ruby_raider/runtime/js/actionability.js +134 -0
  66. data/lib/ruby_raider/runtime/js/role_engine.js +315 -0
  67. data/lib/ruby_raider/runtime/locator_converter.rb +72 -0
  68. data/lib/ruby_raider/runtime/matchers/base.rb +222 -0
  69. data/lib/ruby_raider/runtime/matchers/element.rb +183 -0
  70. data/lib/ruby_raider/runtime/matchers/page.rb +71 -0
  71. data/lib/ruby_raider/runtime/matchers/presence.rb +41 -0
  72. data/lib/ruby_raider/runtime/matchers/retrying_block.rb +104 -0
  73. data/lib/ruby_raider/runtime/observer.rb +170 -0
  74. data/lib/ruby_raider/runtime/role_finder.rb +83 -0
  75. data/lib/ruby_raider/runtime/rspec.rb +78 -0
  76. data/lib/ruby_raider/runtime/selectors.rb +60 -0
  77. data/lib/ruby_raider/runtime/strict.rb +142 -0
  78. data/lib/ruby_raider/runtime/wait.rb +84 -0
  79. data/lib/ruby_raider/runtime.rb +20 -0
  80. data/lib/scaffolding/name_normalizer.rb +1 -1
  81. data/lib/scaffolding/project_detector.rb +2 -28
  82. data/lib/scaffolding/scaffolding.rb +0 -20
  83. data/lib/scaffolding/templates/component.tt +0 -14
  84. data/lib/scaffolding/templates/page_object.tt +2 -14
  85. data/lib/scaffolding/templates/spec.tt +1 -9
  86. data/lib/utilities/utilities.rb +10 -8
  87. data/lib/version +1 -1
  88. data/ruby_raider.gemspec +2 -1
  89. data/sig/commands/scaffolding_commands.rbs +0 -2
  90. data/sig/commands/utility_commands.rbs +6 -0
  91. data/sig/generators/generator.rbs +0 -4
  92. data/sig/generators/helper_generator.rbs +0 -1
  93. data/sig/generators/menu_generator.rbs +0 -1
  94. data/sig/ruby_raider/ffmpeg.rbs +1 -0
  95. data/sig/ruby_raider/runtime/actionability.rbs +25 -0
  96. data/sig/ruby_raider/runtime/actionable.rbs +13 -0
  97. data/sig/ruby_raider/runtime/by_role.rbs +15 -0
  98. data/sig/ruby_raider/runtime/config.rbs +26 -0
  99. data/sig/ruby_raider/runtime/context.rbs +12 -0
  100. data/sig/ruby_raider/runtime/errors.rbs +36 -0
  101. data/sig/ruby_raider/runtime/finders.rbs +26 -0
  102. data/sig/ruby_raider/runtime/locator_converter.rbs +21 -0
  103. data/sig/ruby_raider/runtime/matchers/base.rbs +64 -0
  104. data/sig/ruby_raider/runtime/matchers/element.rbs +78 -0
  105. data/sig/ruby_raider/runtime/matchers/page.rbs +38 -0
  106. data/sig/ruby_raider/runtime/matchers/presence.rbs +21 -0
  107. data/sig/ruby_raider/runtime/matchers/retrying_block.rbs +27 -0
  108. data/sig/ruby_raider/runtime/observer.rbs +46 -0
  109. data/sig/ruby_raider/runtime/role_finder.rbs +18 -0
  110. data/sig/ruby_raider/runtime/selectors.rbs +21 -0
  111. data/sig/ruby_raider/runtime/strict.rbs +35 -0
  112. data/sig/ruby_raider/runtime/wait.rbs +17 -0
  113. data/sig/ruby_raider/runtime.rbs +2 -0
  114. data/sig/scaffolding/project_detector.rbs +0 -4
  115. data/sig/scaffolding/scaffolding.rbs +0 -5
  116. data/sig/utilities/utilities.rbs +2 -1
  117. data/sig/vendor/selenium_webdriver.rbs +71 -0
  118. data/spec/commands/raider_commands_spec.rb +38 -3
  119. data/spec/commands/scaffolding_commands_spec.rb +27 -0
  120. data/spec/commands/utility_commands_spec.rb +53 -0
  121. data/spec/generators/gesture_helper_spec.rb +123 -0
  122. data/spec/generators/network_helper_spec.rb +634 -0
  123. data/spec/generators/screenshot_helper_spec.rb +776 -0
  124. data/spec/generators/template_renderer_spec.rb +0 -4
  125. data/spec/generators/trace_helper_spec.rb +489 -97
  126. data/spec/generators/video_helper_spec.rb +21 -13
  127. data/spec/integration/commands/browser_update_after_creation_spec.rb +0 -8
  128. data/spec/integration/commands/scaffolding_commands_spec.rb +12 -70
  129. data/spec/integration/commands/utility_commands_spec.rb +19 -41
  130. data/spec/integration/content/azure_content_spec.rb +2 -6
  131. data/spec/integration/content/ci_content_spec.rb +1 -55
  132. data/spec/integration/content/common_content_spec.rb +1 -118
  133. data/spec/integration/content/config_content_spec.rb +34 -31
  134. data/spec/integration/content/gemfile_content_spec.rb +7 -72
  135. data/spec/integration/content/helper_content_spec.rb +105 -99
  136. data/spec/integration/content/page_content_spec.rb +85 -87
  137. data/spec/integration/content/readme_content_spec.rb +141 -77
  138. data/spec/integration/content/rspec_reporter_content_spec.rb +2 -2
  139. data/spec/integration/content/rubocop_content_spec.rb +1 -1
  140. data/spec/integration/content/syntax_validation_spec.rb +2 -2
  141. data/spec/integration/content/test_content_spec.rb +23 -147
  142. data/spec/integration/end_to_end_features_spec.rb +1 -43
  143. data/spec/integration/end_to_end_spec.rb +334 -329
  144. data/spec/integration/generators/automation_generator_spec.rb +3 -37
  145. data/spec/integration/generators/axe_addon_spec.rb +2 -35
  146. data/spec/integration/generators/azure_generator_spec.rb +1 -1
  147. data/spec/integration/generators/common_generator_spec.rb +1 -40
  148. data/spec/integration/generators/config_features_spec.rb +1 -24
  149. data/spec/integration/generators/github_generator_spec.rb +0 -12
  150. data/spec/integration/generators/helpers_generator_spec.rb +74 -80
  151. data/spec/integration/generators/invoke_generators_spec.rb +54 -45
  152. data/spec/integration/generators/rspec_generator_spec.rb +0 -6
  153. data/spec/integration/scaffolding_e2e_spec.rb +17 -179
  154. data/spec/integration/spec_helper.rb +4 -6
  155. data/spec/integration/trace_format_checker.rb +11 -2
  156. data/spec/integration/trace_page_server.rb +72 -5
  157. data/spec/menus/menu_generator_spec.rb +14 -39
  158. data/spec/runtime/actionability_spec.rb +207 -0
  159. data/spec/runtime/actionable_spec.rb +125 -0
  160. data/spec/runtime/browser/actionability_script_browser_spec.rb +150 -0
  161. data/spec/runtime/browser/actionable_browser_spec.rb +98 -0
  162. data/spec/runtime/browser/finders_browser_spec.rb +148 -0
  163. data/spec/runtime/browser/matchers_browser_spec.rb +67 -0
  164. data/spec/runtime/browser/retrying_block_browser_spec.rb +37 -0
  165. data/spec/runtime/browser/role_engine_browser_spec.rb +184 -0
  166. data/spec/runtime/browser/strict_browser_spec.rb +38 -0
  167. data/spec/runtime/by_role_spec.rb +52 -0
  168. data/spec/runtime/config_spec.rb +79 -0
  169. data/spec/runtime/context_spec.rb +73 -0
  170. data/spec/runtime/errors_spec.rb +89 -0
  171. data/spec/runtime/finders_spec.rb +165 -0
  172. data/spec/runtime/fixtures/actionability.html +70 -0
  173. data/spec/runtime/fixtures/locators.html +46 -0
  174. data/spec/runtime/fixtures/matchers.html +33 -0
  175. data/spec/runtime/fixtures/roles.html +162 -0
  176. data/spec/runtime/matchers/base_spec.rb +165 -0
  177. data/spec/runtime/matchers/element_spec.rb +277 -0
  178. data/spec/runtime/matchers/page_spec.rb +102 -0
  179. data/spec/runtime/matchers/presence_spec.rb +59 -0
  180. data/spec/runtime/matchers/retrying_block_spec.rb +165 -0
  181. data/spec/runtime/observer_spec.rb +341 -0
  182. data/spec/runtime/role_finder_spec.rb +156 -0
  183. data/spec/runtime/role_query_spec.rb +75 -0
  184. data/spec/runtime/selectors_spec.rb +135 -0
  185. data/spec/runtime/strict_spec.rb +257 -0
  186. data/spec/runtime/support/browser.rb +48 -0
  187. data/spec/runtime/support/fake_bridge.rb +117 -0
  188. data/spec/runtime/wait_spec.rb +71 -0
  189. data/spec/scaffolding/name_normalizer_spec.rb +3 -2
  190. data/spec/scaffolding/scaffold_project_detector_spec.rb +4 -43
  191. data/spec/system/selenium_spec.rb +1 -5
  192. data/spec/system/support/system_test_helper.rb +2 -5
  193. data/spec/utilities/ffmpeg_spec.rb +80 -7
  194. data/spec/utilities/headless_config_spec.rb +0 -7
  195. data/spec/utilities/utilities_spec.rb +24 -0
  196. data/spec/utilities/video_command_spec.rb +13 -0
  197. metadata +118 -53
  198. data/docs/superpowers/plans/2026-10-25-failure-video-replay.md +0 -400
  199. data/docs/superpowers/plans/2026-10-26-parity-cleanup.md +0 -233
  200. data/docs/superpowers/plans/2026-10-28-failure-card.md +0 -295
  201. data/docs/superpowers/specs/2026-10-25-failure-video-replay-design.md +0 -214
  202. data/docs/superpowers/specs/2026-10-28-failure-card-design.md +0 -210
  203. data/lib/generators/automation/templates/header.tt +0 -9
  204. data/lib/generators/cucumber/cucumber_generator.rb +0 -58
  205. data/lib/generators/cucumber/templates/accessibility_feature.tt +0 -5
  206. data/lib/generators/cucumber/templates/accessibility_steps.tt +0 -17
  207. data/lib/generators/cucumber/templates/cucumber.tt +0 -1
  208. data/lib/generators/cucumber/templates/env.tt +0 -7
  209. data/lib/generators/cucumber/templates/feature.tt +0 -21
  210. data/lib/generators/cucumber/templates/partials/appium_env.tt +0 -26
  211. data/lib/generators/cucumber/templates/partials/driver_world.tt +0 -18
  212. data/lib/generators/cucumber/templates/partials/mobile_steps.tt +0 -20
  213. data/lib/generators/cucumber/templates/partials/selenium_env.tt +0 -120
  214. data/lib/generators/cucumber/templates/partials/watir_env.tt +0 -48
  215. data/lib/generators/cucumber/templates/partials/watir_world.tt +0 -4
  216. data/lib/generators/cucumber/templates/partials/web_steps.tt +0 -28
  217. data/lib/generators/cucumber/templates/steps.tt +0 -5
  218. data/lib/generators/cucumber/templates/user_factory.tt +0 -15
  219. data/lib/generators/cucumber/templates/world.tt +0 -7
  220. data/lib/generators/templates/helpers/browser_helper.tt +0 -31
  221. data/lib/generators/templates/helpers/raider_element.tt +0 -159
  222. data/lib/generators/templates/helpers/wait_helper.tt +0 -611
  223. data/lib/scaffolding/templates/feature.tt +0 -6
  224. data/lib/scaffolding/templates/steps.tt +0 -19
  225. data/sig/generators/cucumber/cucumber_generator.rbs +0 -12
  226. data/spec/fixtures/watir_master/cucumber_watir/Readme.md.snapshot +0 -175
  227. data/spec/fixtures/watir_master/cucumber_watir/features/step_definitions/login_steps.rb.snapshot +0 -24
  228. data/spec/fixtures/watir_master/cucumber_watir/page_objects/abstract/page.rb.snapshot +0 -37
  229. data/spec/fixtures/watir_master/cucumber_watir/page_objects/pages/login.rb.snapshot +0 -33
  230. data/spec/fixtures/watir_master/rspec_watir/Readme.md.snapshot +0 -174
  231. data/spec/fixtures/watir_master/rspec_watir/page_objects/abstract/page.rb.snapshot +0 -37
  232. data/spec/fixtures/watir_master/rspec_watir/page_objects/pages/login.rb.snapshot +0 -33
  233. data/spec/fixtures/watir_master/rspec_watir/spec/login_page_spec.rb.snapshot +0 -49
  234. data/spec/integration/content/cucumber_reporter_content_spec.rb +0 -161
  235. data/spec/integration/generators/cucumber_generator_spec.rb +0 -100
  236. data/spec/integration/helpers/wait_helper_mobile_spec.rb +0 -281
  237. data/spec/integration/helpers/wait_helper_spec.rb +0 -679
  238. data/spec/integration/helpers/wait_helper_support.rb +0 -183
  239. data/spec/system/watir_spec.rb +0 -38
@@ -13,7 +13,7 @@ require_relative 'trace_page_server'
13
13
  # These tests:
14
14
  # 1. Generate a complete project
15
15
  # 2. Install dependencies (bundle install)
16
- # 3. Run the generated tests (rspec/cucumber)
16
+ # 3. Run the generated tests (rspec)
17
17
  # 4. Verify tests pass
18
18
  #
19
19
  # This ensures the template system produces working, executable test frameworks
@@ -94,21 +94,6 @@ describe 'End-to-End Project Generation and Execution' do
94
94
  result
95
95
  end
96
96
 
97
- # Helper to run Cucumber tests
98
- def run_cucumber(project_name)
99
- puts "\n🥒 Running Cucumber tests in #{project_name}..."
100
- result = run_in_project(project_name, 'HEADLESS=true bundle exec cucumber features/ --format pretty', timeout: 120)
101
-
102
- puts result[:stdout] if result[:stdout].length.positive?
103
-
104
- unless result[:success]
105
- puts '❌ Cucumber tests failed:'
106
- puts result[:stderr] if result[:stderr].length.positive?
107
- end
108
-
109
- result
110
- end
111
-
112
97
  # Shared example for RSpec-based projects
113
98
  shared_examples 'executable rspec project' do |project_name|
114
99
  let(:project) { project_name }
@@ -117,10 +102,10 @@ describe 'End-to-End Project Generation and Execution' do
117
102
  expect(bundle_install(project)).to be true
118
103
  end
119
104
 
120
- it 'resolves raider_reporter 0.10+ from RubyGems and ships the raider-reporter executable', :aggregate_failures do
105
+ it 'resolves raider_reporter 1.x from RubyGems and ships the raider-reporter executable', :aggregate_failures do
121
106
  skip 'Bundle install failed' unless bundle_install(project)
122
107
 
123
- expect(File.read(File.join(project, 'Gemfile.lock'))).to match(/^ raider_reporter \(0\.1\d\.\d+\)$/)
108
+ expect(File.read(File.join(project, 'Gemfile.lock'))).to match(/^ raider_reporter \(1\.\d+\.\d+\)$/)
124
109
  result = run_in_project(project, 'bundle exec raider-reporter --help', timeout: 60)
125
110
  expect(result[:exit_code]).to eq(0), "STDOUT: #{result[:stdout]}\nSTDERR: #{result[:stderr]}"
126
111
  expect(result[:stdout] + result[:stderr]).to include('raider-reporter comment')
@@ -157,116 +142,6 @@ describe 'End-to-End Project Generation and Execution' do
157
142
  end
158
143
  end
159
144
 
160
- # Shared example for Cucumber-based projects
161
- shared_examples 'executable cucumber project' do |project_name|
162
- let(:project) { project_name }
163
-
164
- it 'installs dependencies successfully' do
165
- expect(bundle_install(project)).to be true
166
- end
167
-
168
- it 'runs generated Cucumber tests successfully', :slow do
169
- skip 'Bundle install failed' unless bundle_install(project)
170
-
171
- result = run_cucumber(project)
172
-
173
- expect(result[:success]).to be(true),
174
- "Cucumber tests failed with exit code #{result[:exit_code]}.\n" \
175
- "STDOUT: #{result[:stdout]}\n" \
176
- "STDERR: #{result[:stderr]}"
177
- end
178
-
179
- it 'resolves raider_reporter 0.10+ from RubyGems and requires its Cucumber plugin', :aggregate_failures do
180
- skip 'Bundle install failed' unless bundle_install(project)
181
-
182
- lockfile = File.read(File.join(project, 'Gemfile.lock'))
183
- expect(lockfile).to match(/^ raider_reporter \(0\.1\d\.\d+\)$/)
184
- expect(File.read(File.join(project, 'features/support/env.rb'))).to include("require 'raider_reporter/cucumber'")
185
- end
186
-
187
- it 'prints pretty output and keeps the exit status of a failing Cucumber run', :aggregate_failures, :slow do
188
- skip 'Bundle install failed' unless bundle_install(project)
189
-
190
- result = run_cucumber_with_failure(project)
191
-
192
- expect(result[:stdout]).to include('Feature: Reporter failure')
193
- expect(result[:stdout]).to include('Scenario: A deliberately failing scenario')
194
- expect(result[:stdout]).to match(/\d+ scenarios? \(\d+ failed/)
195
- expect(result[:exit_code]).to eq(1)
196
- end
197
-
198
- it 'writes rerun.txt listing only the failing scenario', :aggregate_failures, :slow do
199
- skip 'Bundle install failed' unless bundle_install(project)
200
-
201
- result = run_cucumber_with_failure(project)
202
-
203
- expect(result[:exit_code]).to eq(1)
204
- rerun = File.join(project, 'rerun.txt')
205
- expect(File).to exist(rerun)
206
- expect(File.read(rerun).strip).to eq('features/reporter_failure.feature:3')
207
- end
208
-
209
- it 'writes raider-results/run.json listing every scenario with a failing scenario screenshot',
210
- :aggregate_failures, :slow do
211
- skip 'Bundle install failed' unless bundle_install(project)
212
-
213
- result = run_cucumber_with_failure(project)
214
- summary = result[:stdout].match(/(\d+) scenarios? \((?:(\d+) failed)?/)
215
- expect(summary).not_to be_nil, "No Cucumber summary line.\nSTDOUT: #{result[:stdout]}\nSTDERR: #{result[:stderr]}"
216
-
217
- run = JSON.parse(File.read(File.join(project, 'raider-results', 'run.json')))
218
- expect(run['schema_version']).to eq(1)
219
- expect(run['results'].size).to eq(summary[1].to_i)
220
- expect(run['results'].count { |r| r['status'] == 'failed' }).to eq(summary[2].to_i)
221
-
222
- failing = run['results'].find { |r| r['full_name'] == 'Reporter failure: A deliberately failing scenario' }
223
- expect(failing).not_to be_nil, "Scenario missing from run.json: #{run['results'].map { |r| r['full_name'] }}"
224
- expect(failing['status']).to eq('failed')
225
- expect(failing['file_path']).to eq('features/reporter_failure.feature')
226
- expect(failing['failure']['message']).to start_with(
227
- 'Then the reporter records this failure (features/reporter_failure.feature:5)'
228
- )
229
- screenshot = failing['attachments'].find { |a| a['name'] == 'screenshot' }
230
- expect(screenshot).not_to be_nil, "No screenshot attachment: #{failing['attachments']}"
231
- expect(screenshot['content_type']).to eq('image/png')
232
- end
233
- end
234
-
235
- # Runs the project's features plus a deliberately failing scenario, then removes that scenario again
236
- def run_cucumber_with_failure(project)
237
- add_failing_cucumber_scenario(project)
238
- FileUtils.rm_rf([File.join(project, 'raider-results'), File.join(project, 'rerun.txt')])
239
- run_cucumber(project)
240
- ensure
241
- remove_failing_cucumber_scenario(project)
242
- end
243
-
244
- # Adds a scenario that always fails at its last step, after the browser has been started
245
- def add_failing_cucumber_scenario(project)
246
- File.write(File.join(project, 'features/reporter_failure.feature'), <<~FEATURE)
247
- Feature: Reporter failure
248
-
249
- Scenario: A deliberately failing scenario
250
- Given the reporter has a started scenario
251
- Then the reporter records this failure
252
- FEATURE
253
- File.write(File.join(project, 'features/step_definitions/reporter_failure_steps.rb'), <<~STEPS)
254
- # frozen_string_literal: true
255
-
256
- Given('the reporter has a started scenario') {}
257
-
258
- Then('the reporter records this failure') do
259
- raise 'deliberate failure for raider_reporter'
260
- end
261
- STEPS
262
- end
263
-
264
- # Keeps the deliberate failure from leaking into the other examples that share the project
265
- def remove_failing_cucumber_scenario(project)
266
- FileUtils.rm_f(File.join(project, 'features/reporter_failure.feature'))
267
- FileUtils.rm_f(File.join(project, 'features/step_definitions/reporter_failure_steps.rb'))
268
- end
269
-
270
145
  # Runs the project's own RuboCop with the gems its bundle resolved (newer than this gem's dev bundle).
271
146
  # It runs from a copy outside this repo, as a user's project would: inside it RuboCop would also read
272
147
  # this repo's .rubocop.yml, gemspec and .ruby-version.
@@ -291,6 +166,13 @@ describe 'End-to-End Project Generation and Execution' do
291
166
  expect_project_rubocop_clean('rspec_selenium')
292
167
  end
293
168
 
169
+ it 'prints the actionability notice once per run', :slow do
170
+ skip 'Bundle install failed' unless bundle_install('rspec_selenium')
171
+
172
+ result = run_rspec('rspec_selenium')
173
+ expect(result[:stderr].scan('[raider] actionability on').size).to eq(1), "STDERR: #{result[:stderr]}"
174
+ end
175
+
294
176
  it 'saves the login once and reuses it', :aggregate_failures, :slow do
295
177
  skip 'Bundle install failed' unless bundle_install('rspec_selenium')
296
178
 
@@ -314,22 +196,6 @@ describe 'End-to-End Project Generation and Execution' do
314
196
  cookie_values.select { |value| value.length >= 8 }.each { |value| expect(output).not_to include(value) }
315
197
  end
316
198
  end
317
-
318
- describe 'Watir + RSpec' do
319
- include_examples 'executable rspec project', 'rspec_watir'
320
- end
321
-
322
- describe 'Selenium + Cucumber' do
323
- include_examples 'executable cucumber project', 'cucumber_selenium'
324
-
325
- it 'passes its own RuboCop with its bundled gems', :slow do
326
- expect_project_rubocop_clean('cucumber_selenium')
327
- end
328
- end
329
-
330
- describe 'Watir + Cucumber' do
331
- include_examples 'executable cucumber project', 'cucumber_watir'
332
- end
333
199
  end
334
200
 
335
201
  # Recorded Azure Pipelines env of a push (IndividualCI) build, see raider_reporter's CiDetector specs
@@ -382,12 +248,12 @@ describe 'End-to-End Project Generation and Execution' do
382
248
  describe 'Selenium + RSpec' do
383
249
  let(:project) { generate_azure_project('rspec') }
384
250
 
385
- it 'ships azure-pipelines.yml and resolves raider_reporter 0.10+', :aggregate_failures do
251
+ it 'ships azure-pipelines.yml and resolves raider_reporter 1.x', :aggregate_failures do
386
252
  expect(File).to exist(File.join(project, 'azure-pipelines.yml'))
387
253
  expect(File).not_to exist(File.join(project, '.github/workflows'))
388
254
  skip 'Bundle install failed' unless bundle_install(project)
389
255
 
390
- expect(File.read(File.join(project, 'Gemfile.lock'))).to match(/^ raider_reporter \(0\.1\d\.\d+\)$/)
256
+ expect(File.read(File.join(project, 'Gemfile.lock'))).to match(/^ raider_reporter \(1\.\d+\.\d+\)$/)
391
257
  end
392
258
 
393
259
  it 'records provider azure_pipelines and an azure_pipelines: build key in run.json', :aggregate_failures, :slow do
@@ -400,27 +266,6 @@ describe 'End-to-End Project Generation and Execution' do
400
266
  expect_azure_ci_block(project)
401
267
  end
402
268
  end
403
-
404
- describe 'Selenium + Cucumber' do
405
- let(:project) { generate_azure_project('cucumber') }
406
-
407
- it 'ships azure-pipelines.yml and resolves raider_reporter 0.10+', :aggregate_failures do
408
- expect(File).to exist(File.join(project, 'azure-pipelines.yml'))
409
- skip 'Bundle install failed' unless bundle_install(project)
410
-
411
- expect(File.read(File.join(project, 'Gemfile.lock'))).to match(/^ raider_reporter \(0\.1\d\.\d+\)$/)
412
- end
413
-
414
- it 'records provider azure_pipelines and an azure_pipelines: build key in run.json', :aggregate_failures, :slow do
415
- skip 'Bundle install failed' unless bundle_install(project)
416
-
417
- FileUtils.rm_rf(File.join(project, 'raider-results'))
418
- result = run_in_project(project, "#{azure_env_prefix} bundle exec cucumber features/ --format pretty",
419
- timeout: 120)
420
- expect(result[:success]).to be(true), "STDOUT: #{result[:stdout]}\nSTDERR: #{result[:stderr]}"
421
- expect_azure_ci_block(project)
422
- end
423
- end
424
269
  end
425
270
 
426
271
  # An empty skeleton (examples: false) still passes its run, so its CI is green until tests are added
@@ -444,17 +289,6 @@ describe 'End-to-End Project Generation and Execution' do
444
289
  expect(result[:stdout]).to include('0 examples, 0 failures')
445
290
  end
446
291
  end
447
-
448
- it 'runs bundle exec cucumber on a selenium cucumber skeleton with 0 scenarios', :aggregate_failures do
449
- project = generate_skeleton_project('cucumber')
450
- skip 'Bundle install failed' unless bundle_install(project)
451
-
452
- ['cucumber', 'cucumber features'].each do |command|
453
- result = run_in_project(project, "bundle exec #{command}", timeout: 120)
454
- expect(result[:exit_code]).to eq(0), "#{command}\nSTDOUT: #{result[:stdout]}\nSTDERR: #{result[:stderr]}"
455
- expect(result[:stdout]).to include('0 scenarios')
456
- end
457
- end
458
292
  end
459
293
 
460
294
  # Browser e2e helpers shared by the failure video and the trace replay contexts
@@ -470,7 +304,7 @@ describe 'End-to-End Project Generation and Execution' do
470
304
  File.directory?("/Applications/#{app}.app") || system("command -v #{command} > /dev/null 2>&1")
471
305
  end
472
306
 
473
- # A separate project, so the default projects keep resolving raider_reporter 0.10+ from RubyGems
307
+ # A separate project, so the default projects keep resolving raider_reporter 1.x from RubyGems
474
308
  def generate_video_project(framework, automation)
475
309
  name = "video_#{framework}_#{automation}"
476
310
  unless LazyProjectGenerator::GENERATED.include?(name)
@@ -487,9 +321,9 @@ describe 'End-to-End Project Generation and Execution' do
487
321
  JSON.parse(File.read(File.join(project, 'raider-results', 'run.json')))['results']
488
322
  end
489
323
 
490
- # Failure video replay against real browsers. Needs an ffmpeg with libvpx (RAIDER_FFMPEG_PATH), because the
491
- # RaiderHQ ffmpeg release has no checksums yet. Skipped when it, or the browser, is missing. Firefox can be
492
- # pointed at a specific binary with FIREFOX_BINARY.
324
+ # Failure video replay against real browsers. Needs an ffmpeg with libvpx (RAIDER_FFMPEG_PATH), so most examples
325
+ # never download the release binary; RAIDER_E2E_DOWNLOAD=1 adds one that does. Skipped when it, or the browser,
326
+ # is missing. Firefox can be pointed at a specific binary with FIREFOX_BINARY.
493
327
  context 'Failure video replay', :slow, :video do
494
328
  let(:ffmpeg_path) { ENV.fetch('RAIDER_FFMPEG_PATH', '') }
495
329
  let(:cache_dir) { Dir.mktmpdir('raider-cache') }
@@ -534,41 +368,6 @@ describe 'End-to-End Project Generation and Execution' do
534
368
  SPEC
535
369
  end
536
370
 
537
- def add_cucumber_video_feature(project, firefox_binary)
538
- File.write(File.join(project, 'features/video_replay.feature'), <<~FEATURE)
539
- Feature: Video replay
540
-
541
- Scenario: A passing scenario
542
- Given the video page is open
543
- Then the video page title is "Video"
544
-
545
- Scenario: A failing scenario
546
- Given the video page is open
547
- Then the video page title is "deliberate video failure"
548
- FEATURE
549
- File.write(File.join(project, 'features/step_definitions/video_replay_steps.rb'), <<~STEPS)
550
- # frozen_string_literal: true
551
-
552
- Given('the video page is open') do
553
- browser.goto('#{page_url}')
554
- browser.text_field(id: 'name').set('typed')
555
- browser.button(id: 'go').click
556
- end
557
-
558
- Then('the video page title is {string}') do |title|
559
- raise "expected title \#{title}" unless browser.h1(id: 'title').text == title
560
- end
561
- STEPS
562
- config = File.join(project, 'config/config.yml')
563
- File.write(config, File.read(config).sub(/^browser: .*$/, 'browser: firefox'))
564
- # Test setup only: the generated templates do not read FIREFOX_BINARY.
565
- File.write(File.join(project, 'features/support/zz_firefox_binary.rb'), <<~RUBY) if firefox_binary
566
- # frozen_string_literal: true
567
-
568
- Selenium::WebDriver::Firefox.path = ENV['FIREFOX_BINARY'] if ENV['FIREFOX_BINARY']
569
- RUBY
570
- end
571
-
572
371
  def video_files(project)
573
372
  Dir.glob(File.join(project, 'raider-results', '**', '*.{webm,mp4}'))
574
373
  end
@@ -622,46 +421,34 @@ describe 'End-to-End Project Generation and Execution' do
622
421
  it 'runs unchanged with one [video] line and no download when no ffmpeg is usable', :aggregate_failures do
623
422
  off = run_in_project(project, command, env: video_env('VIDEO' => 'off'))
624
423
  FileUtils.rm_rf(File.join(project, 'raider-results'))
625
- result = run_in_project(project, command, env: video_env('RAIDER_FFMPEG_PATH' => nil))
424
+ # A file where the cache dir should be: the download cannot even start, so nothing is fetched.
425
+ blocker = File.join(cache_dir, 'not-a-dir')
426
+ File.write(blocker, '')
427
+ result = run_in_project(project, command, env: video_env('RAIDER_FFMPEG_PATH' => nil, 'RAIDER_CACHE_DIR' => blocker))
626
428
 
627
429
  expect(result[:exit_code]).to eq(off[:exit_code]), "STDOUT: #{result[:stdout]}\nSTDERR: #{result[:stderr]}"
628
430
  video_lines = result[:stderr].lines.grep(/\[video\]/)
629
431
  expect(video_lines.size).to eq(1), "STDERR: #{result[:stderr]}"
630
- # Decided at the first driver/recorder call, before any capture or fetch: the placeholder
631
- # manifest has no checksum, so nothing is captured or downloaded.
632
- expect(video_lines.first).to include('no ffmpeg available for this platform yet')
432
+ expect(video_lines.first).to include('ffmpeg download failed')
633
433
  expect(video_files(project)).to be_empty
634
- expect(Dir.glob(File.join(cache_dir, '**', '*'))).to be_empty
635
- end
636
- end
637
-
638
- describe 'Watir + Cucumber on headless Firefox' do
639
- let(:project) { 'video_cucumber_watir' }
640
- let(:firefox_binary) { ENV.fetch('FIREFOX_BINARY', nil) }
641
-
642
- before do
643
- skip_unless_video_prerequisites('firefox')
644
- generate_video_project('cucumber', 'watir')
645
- add_cucumber_video_feature(project, firefox_binary)
434
+ expect(Dir.glob(File.join(cache_dir, '**', '*'))).to eq([blocker])
646
435
  end
647
436
 
648
- after do
649
- FileUtils.rm_f(File.join(project, 'features/video_replay.feature'))
650
- FileUtils.rm_f(File.join(project, 'features/step_definitions/video_replay_steps.rb'))
651
- end
437
+ # Downloads the pinned ffmpeg-7.1 release asset for this platform into an empty cache.
438
+ it 'downloads the pinned ffmpeg into an empty cache and attaches the video', :aggregate_failures do
439
+ skip 'set RAIDER_E2E_DOWNLOAD=1 to download the ffmpeg-7.1 release asset' unless ENV['RAIDER_E2E_DOWNLOAD'] == '1'
652
440
 
653
- it 'attaches video.webm to the failing scenario only and plays it in index.html', :aggregate_failures do
654
- result = run_in_project(project, 'bundle exec cucumber features/video_replay.feature',
655
- env: video_env('FIREFOX_BINARY' => firefox_binary), timeout: 240)
441
+ result = run_in_project(project, command, env: video_env('RAIDER_FFMPEG_PATH' => nil))
656
442
  expect(result[:exit_code]).to eq(1), "STDOUT: #{result[:stdout]}\nSTDERR: #{result[:stderr]}"
657
443
  expect(result[:stderr]).not_to include('[video]')
658
- expect_video_for_failure_only(project, 'A failing scenario', result)
444
+ expect(Dir.glob(File.join(cache_dir, 'ffmpeg', '7.1', 'ffmpeg{,.exe}')).size).to eq(1)
445
+ expect_video_for_failure_only(project, 'fails after driving the page', result)
659
446
  end
660
447
  end
661
448
  end
662
449
 
663
450
  # Trace replay against headless Chrome, and one example on headless Firefox. The page is served over HTTP from this process (never file://), so
664
- # WebDriver BiDi reports real network and console entries. raider_reporter ~> 0.12 resolves from RubyGems, or
451
+ # WebDriver BiDi reports real network and console entries. raider_reporter ~> 1.0 resolves from RubyGems, or
665
452
  # from a checkout at RAIDER_REPORTER_PATH. The example with video on also needs RAIDER_FFMPEG_PATH.
666
453
  # Set TRACE_FIXTURE_DIR to keep the failing RSpec example's trace.zip (and an unzipped copy) there.
667
454
  context 'Trace replay', :slow do
@@ -686,8 +473,8 @@ describe 'End-to-End Project Generation and Execution' do
686
473
  def skip_unless_trace_prerequisites(project, browser = 'chrome')
687
474
  skip "#{browser == 'chrome' ? 'Google Chrome' : 'Firefox'} is not installed" unless browser_installed?(browser)
688
475
  version = run_in_project(project, %(bundle exec ruby -e "require 'raider_reporter/version'; print RaiderReporter::VERSION"))
689
- skip "the bundle does not resolve raider_reporter ~> 0.12 (set RAIDER_REPORTER_PATH): #{version[:stderr].lines.last}" unless
690
- version[:success] && Gem::Version.new(version[:stdout]) >= Gem::Version.new('0.12')
476
+ skip "the bundle does not resolve raider_reporter ~> 1.0 (set RAIDER_REPORTER_PATH): #{version[:stderr].lines.last}" unless
477
+ version[:success] && Gem::Version.new(version[:stdout]) >= Gem::Version.new('1.0')
691
478
  end
692
479
 
693
480
  def trace_env(overrides = {})
@@ -747,7 +534,7 @@ describe 'End-to-End Project Generation and Execution' do
747
534
  'passes after driving the page'
748
535
  end
749
536
 
750
- # Drives the page through the generated WaitHelper, so the trace has action steps.
537
+ # Drives the page with plain Selenium and the runtime's matchers, so the trace has action steps.
751
538
  # Each example prints the driver's webSocketUrl, which is set only while tracing is on.
752
539
  def add_rspec_trace_spec(project)
753
540
  File.write(File.join(project, 'spec/trace_replay_spec.rb'), <<~SPEC)
@@ -757,21 +544,23 @@ describe 'End-to-End Project Generation and Execution' do
757
544
 
758
545
  describe 'Trace replay' do
759
546
  it '#{failing}' do
760
- driver.navigate.to('#{server.url}')
547
+ driver.navigate.to('#{server.url}start')
761
548
  puts "TRACE_E2E_WEBSOCKET=\#{driver.capabilities[:web_socket_url].inspect}"
762
- send_keys({ id: 'pw' }, '#{secrets[0]}')
763
- send_keys({ id: 'pw2' }, '#{secrets[1]}')
764
- find_element(id: 'name').send_keys('#{plain_value}')
765
- click({ id: 'go' })
766
- eventually(timeout: 5) { expect(text(id: 'status')).to eq('answered by /api') }
767
- eventually(timeout: 1) { expect(text(id: 'title')).to eq('deliberate trace failure') }
549
+ driver.find_element(id: 'pw').send_keys('#{secrets[0]}')
550
+ driver.find_element(id: 'pw2').send_keys('#{secrets[1]}')
551
+ form = driver.find_element(id: 'form')
552
+ form.find_element(id: 'name').send_keys('#{plain_value}')
553
+ driver.find_element(id: 'go').click
554
+ expect { driver.find_element(id: 'status') }.to have_text('answered by /api', wait: 5)
555
+ expect { driver.find_element(id: 'status').text }.to eq('answered by /api')
556
+ expect { driver.find_element(id: 'title') }.to have_text('deliberate trace failure', wait: 1)
768
557
  end
769
558
 
770
559
  it '#{passing}' do
771
560
  driver.navigate.to('#{server.url}')
772
561
  puts "TRACE_E2E_WEBSOCKET=\#{driver.capabilities[:web_socket_url].inspect}"
773
- send_keys({ id: 'name' }, 'ok')
774
- eventually { expect(text(id: 'title')).to eq('Trace') }
562
+ driver.find_element(id: 'name').send_keys('ok')
563
+ expect { driver.find_element(id: 'title') }.to have_text('Trace')
775
564
  end
776
565
  end
777
566
  SPEC
@@ -782,6 +571,19 @@ describe 'End-to-End Project Generation and Execution' do
782
571
  trace_zip(project, trace_attachments(result).first)
783
572
  end
784
573
 
574
+ # Locators as id strategies, the chained find as within, the password steps masked, and no 3.x step shapes.
575
+ def expect_runtime_steps(steps)
576
+ by_id = ->(step) { step['locator'].is_a?(Hash) && step['locator']['strategy'] == 'id' && step['locator']['selector'].is_a?(String) }
577
+ expect(steps.select { |step| step['action'] == 'click' }).to all(satisfy(&by_id)).and(be_any)
578
+ expect(steps.select { |step| step['action'] == 'click' }.first['source']['file']).to end_with('spec/trace_replay_spec.rb')
579
+ typed = steps.select { |step| step['action'] == 'send_keys' }
580
+ expect(typed).to all(satisfy(&by_id))
581
+ expect(typed.last['locator']['within']).to be_a(Array).and(be_any)
582
+ expect(typed.first(2)).to all(include('value' => nil, 'secret' => true))
583
+ expect(steps.map { |step| step['kind'] }).not_to include('group')
584
+ expect(steps.map { |step| step['action'] }).not_to include('cucumber_step')
585
+ end
586
+
785
587
  def steps_of(path)
786
588
  TraceFormatChecker.read(path).first['steps']
787
589
  end
@@ -824,6 +626,16 @@ describe 'End-to-End Project Generation and Execution' do
824
626
  expect(trace['console']).to include(include('level' => 'error', 'text' => a_string_including('trace e2e error')))
825
627
  end
826
628
 
629
+ # /start redirects to /: two entries, one per hop, both credited to the navigate step.
630
+ def expect_redirect_hops(trace)
631
+ navigate = trace['steps'].find { |step| step['kind'] == 'navigate' }
632
+ start = trace['network'].find { |entry| entry['url'].to_s.end_with?('/start') }
633
+ page = trace['network'].find { |entry| entry['url'] == server.url }
634
+ expect(start).to include('status' => 302, 'step_index' => navigate['index'])
635
+ expect(page).to include('status' => 200, 'step_index' => navigate['index'])
636
+ expect(page['duration_ms']).to be >= (TracePageServer::PAGE_DELAY * 1000) - 50
637
+ end
638
+
827
639
  # The same-origin stylesheet inlined as <style>, and the page's <script> gone.
828
640
  def expect_sanitised_snapshots(path, names)
829
641
  entries = zip_entries(path)
@@ -847,12 +659,14 @@ describe 'End-to-End Project Generation and Execution' do
847
659
  expect(trace_attachments(result_named(project, passing))).to be_empty
848
660
  expect(trace_files(project).size).to eq(1)
849
661
  expect_valid_trace(path)
662
+ expect_runtime_steps(steps_of(path))
850
663
 
851
664
  trace, names = TraceFormatChecker.read(path)
852
665
  expect(trace['capabilities']).to include('network' => true, 'console' => true)
853
666
  expect_steps(trace['steps'])
854
667
  expect_jpeg_screenshots(path, names)
855
668
  expect_network_and_console(trace)
669
+ expect_redirect_hops(trace)
856
670
  expect_sanitised_snapshots(path, names)
857
671
  end
858
672
 
@@ -871,7 +685,7 @@ describe 'End-to-End Project Generation and Execution' do
871
685
  end
872
686
 
873
687
  it 'writes no trace and no web_socket_url with TRACE=off', :aggregate_failures do
874
- run = run_in_project(project, command, env: trace_env('TRACE' => 'off'))
688
+ run = run_in_project(project, command, env: trace_env('TRACE' => 'off', 'BIDI' => 'off'))
875
689
  expect_run(run)
876
690
  expect(run[:stdout].scan(/^TRACE_E2E_WEBSOCKET=(.*)$/).flatten).to eq(%w[nil nil])
877
691
  expect(results(project).flat_map { |result| trace_attachments(result) }).to be_empty
@@ -954,6 +768,7 @@ describe 'End-to-End Project Generation and Execution' do
954
768
  expect_run(run)
955
769
  path = failing_trace(result_named(project, failing))
956
770
  expect_valid_trace(path)
771
+ expect_runtime_steps(steps_of(path))
957
772
 
958
773
  trace, names = TraceFormatChecker.read(path)
959
774
  expect(trace['browser']).to include('name' => 'firefox')
@@ -965,57 +780,286 @@ describe 'End-to-End Project Generation and Execution' do
965
780
  end
966
781
  end
967
782
 
968
- describe 'Selenium + Cucumber on headless Chrome' do
969
- let(:project) { 'video_cucumber_selenium' }
783
+ # mock_request / block_request through WebDriver BiDi, on a page that fetches /api/* and a cross-origin URL
784
+ # that exists nowhere (so it only answers when mocked). Chrome by default; Edge and Firefox run only when
785
+ # RAIDER_E2E_BROWSERS (comma separated) lists them.
786
+ describe 'Network mocking' do
787
+ let(:project) { 'video_rspec_selenium' }
788
+ let(:original_config) { File.read(config) }
970
789
 
971
- before do
972
- generate_video_project('cucumber', 'selenium')
973
- skip_unless_trace_prerequisites(project)
974
- add_cucumber_trace_feature(project)
790
+ def config
791
+ File.join(project, 'config/config.yml')
975
792
  end
976
793
 
977
- after do
978
- FileUtils.rm_f(File.join(project, 'features/trace_replay.feature'))
979
- FileUtils.rm_f(File.join(project, 'features/step_definitions/trace_replay_steps.rb'))
794
+ def spec_path
795
+ File.join(project, 'spec/network_mocking_spec.rb')
796
+ end
797
+
798
+ def opted_in?(browser)
799
+ ENV.fetch('RAIDER_E2E_BROWSERS', '').split(',').map(&:strip).include?(browser)
980
800
  end
981
801
 
982
- def add_cucumber_trace_feature(project)
983
- File.write(File.join(project, 'features/trace_replay.feature'), <<~FEATURE)
984
- Feature: Trace replay
802
+ def skip_unless_mocking_prerequisites(browser)
803
+ skip "set RAIDER_E2E_BROWSERS=#{browser} to run network mocking on #{browser}" unless browser == 'chrome' || opted_in?(browser)
804
+ skip 'Microsoft Edge is not installed' if browser == 'edge' && !File.directory?('/Applications/Microsoft Edge.app')
805
+ skip_unless_trace_prerequisites(project, browser == 'firefox' ? 'firefox' : 'chrome')
806
+ end
985
807
 
986
- Scenario: A failing traced scenario
987
- Given the trace page is open
988
- When I type a name on the trace page
989
- Then the trace page title is "deliberate trace failure"
990
- FEATURE
991
- File.write(File.join(project, 'features/step_definitions/trace_replay_steps.rb'), <<~STEPS)
808
+ def write_spec(body)
809
+ File.write(spec_path, <<~SPEC)
992
810
  # frozen_string_literal: true
993
811
 
994
- Given('the trace page is open') do
995
- driver.navigate.to('#{server.url}')
812
+ require_relative '../helpers/spec_helper'
813
+
814
+ describe 'Network mocking' do
815
+ #{body.lines.map { |line| line.strip.empty? ? line : " #{line}" }.join}
996
816
  end
817
+ SPEC
818
+ end
819
+
820
+ def mocking_run(overrides = {})
821
+ run_in_project(project, 'bundle exec rspec spec/network_mocking_spec.rb', env: trace_env(overrides), timeout: 240)
822
+ end
997
823
 
998
- When('I type a name on the trace page') do
999
- send_keys({ id: 'name' }, '#{plain_value}')
1000
- click({ id: 'go' })
824
+ def mock_example(browser)
825
+ write_spec(<<~BODY)
826
+ it 'mocks, blocks, edits and removes' do
827
+ driver.navigate.to('#{server.url}mock')
828
+ users = mock_request('#{server.url}api/users', json: { users: ['ana'] })
829
+ block_request('**/api/fail')
830
+ mock_request('**/api/echo') { { continue: { headers: { 'x-raider' => 'yes' } } } }
831
+ mock_request('http://mock.raider.test/api/cors', json: { ok: true })
832
+ driver.find_element(id: 'users').click
833
+ expect { driver.find_element(id: 'users-out') }.to have_text('ana', wait: 5)
834
+ driver.find_element(id: 'fail').click
835
+ expect { driver.find_element(id: 'fail-out') }.to have_text('request failed', wait: 5)
836
+ driver.find_element(id: 'echo').click
837
+ expect { driver.find_element(id: 'echo-out') }.to have_text('echo yes', wait: 5)
838
+ driver.find_element(id: 'cors').click
839
+ expect { driver.find_element(id: 'cors-out') }.to have_text('cors true', wait: 5)
840
+ expect { users.calls.size }.to eq(1)
841
+ expect { users.called? }.to be(true)
842
+ remove_mock(users)
843
+ driver.find_element(id: 'users').click
844
+ expect { driver.find_element(id: 'users-out') }.to have_text('real', wait: 5)
845
+ expect { users.calls.size }.to eq(1)
846
+ puts 'NETWORK_MOCKING_#{browser.upcase}_DONE'
1001
847
  end
848
+ BODY
849
+ end
850
+
851
+ def switch_browser(name)
852
+ # The generated config carries browser arguments for chrome and firefox only.
853
+ edge_args = " edge:\n - no-sandbox\n"
854
+ File.write(config, original_config.sub(/^browser: .*$/, "browser: #{name}").sub(/^ firefox:/, "#{edge_args} firefox:"))
855
+ end
856
+
857
+ # Skips when the browser is unavailable or not opted in; otherwise points the config at it.
858
+ def use_browser(name)
859
+ skip_unless_mocking_prerequisites(name)
860
+ original_config
861
+ switch_browser(name)
862
+ end
863
+
864
+ before { generate_video_project('rspec', 'selenium') }
865
+
866
+ after do
867
+ File.write(config, original_config) if File.exist?(config)
868
+ FileUtils.rm_f(spec_path)
869
+ end
1002
870
 
1003
- Then('the trace page title is {string}') do |title|
1004
- eventually(timeout: 1) { expect(text(id: 'title')).to eq(title) }
871
+ %w[chrome edge firefox].each do |name|
872
+ it "mocks, blocks, edits headers and removes a mock on headless #{name}", :aggregate_failures do
873
+ use_browser(name)
874
+ mock_example(name)
875
+ run = mocking_run('TRACE' => 'off')
876
+ expect_run(run, exit_code: 0)
877
+ expect(run[:stdout]).to include("NETWORK_MOCKING_#{name.upcase}_DONE")
878
+ end
879
+ end
880
+
881
+ def write_failing_spec
882
+ write_spec(<<~BODY)
883
+ it 'fails after mocking' do
884
+ driver.navigate.to('#{server.url}mock')
885
+ mock_request('#{server.url}api/users', json: { users: ['ana'] })
886
+ block_request('#{server.url}api/fail')
887
+ driver.find_element(id: 'users').click
888
+ expect { driver.find_element(id: 'users-out') }.to have_text('ana', wait: 5)
889
+ driver.find_element(id: 'fail').click
890
+ expect { driver.find_element(id: 'fail-out') }.to have_text('request failed', wait: 5)
891
+ expect { driver.find_element(id: 'users-out') }.to have_text('deliberate mocking failure', wait: 1)
1005
892
  end
1006
- STEPS
893
+ BODY
1007
894
  end
1008
895
 
1009
- it 'attaches a trace.zip with Gherkin step groups to the failing scenario', :aggregate_failures do
1010
- run = run_in_project(project, 'bundle exec cucumber features/trace_replay.feature', env: trace_env, timeout: 240)
1011
- expect_run(run)
1012
- attachments = trace_attachments(result_named(project, 'A failing traced scenario'))
1013
- expect(attachments.size).to eq(1)
1014
- expect(attachments.first).to include('content_type' => 'application/vnd.raider.trace+zip', 'attempt' => 1)
1015
- path = trace_zip(project, attachments.first)
896
+ it 'keeps mocked entries in the failing example trace', :aggregate_failures do
897
+ use_browser('chrome')
898
+ write_failing_spec
899
+ expect_run(mocking_run)
900
+ path = failing_trace(result_named(project, 'fails after mocking'))
901
+ keep_fixture(path)
1016
902
  expect_valid_trace(path)
1017
- groups = TraceFormatChecker.read(path).first['steps'].select { |step| step['action'] == 'cucumber_step' }
1018
- expect(groups).to include(include('kind' => 'group', 'name' => a_string_including('the trace page is open')))
903
+ network = TraceFormatChecker.read(path).first['network']
904
+ users = network.find { |entry| entry['url'].to_s.end_with?('/api/users') }
905
+ failed = network.find { |entry| entry['url'].to_s.end_with?('/api/fail') }
906
+ expect(users).to include('mocked' => 'fulfilled', 'status' => 200)
907
+ expect(failed).to include('mocked' => 'failed')
908
+ end
909
+
910
+ it 'fails the example with MockError when a block raises', :aggregate_failures do
911
+ use_browser('chrome')
912
+ write_spec(<<~BODY)
913
+ it 'has a raising block' do
914
+ driver.navigate.to('#{server.url}mock')
915
+ mock_request('#{server.url}api/users') { raise 'boom from the block' }
916
+ driver.find_element(id: 'users').click
917
+ expect { driver.find_element(id: 'users-out') }.to have_text('users failed', wait: 5)
918
+ end
919
+ BODY
920
+ run = mocking_run('TRACE' => 'off')
921
+ expect(run[:exit_code]).to eq(1), "STDOUT: #{run[:stdout]}\nSTDERR: #{run[:stderr]}"
922
+ expect(run[:stdout]).to include('NetworkHelper::MockError', 'boom from the block')
923
+ end
924
+ end
925
+ end
926
+
927
+ # match_screenshot against real browsers, on a fixed data: page (no server, no animation). Chrome by default; Edge and
928
+ # Firefox run only when RAIDER_E2E_BROWSERS (comma separated) lists them. The generated spec recolours the page
929
+ # when SHOT_VARIANT=changed. raider_reporter comes from RubyGems (no `comparison` method yet), so the images are
930
+ # attached and one warning is printed; the report's comparisons field is not asserted here.
931
+ context 'Screenshot comparison', :slow do
932
+ let(:cache_dir) { Dir.mktmpdir('raider-cache') }
933
+ let(:baseline) { "screenshots/baselines/#{browser_name}/home.png" }
934
+ let(:original_config) { File.read(config_path) }
935
+
936
+ after do
937
+ File.write(config_path, original_config) if File.exist?(config_path)
938
+ FileUtils.rm_rf(File.join(project, 'screenshots'))
939
+ FileUtils.rm_f(File.join(project, 'spec/screenshot_comparison_spec.rb'))
940
+ FileUtils.rm_rf(cache_dir)
941
+ end
942
+
943
+ def config_path
944
+ File.join(project, 'config/config.yml')
945
+ end
946
+
947
+ def shot_page
948
+ html = '<body style="margin:0;font-family:monospace"><h1 id="title">Screenshot</h1><p>Fixed content</p></body>'
949
+ "data:text/html,#{ERB::Util.url_encode(html)}"
950
+ end
951
+
952
+ def recolour
953
+ "document.documentElement.style.background = 'rgb(200, 0, 0)'; document.body.style.background = 'rgb(200, 0, 0)'"
954
+ end
955
+
956
+ def shot_env(overrides = {})
957
+ ci = %w[CI GITHUB_ACTIONS GITLAB_CI JENKINS_URL BUILDKITE CIRCLECI TF_BUILD TRAVIS].to_h { |key| [key, nil] }
958
+ ci.merge('HEADLESS' => 'true', 'VIDEO' => 'off', 'TRACE' => 'off', 'RAIDER_CACHE_DIR' => cache_dir,
959
+ 'RAIDER_TOKEN' => nil, 'RAIDER_ENDPOINT' => nil, 'SCREENSHOTS' => nil, 'SHOT_VARIANT' => nil).merge(overrides)
960
+ end
961
+
962
+ def use_browser(name)
963
+ opted_in = ENV.fetch('RAIDER_E2E_BROWSERS', '').split(',').map(&:strip).include?(name)
964
+ skip "set RAIDER_E2E_BROWSERS=#{name} to run screenshot comparison on #{name}" unless name == 'chrome' || opted_in
965
+ skip 'Microsoft Edge is not installed' if name == 'edge' && !File.directory?('/Applications/Microsoft Edge.app')
966
+ skip "#{name} is not installed" unless name == 'edge' || browser_installed?(name == 'firefox' ? 'firefox' : 'chrome')
967
+ @browser_name = name
968
+ original_config
969
+ edge_args = " edge:\n - no-sandbox\n"
970
+ File.write(config_path, original_config.sub(/^browser: .*$/, "browser: #{name}").sub(/^ firefox:/, "#{edge_args} firefox:"))
971
+ end
972
+
973
+ attr_reader :browser_name
974
+
975
+ def attachment_names(project)
976
+ results(project).flat_map { |result| result['attachments'].map { |attachment| attachment['name'] } }
977
+ end
978
+
979
+ def comparison_names(project)
980
+ attachment_names(project).grep(/\Acomparison:/)
981
+ end
982
+
983
+ def baseline_path
984
+ File.join(project, baseline)
985
+ end
986
+
987
+ def write_rspec_spec
988
+ File.write(File.join(project, 'spec/screenshot_comparison_spec.rb'), <<~SPEC)
989
+ # frozen_string_literal: true
990
+
991
+ require_relative '../helpers/spec_helper'
992
+
993
+ describe 'Screenshot comparison' do
994
+ it 'matches home' do
995
+ driver.navigate.to('#{shot_page}')
996
+ driver.execute_script("#{recolour}") if ENV['SHOT_VARIANT'] == 'changed'
997
+ match_screenshot('home')
998
+ end
999
+ end
1000
+ SPEC
1001
+ end
1002
+
1003
+ # Every failure message in run.json, as text.
1004
+ def failure_text(project)
1005
+ results(project).to_json
1006
+ end
1007
+
1008
+ def expect_ok(run)
1009
+ expect(run[:exit_code]).to eq(0), "STDOUT: #{run[:stdout]}\nSTDERR: #{run[:stderr]}"
1010
+ end
1011
+
1012
+ def expect_failed(run)
1013
+ expect(run[:exit_code]).to eq(1), "STDOUT: #{run[:stdout]}\nSTDERR: #{run[:stderr]}"
1014
+ end
1015
+
1016
+ # The five runs of the plan, in order; each block is one run of the generated test.
1017
+ def walk_through(command)
1018
+ run = proc do |overrides = {}|
1019
+ FileUtils.rm_rf(File.join(project, 'raider-results'))
1020
+ run_in_project(project, command, env: shot_env(overrides), timeout: 300)
1021
+ end
1022
+
1023
+ expect_ok(run.call) # 1: creates the baseline
1024
+ expect(File).to exist(baseline_path)
1025
+ expect(File.binread(baseline_path)).to start_with("\x89PNG".b)
1026
+ first_bytes = File.binread(baseline_path)
1027
+
1028
+ expect_ok(run.call) # 2: matches
1029
+ expect(comparison_names(project)).to be_empty
1030
+
1031
+ different = run.call('SHOT_VARIANT' => 'changed') # 3: differs
1032
+ expect_failed(different)
1033
+ expect(comparison_names(project)).to include('comparison:home:expected', 'comparison:home:actual', 'comparison:home:diff')
1034
+ expect(failure_text(project)).to include(baseline)
1035
+ expect(File.binread(baseline_path)).to eq(first_bytes)
1036
+ expect(different[:stderr].scan('[screenshots] this raider_reporter has no comparison method').size).to be <= 1
1037
+
1038
+ FileUtils.rm_f(baseline_path) # 4: CI without a baseline
1039
+ missing = run.call('CI' => '1')
1040
+ expect_failed(missing)
1041
+ expect(File).not_to exist(baseline_path)
1042
+ expect(failure_text(project)).to include('no baseline')
1043
+
1044
+ expect_ok(run.call('SCREENSHOTS' => 'update')) # 5: update rewrites
1045
+ expect(File).to exist(baseline_path)
1046
+ expect_ok(run.call('SHOT_VARIANT' => 'changed', 'SCREENSHOTS' => 'update'))
1047
+ expect(File.binread(baseline_path)).not_to eq(first_bytes)
1048
+ end
1049
+
1050
+ %w[chrome edge firefox].each do |name|
1051
+ describe "Selenium + RSpec on headless #{name}" do
1052
+ let(:project) { 'video_rspec_selenium' }
1053
+
1054
+ before do
1055
+ generate_video_project('rspec', 'selenium')
1056
+ use_browser(name)
1057
+ write_rspec_spec
1058
+ end
1059
+
1060
+ it 'creates, matches, fails with images, refuses on CI and updates', :aggregate_failures do
1061
+ walk_through('bundle exec rspec spec/screenshot_comparison_spec.rb')
1062
+ end
1019
1063
  end
1020
1064
  end
1021
1065
  end
@@ -1035,19 +1079,6 @@ describe 'End-to-End Project Generation and Execution' do
1035
1079
  end
1036
1080
  end
1037
1081
 
1038
- describe 'iOS + Cucumber' do
1039
- it 'generates valid project structure' do
1040
- expect(File).to exist('cucumber_ios/features/support/env.rb')
1041
- expect(File).to exist('cucumber_ios/Gemfile')
1042
- expect(File).to exist('cucumber_ios/features')
1043
- end
1044
-
1045
- it 'has valid Ruby syntax in generated files' do
1046
- result = run_in_project('cucumber_ios', 'ruby -c features/support/env.rb')
1047
- expect(result[:success]).to be true
1048
- end
1049
- end
1050
-
1051
1082
  describe 'Android + RSpec' do
1052
1083
  it 'generates valid project structure' do
1053
1084
  expect(File).to exist('rspec_android/helpers/spec_helper.rb')
@@ -1061,19 +1092,6 @@ describe 'End-to-End Project Generation and Execution' do
1061
1092
  end
1062
1093
  end
1063
1094
 
1064
- describe 'Android + Cucumber' do
1065
- it 'generates valid project structure' do
1066
- expect(File).to exist('cucumber_android/features/support/env.rb')
1067
- expect(File).to exist('cucumber_android/Gemfile')
1068
- expect(File).to exist('cucumber_android/features')
1069
- end
1070
-
1071
- it 'has valid Ruby syntax in generated files' do
1072
- result = run_in_project('cucumber_android', 'ruby -c features/support/env.rb')
1073
- expect(result[:success]).to be true
1074
- end
1075
- end
1076
-
1077
1095
  describe 'Cross-Platform + RSpec' do
1078
1096
  it 'generates valid project structure' do
1079
1097
  expect(File).to exist('rspec_cross_platform/helpers/appium_helper.rb')
@@ -1086,19 +1104,6 @@ describe 'End-to-End Project Generation and Execution' do
1086
1104
  expect(result[:success]).to be true
1087
1105
  end
1088
1106
  end
1089
-
1090
- describe 'Cross-Platform + Cucumber' do
1091
- it 'generates valid project structure' do
1092
- expect(File).to exist('cucumber_cross_platform/helpers/appium_helper.rb')
1093
- expect(File).to exist('cucumber_cross_platform/Gemfile')
1094
- expect(File).to exist('cucumber_cross_platform/features')
1095
- end
1096
-
1097
- it 'has valid Ruby syntax in generated files' do
1098
- result = run_in_project('cucumber_cross_platform', 'ruby -c features/support/env.rb')
1099
- expect(result[:success]).to be true
1100
- end
1101
- end
1102
1107
  end
1103
1108
 
1104
1109
  # Verify template system performance (caching working)