ruby_raider 3.12.1 → 4.0.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.
- checksums.yaml +4 -4
- data/.github/workflows/runtime.yml +38 -0
- data/.github/workflows/system_tests.yml +1 -23
- data/.reek.yml +1 -0
- data/.rspec +1 -0
- data/Gemfile +2 -0
- data/README.md +17 -48
- data/RELEASE.md +22 -0
- data/bin/raider +5 -0
- data/lib/commands/scaffolding_commands.rb +2 -25
- data/lib/commands/utility_commands.rb +39 -3
- data/lib/generators/automation/automation_generator.rb +0 -5
- data/lib/generators/automation/templates/component.tt +1 -0
- data/lib/generators/automation/templates/home.tt +2 -2
- data/lib/generators/automation/templates/login.tt +6 -26
- data/lib/generators/automation/templates/page.tt +23 -18
- data/lib/generators/automation/templates/partials/home_page_selector.tt +1 -2
- data/lib/generators/automation/templates/partials/initialize_selector.tt +0 -8
- data/lib/generators/automation/templates/partials/pdp_page_selector.tt +1 -2
- data/lib/generators/automation/templates/partials/url_methods.tt +8 -2
- data/lib/generators/automation/templates/partials/visit_method.tt +0 -5
- data/lib/generators/automation/templates/pdp.tt +1 -9
- data/lib/generators/common_generator.rb +0 -2
- data/lib/generators/generator.rb +19 -17
- data/lib/generators/helper_generator.rb +25 -16
- data/lib/generators/infrastructure/templates/azure_pipelines.tt +1 -1
- data/lib/generators/infrastructure/templates/github.tt +2 -3
- data/lib/generators/infrastructure/templates/github_appium.tt +0 -8
- data/lib/generators/invoke_generators.rb +4 -23
- data/lib/generators/menu_generator.rb +1 -9
- data/lib/generators/rspec/templates/accessibility_spec.tt +1 -9
- data/lib/generators/rspec/templates/spec.tt +8 -24
- data/lib/generators/template_renderer/partial_cache.rb +3 -1
- data/lib/generators/template_renderer.rb +1 -1
- data/lib/generators/templates/common/gemfile.tt +3 -10
- data/lib/generators/templates/common/git_ignore.tt +0 -5
- data/lib/generators/templates/common/partials/mobile_config.tt +3 -1
- data/lib/generators/templates/common/partials/web_config.tt +17 -1
- data/lib/generators/templates/common/rakefile.tt +0 -15
- data/lib/generators/templates/common/read_me.tt +394 -242
- data/lib/generators/templates/common/rubocop.tt +0 -2
- data/lib/generators/templates/helpers/driver_helper.tt +30 -0
- data/lib/generators/templates/helpers/gesture_helper.tt +78 -0
- data/lib/generators/templates/helpers/network_helper.tt +521 -0
- data/lib/generators/templates/helpers/partials/quit_driver.tt +0 -2
- data/lib/generators/templates/helpers/partials/screenshot.tt +0 -2
- data/lib/generators/templates/helpers/partials/selenium_driver.tt +14 -1
- data/lib/generators/templates/helpers/screenshot_helper.tt +490 -0
- data/lib/generators/templates/helpers/spec_helper.tt +56 -27
- data/lib/generators/templates/helpers/trace_helper.tt +1242 -0
- data/lib/generators/templates/helpers/video_helper.tt +3 -8
- data/lib/ruby_raider/runtime/actionability.rb +129 -0
- data/lib/ruby_raider/runtime/actionable.rb +49 -0
- data/lib/ruby_raider/runtime/by_role.rb +55 -0
- data/lib/ruby_raider/runtime/config.rb +79 -0
- data/lib/ruby_raider/runtime/context.rb +38 -0
- data/lib/ruby_raider/runtime/errors.rb +69 -0
- data/lib/ruby_raider/runtime/finders.rb +73 -0
- data/lib/ruby_raider/runtime/js/actionability.js +134 -0
- data/lib/ruby_raider/runtime/js/role_engine.js +315 -0
- data/lib/ruby_raider/runtime/locator_converter.rb +72 -0
- data/lib/ruby_raider/runtime/matchers/base.rb +222 -0
- data/lib/ruby_raider/runtime/matchers/element.rb +183 -0
- data/lib/ruby_raider/runtime/matchers/page.rb +71 -0
- data/lib/ruby_raider/runtime/matchers/presence.rb +41 -0
- data/lib/ruby_raider/runtime/matchers/retrying_block.rb +104 -0
- data/lib/ruby_raider/runtime/observer.rb +170 -0
- data/lib/ruby_raider/runtime/role_finder.rb +83 -0
- data/lib/ruby_raider/runtime/rspec.rb +78 -0
- data/lib/ruby_raider/runtime/selectors.rb +60 -0
- data/lib/ruby_raider/runtime/strict.rb +142 -0
- data/lib/ruby_raider/runtime/wait.rb +84 -0
- data/lib/ruby_raider/runtime.rb +20 -0
- data/lib/scaffolding/name_normalizer.rb +1 -1
- data/lib/scaffolding/project_detector.rb +2 -28
- data/lib/scaffolding/scaffolding.rb +0 -20
- data/lib/scaffolding/templates/component.tt +0 -14
- data/lib/scaffolding/templates/page_object.tt +2 -14
- data/lib/scaffolding/templates/spec.tt +1 -9
- data/lib/utilities/utilities.rb +17 -8
- data/lib/version +1 -1
- data/ruby_raider.gemspec +3 -1
- data/sig/commands/scaffolding_commands.rbs +0 -2
- data/sig/commands/utility_commands.rbs +8 -0
- data/sig/generators/generator.rbs +4 -4
- data/sig/generators/helper_generator.rbs +1 -1
- data/sig/generators/menu_generator.rbs +0 -1
- data/sig/ruby_raider/runtime/actionability.rbs +25 -0
- data/sig/ruby_raider/runtime/actionable.rbs +13 -0
- data/sig/ruby_raider/runtime/by_role.rbs +15 -0
- data/sig/ruby_raider/runtime/config.rbs +26 -0
- data/sig/ruby_raider/runtime/context.rbs +12 -0
- data/sig/ruby_raider/runtime/errors.rbs +36 -0
- data/sig/ruby_raider/runtime/finders.rbs +26 -0
- data/sig/ruby_raider/runtime/locator_converter.rbs +21 -0
- data/sig/ruby_raider/runtime/matchers/base.rbs +64 -0
- data/sig/ruby_raider/runtime/matchers/element.rbs +78 -0
- data/sig/ruby_raider/runtime/matchers/page.rbs +38 -0
- data/sig/ruby_raider/runtime/matchers/presence.rbs +21 -0
- data/sig/ruby_raider/runtime/matchers/retrying_block.rbs +27 -0
- data/sig/ruby_raider/runtime/observer.rbs +46 -0
- data/sig/ruby_raider/runtime/role_finder.rbs +18 -0
- data/sig/ruby_raider/runtime/selectors.rbs +21 -0
- data/sig/ruby_raider/runtime/strict.rbs +35 -0
- data/sig/ruby_raider/runtime/wait.rbs +17 -0
- data/sig/ruby_raider/runtime.rbs +2 -0
- data/sig/scaffolding/project_detector.rbs +0 -4
- data/sig/scaffolding/scaffolding.rbs +0 -5
- data/sig/utilities/utilities.rbs +3 -1
- data/sig/vendor/selenium_webdriver.rbs +71 -0
- data/spec/commands/raider_commands_spec.rb +38 -3
- data/spec/commands/scaffolding_commands_spec.rb +27 -0
- data/spec/commands/utility_commands_spec.rb +53 -0
- data/spec/generators/fixtures/video_helper_stubs/selenium-webdriver.rb +11 -2
- data/spec/generators/gesture_helper_spec.rb +123 -0
- data/spec/generators/network_helper_spec.rb +634 -0
- data/spec/generators/screenshot_helper_spec.rb +776 -0
- data/spec/generators/template_renderer_spec.rb +0 -4
- data/spec/generators/trace_helper_spec.rb +1337 -0
- data/spec/generators/video_helper_spec.rb +0 -9
- data/spec/integration/commands/browser_update_after_creation_spec.rb +0 -8
- data/spec/integration/commands/scaffolding_commands_spec.rb +12 -70
- data/spec/integration/commands/utility_commands_spec.rb +19 -41
- data/spec/integration/content/azure_content_spec.rb +2 -6
- data/spec/integration/content/ci_content_spec.rb +1 -55
- data/spec/integration/content/common_content_spec.rb +1 -118
- data/spec/integration/content/config_content_spec.rb +52 -29
- data/spec/integration/content/gemfile_content_spec.rb +7 -72
- data/spec/integration/content/helper_content_spec.rb +158 -93
- data/spec/integration/content/page_content_spec.rb +85 -87
- data/spec/integration/content/readme_content_spec.rb +176 -71
- data/spec/integration/content/rspec_reporter_content_spec.rb +2 -2
- data/spec/integration/content/rubocop_content_spec.rb +1 -1
- data/spec/integration/content/syntax_validation_spec.rb +2 -2
- data/spec/integration/content/test_content_spec.rb +23 -147
- data/spec/integration/end_to_end_features_spec.rb +1 -43
- data/spec/integration/end_to_end_spec.rb +648 -292
- data/spec/integration/generators/automation_generator_spec.rb +3 -37
- data/spec/integration/generators/axe_addon_spec.rb +2 -35
- data/spec/integration/generators/azure_generator_spec.rb +1 -1
- data/spec/integration/generators/common_generator_spec.rb +1 -40
- data/spec/integration/generators/config_features_spec.rb +1 -24
- data/spec/integration/generators/github_generator_spec.rb +0 -12
- data/spec/integration/generators/helpers_generator_spec.rb +91 -71
- data/spec/integration/generators/invoke_generators_spec.rb +54 -45
- data/spec/integration/generators/rspec_generator_spec.rb +0 -6
- data/spec/integration/scaffolding_e2e_spec.rb +17 -179
- data/spec/integration/spec_helper.rb +4 -6
- data/spec/integration/trace_format_checker.rb +150 -0
- data/spec/integration/trace_page_server.rb +147 -0
- data/spec/menus/menu_generator_spec.rb +14 -39
- data/spec/runtime/actionability_spec.rb +207 -0
- data/spec/runtime/actionable_spec.rb +125 -0
- data/spec/runtime/browser/actionability_script_browser_spec.rb +150 -0
- data/spec/runtime/browser/actionable_browser_spec.rb +98 -0
- data/spec/runtime/browser/finders_browser_spec.rb +148 -0
- data/spec/runtime/browser/matchers_browser_spec.rb +67 -0
- data/spec/runtime/browser/retrying_block_browser_spec.rb +37 -0
- data/spec/runtime/browser/role_engine_browser_spec.rb +184 -0
- data/spec/runtime/browser/strict_browser_spec.rb +38 -0
- data/spec/runtime/by_role_spec.rb +52 -0
- data/spec/runtime/config_spec.rb +79 -0
- data/spec/runtime/context_spec.rb +73 -0
- data/spec/runtime/errors_spec.rb +89 -0
- data/spec/runtime/finders_spec.rb +165 -0
- data/spec/runtime/fixtures/actionability.html +70 -0
- data/spec/runtime/fixtures/locators.html +46 -0
- data/spec/runtime/fixtures/matchers.html +33 -0
- data/spec/runtime/fixtures/roles.html +162 -0
- data/spec/runtime/matchers/base_spec.rb +165 -0
- data/spec/runtime/matchers/element_spec.rb +277 -0
- data/spec/runtime/matchers/page_spec.rb +102 -0
- data/spec/runtime/matchers/presence_spec.rb +59 -0
- data/spec/runtime/matchers/retrying_block_spec.rb +165 -0
- data/spec/runtime/observer_spec.rb +341 -0
- data/spec/runtime/role_finder_spec.rb +156 -0
- data/spec/runtime/role_query_spec.rb +75 -0
- data/spec/runtime/selectors_spec.rb +135 -0
- data/spec/runtime/strict_spec.rb +257 -0
- data/spec/runtime/support/browser.rb +48 -0
- data/spec/runtime/support/fake_bridge.rb +117 -0
- data/spec/runtime/wait_spec.rb +71 -0
- data/spec/scaffolding/name_normalizer_spec.rb +3 -2
- data/spec/scaffolding/scaffold_project_detector_spec.rb +4 -43
- data/spec/system/selenium_spec.rb +1 -5
- data/spec/system/support/system_test_helper.rb +2 -5
- data/spec/utilities/headless_config_spec.rb +0 -7
- data/spec/utilities/trace_command_spec.rb +66 -0
- data/spec/utilities/utilities_spec.rb +24 -0
- metadata +134 -44
- data/lib/generators/automation/templates/header.tt +0 -9
- data/lib/generators/cucumber/cucumber_generator.rb +0 -58
- data/lib/generators/cucumber/templates/accessibility_feature.tt +0 -5
- data/lib/generators/cucumber/templates/accessibility_steps.tt +0 -17
- data/lib/generators/cucumber/templates/cucumber.tt +0 -1
- data/lib/generators/cucumber/templates/env.tt +0 -7
- data/lib/generators/cucumber/templates/feature.tt +0 -21
- data/lib/generators/cucumber/templates/partials/appium_env.tt +0 -26
- data/lib/generators/cucumber/templates/partials/driver_world.tt +0 -18
- data/lib/generators/cucumber/templates/partials/mobile_steps.tt +0 -20
- data/lib/generators/cucumber/templates/partials/selenium_env.tt +0 -56
- data/lib/generators/cucumber/templates/partials/watir_env.tt +0 -48
- data/lib/generators/cucumber/templates/partials/watir_world.tt +0 -4
- data/lib/generators/cucumber/templates/partials/web_steps.tt +0 -28
- data/lib/generators/cucumber/templates/steps.tt +0 -5
- data/lib/generators/cucumber/templates/user_factory.tt +0 -15
- data/lib/generators/cucumber/templates/world.tt +0 -7
- data/lib/generators/templates/helpers/browser_helper.tt +0 -31
- data/lib/generators/templates/helpers/raider_element.tt +0 -159
- data/lib/generators/templates/helpers/wait_helper.tt +0 -470
- data/lib/scaffolding/templates/feature.tt +0 -6
- data/lib/scaffolding/templates/steps.tt +0 -19
- data/sig/generators/cucumber/cucumber_generator.rbs +0 -12
- data/spec/fixtures/watir_master/cucumber_watir/Readme.md.snapshot +0 -175
- data/spec/fixtures/watir_master/cucumber_watir/features/step_definitions/login_steps.rb.snapshot +0 -24
- data/spec/fixtures/watir_master/cucumber_watir/page_objects/abstract/page.rb.snapshot +0 -37
- data/spec/fixtures/watir_master/cucumber_watir/page_objects/pages/login.rb.snapshot +0 -33
- data/spec/fixtures/watir_master/rspec_watir/Readme.md.snapshot +0 -174
- data/spec/fixtures/watir_master/rspec_watir/page_objects/abstract/page.rb.snapshot +0 -37
- data/spec/fixtures/watir_master/rspec_watir/page_objects/pages/login.rb.snapshot +0 -33
- data/spec/fixtures/watir_master/rspec_watir/spec/login_page_spec.rb.snapshot +0 -49
- data/spec/integration/content/cucumber_reporter_content_spec.rb +0 -110
- data/spec/integration/generators/cucumber_generator_spec.rb +0 -100
- data/spec/integration/helpers/wait_helper_mobile_spec.rb +0 -281
- data/spec/integration/helpers/wait_helper_spec.rb +0 -496
- data/spec/integration/helpers/wait_helper_support.rb +0 -183
- data/spec/system/watir_spec.rb +0 -38
|
@@ -6,12 +6,14 @@ require 'open3'
|
|
|
6
6
|
require 'json'
|
|
7
7
|
require 'erb'
|
|
8
8
|
require 'tmpdir'
|
|
9
|
+
require_relative 'trace_format_checker'
|
|
10
|
+
require_relative 'trace_page_server'
|
|
9
11
|
|
|
10
12
|
# End-to-end integration tests that verify generated projects actually work
|
|
11
13
|
# These tests:
|
|
12
14
|
# 1. Generate a complete project
|
|
13
15
|
# 2. Install dependencies (bundle install)
|
|
14
|
-
# 3. Run the generated tests (rspec
|
|
16
|
+
# 3. Run the generated tests (rspec)
|
|
15
17
|
# 4. Verify tests pass
|
|
16
18
|
#
|
|
17
19
|
# This ensures the template system produces working, executable test frameworks
|
|
@@ -92,21 +94,6 @@ describe 'End-to-End Project Generation and Execution' do
|
|
|
92
94
|
result
|
|
93
95
|
end
|
|
94
96
|
|
|
95
|
-
# Helper to run Cucumber tests
|
|
96
|
-
def run_cucumber(project_name)
|
|
97
|
-
puts "\n🥒 Running Cucumber tests in #{project_name}..."
|
|
98
|
-
result = run_in_project(project_name, 'HEADLESS=true bundle exec cucumber features/ --format pretty', timeout: 120)
|
|
99
|
-
|
|
100
|
-
puts result[:stdout] if result[:stdout].length.positive?
|
|
101
|
-
|
|
102
|
-
unless result[:success]
|
|
103
|
-
puts '❌ Cucumber tests failed:'
|
|
104
|
-
puts result[:stderr] if result[:stderr].length.positive?
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
result
|
|
108
|
-
end
|
|
109
|
-
|
|
110
97
|
# Shared example for RSpec-based projects
|
|
111
98
|
shared_examples 'executable rspec project' do |project_name|
|
|
112
99
|
let(:project) { project_name }
|
|
@@ -115,10 +102,10 @@ describe 'End-to-End Project Generation and Execution' do
|
|
|
115
102
|
expect(bundle_install(project)).to be true
|
|
116
103
|
end
|
|
117
104
|
|
|
118
|
-
it 'resolves raider_reporter
|
|
105
|
+
it 'resolves raider_reporter 1.x from RubyGems and ships the raider-reporter executable', :aggregate_failures do
|
|
119
106
|
skip 'Bundle install failed' unless bundle_install(project)
|
|
120
107
|
|
|
121
|
-
expect(File.read(File.join(project, 'Gemfile.lock'))).to match(/^ raider_reporter \(
|
|
108
|
+
expect(File.read(File.join(project, 'Gemfile.lock'))).to match(/^ raider_reporter \(1\.\d+\.\d+\)$/)
|
|
122
109
|
result = run_in_project(project, 'bundle exec raider-reporter --help', timeout: 60)
|
|
123
110
|
expect(result[:exit_code]).to eq(0), "STDOUT: #{result[:stdout]}\nSTDERR: #{result[:stderr]}"
|
|
124
111
|
expect(result[:stdout] + result[:stderr]).to include('raider-reporter comment')
|
|
@@ -155,116 +142,6 @@ describe 'End-to-End Project Generation and Execution' do
|
|
|
155
142
|
end
|
|
156
143
|
end
|
|
157
144
|
|
|
158
|
-
# Shared example for Cucumber-based projects
|
|
159
|
-
shared_examples 'executable cucumber project' do |project_name|
|
|
160
|
-
let(:project) { project_name }
|
|
161
|
-
|
|
162
|
-
it 'installs dependencies successfully' do
|
|
163
|
-
expect(bundle_install(project)).to be true
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
it 'runs generated Cucumber tests successfully', :slow do
|
|
167
|
-
skip 'Bundle install failed' unless bundle_install(project)
|
|
168
|
-
|
|
169
|
-
result = run_cucumber(project)
|
|
170
|
-
|
|
171
|
-
expect(result[:success]).to be(true),
|
|
172
|
-
"Cucumber tests failed with exit code #{result[:exit_code]}.\n" \
|
|
173
|
-
"STDOUT: #{result[:stdout]}\n" \
|
|
174
|
-
"STDERR: #{result[:stderr]}"
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
it 'resolves raider_reporter 0.10+ from RubyGems and requires its Cucumber plugin', :aggregate_failures do
|
|
178
|
-
skip 'Bundle install failed' unless bundle_install(project)
|
|
179
|
-
|
|
180
|
-
lockfile = File.read(File.join(project, 'Gemfile.lock'))
|
|
181
|
-
expect(lockfile).to match(/^ raider_reporter \(0\.1\d\.\d+\)$/)
|
|
182
|
-
expect(File.read(File.join(project, 'features/support/env.rb'))).to include("require 'raider_reporter/cucumber'")
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
it 'prints pretty output and keeps the exit status of a failing Cucumber run', :aggregate_failures, :slow do
|
|
186
|
-
skip 'Bundle install failed' unless bundle_install(project)
|
|
187
|
-
|
|
188
|
-
result = run_cucumber_with_failure(project)
|
|
189
|
-
|
|
190
|
-
expect(result[:stdout]).to include('Feature: Reporter failure')
|
|
191
|
-
expect(result[:stdout]).to include('Scenario: A deliberately failing scenario')
|
|
192
|
-
expect(result[:stdout]).to match(/\d+ scenarios? \(\d+ failed/)
|
|
193
|
-
expect(result[:exit_code]).to eq(1)
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
it 'writes rerun.txt listing only the failing scenario', :aggregate_failures, :slow do
|
|
197
|
-
skip 'Bundle install failed' unless bundle_install(project)
|
|
198
|
-
|
|
199
|
-
result = run_cucumber_with_failure(project)
|
|
200
|
-
|
|
201
|
-
expect(result[:exit_code]).to eq(1)
|
|
202
|
-
rerun = File.join(project, 'rerun.txt')
|
|
203
|
-
expect(File).to exist(rerun)
|
|
204
|
-
expect(File.read(rerun).strip).to eq('features/reporter_failure.feature:3')
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
it 'writes raider-results/run.json listing every scenario with a failing scenario screenshot',
|
|
208
|
-
:aggregate_failures, :slow do
|
|
209
|
-
skip 'Bundle install failed' unless bundle_install(project)
|
|
210
|
-
|
|
211
|
-
result = run_cucumber_with_failure(project)
|
|
212
|
-
summary = result[:stdout].match(/(\d+) scenarios? \((?:(\d+) failed)?/)
|
|
213
|
-
expect(summary).not_to be_nil, "No Cucumber summary line.\nSTDOUT: #{result[:stdout]}\nSTDERR: #{result[:stderr]}"
|
|
214
|
-
|
|
215
|
-
run = JSON.parse(File.read(File.join(project, 'raider-results', 'run.json')))
|
|
216
|
-
expect(run['schema_version']).to eq(1)
|
|
217
|
-
expect(run['results'].size).to eq(summary[1].to_i)
|
|
218
|
-
expect(run['results'].count { |r| r['status'] == 'failed' }).to eq(summary[2].to_i)
|
|
219
|
-
|
|
220
|
-
failing = run['results'].find { |r| r['full_name'] == 'Reporter failure: A deliberately failing scenario' }
|
|
221
|
-
expect(failing).not_to be_nil, "Scenario missing from run.json: #{run['results'].map { |r| r['full_name'] }}"
|
|
222
|
-
expect(failing['status']).to eq('failed')
|
|
223
|
-
expect(failing['file_path']).to eq('features/reporter_failure.feature')
|
|
224
|
-
expect(failing['failure']['message']).to start_with(
|
|
225
|
-
'Then the reporter records this failure (features/reporter_failure.feature:5)'
|
|
226
|
-
)
|
|
227
|
-
screenshot = failing['attachments'].find { |a| a['name'] == 'screenshot' }
|
|
228
|
-
expect(screenshot).not_to be_nil, "No screenshot attachment: #{failing['attachments']}"
|
|
229
|
-
expect(screenshot['content_type']).to eq('image/png')
|
|
230
|
-
end
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
# Runs the project's features plus a deliberately failing scenario, then removes that scenario again
|
|
234
|
-
def run_cucumber_with_failure(project)
|
|
235
|
-
add_failing_cucumber_scenario(project)
|
|
236
|
-
FileUtils.rm_rf([File.join(project, 'raider-results'), File.join(project, 'rerun.txt')])
|
|
237
|
-
run_cucumber(project)
|
|
238
|
-
ensure
|
|
239
|
-
remove_failing_cucumber_scenario(project)
|
|
240
|
-
end
|
|
241
|
-
|
|
242
|
-
# Adds a scenario that always fails at its last step, after the browser has been started
|
|
243
|
-
def add_failing_cucumber_scenario(project)
|
|
244
|
-
File.write(File.join(project, 'features/reporter_failure.feature'), <<~FEATURE)
|
|
245
|
-
Feature: Reporter failure
|
|
246
|
-
|
|
247
|
-
Scenario: A deliberately failing scenario
|
|
248
|
-
Given the reporter has a started scenario
|
|
249
|
-
Then the reporter records this failure
|
|
250
|
-
FEATURE
|
|
251
|
-
File.write(File.join(project, 'features/step_definitions/reporter_failure_steps.rb'), <<~STEPS)
|
|
252
|
-
# frozen_string_literal: true
|
|
253
|
-
|
|
254
|
-
Given('the reporter has a started scenario') {}
|
|
255
|
-
|
|
256
|
-
Then('the reporter records this failure') do
|
|
257
|
-
raise 'deliberate failure for raider_reporter'
|
|
258
|
-
end
|
|
259
|
-
STEPS
|
|
260
|
-
end
|
|
261
|
-
|
|
262
|
-
# Keeps the deliberate failure from leaking into the other examples that share the project
|
|
263
|
-
def remove_failing_cucumber_scenario(project)
|
|
264
|
-
FileUtils.rm_f(File.join(project, 'features/reporter_failure.feature'))
|
|
265
|
-
FileUtils.rm_f(File.join(project, 'features/step_definitions/reporter_failure_steps.rb'))
|
|
266
|
-
end
|
|
267
|
-
|
|
268
145
|
# Runs the project's own RuboCop with the gems its bundle resolved (newer than this gem's dev bundle).
|
|
269
146
|
# It runs from a copy outside this repo, as a user's project would: inside it RuboCop would also read
|
|
270
147
|
# this repo's .rubocop.yml, gemspec and .ruby-version.
|
|
@@ -289,6 +166,13 @@ describe 'End-to-End Project Generation and Execution' do
|
|
|
289
166
|
expect_project_rubocop_clean('rspec_selenium')
|
|
290
167
|
end
|
|
291
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
|
+
|
|
292
176
|
it 'saves the login once and reuses it', :aggregate_failures, :slow do
|
|
293
177
|
skip 'Bundle install failed' unless bundle_install('rspec_selenium')
|
|
294
178
|
|
|
@@ -312,22 +196,6 @@ describe 'End-to-End Project Generation and Execution' do
|
|
|
312
196
|
cookie_values.select { |value| value.length >= 8 }.each { |value| expect(output).not_to include(value) }
|
|
313
197
|
end
|
|
314
198
|
end
|
|
315
|
-
|
|
316
|
-
describe 'Watir + RSpec' do
|
|
317
|
-
include_examples 'executable rspec project', 'rspec_watir'
|
|
318
|
-
end
|
|
319
|
-
|
|
320
|
-
describe 'Selenium + Cucumber' do
|
|
321
|
-
include_examples 'executable cucumber project', 'cucumber_selenium'
|
|
322
|
-
|
|
323
|
-
it 'passes its own RuboCop with its bundled gems', :slow do
|
|
324
|
-
expect_project_rubocop_clean('cucumber_selenium')
|
|
325
|
-
end
|
|
326
|
-
end
|
|
327
|
-
|
|
328
|
-
describe 'Watir + Cucumber' do
|
|
329
|
-
include_examples 'executable cucumber project', 'cucumber_watir'
|
|
330
|
-
end
|
|
331
199
|
end
|
|
332
200
|
|
|
333
201
|
# Recorded Azure Pipelines env of a push (IndividualCI) build, see raider_reporter's CiDetector specs
|
|
@@ -380,12 +248,12 @@ describe 'End-to-End Project Generation and Execution' do
|
|
|
380
248
|
describe 'Selenium + RSpec' do
|
|
381
249
|
let(:project) { generate_azure_project('rspec') }
|
|
382
250
|
|
|
383
|
-
it 'ships azure-pipelines.yml and resolves raider_reporter
|
|
251
|
+
it 'ships azure-pipelines.yml and resolves raider_reporter 1.x', :aggregate_failures do
|
|
384
252
|
expect(File).to exist(File.join(project, 'azure-pipelines.yml'))
|
|
385
253
|
expect(File).not_to exist(File.join(project, '.github/workflows'))
|
|
386
254
|
skip 'Bundle install failed' unless bundle_install(project)
|
|
387
255
|
|
|
388
|
-
expect(File.read(File.join(project, 'Gemfile.lock'))).to match(/^ raider_reporter \(
|
|
256
|
+
expect(File.read(File.join(project, 'Gemfile.lock'))).to match(/^ raider_reporter \(1\.\d+\.\d+\)$/)
|
|
389
257
|
end
|
|
390
258
|
|
|
391
259
|
it 'records provider azure_pipelines and an azure_pipelines: build key in run.json', :aggregate_failures, :slow do
|
|
@@ -398,27 +266,6 @@ describe 'End-to-End Project Generation and Execution' do
|
|
|
398
266
|
expect_azure_ci_block(project)
|
|
399
267
|
end
|
|
400
268
|
end
|
|
401
|
-
|
|
402
|
-
describe 'Selenium + Cucumber' do
|
|
403
|
-
let(:project) { generate_azure_project('cucumber') }
|
|
404
|
-
|
|
405
|
-
it 'ships azure-pipelines.yml and resolves raider_reporter 0.10+', :aggregate_failures do
|
|
406
|
-
expect(File).to exist(File.join(project, 'azure-pipelines.yml'))
|
|
407
|
-
skip 'Bundle install failed' unless bundle_install(project)
|
|
408
|
-
|
|
409
|
-
expect(File.read(File.join(project, 'Gemfile.lock'))).to match(/^ raider_reporter \(0\.1\d\.\d+\)$/)
|
|
410
|
-
end
|
|
411
|
-
|
|
412
|
-
it 'records provider azure_pipelines and an azure_pipelines: build key in run.json', :aggregate_failures, :slow do
|
|
413
|
-
skip 'Bundle install failed' unless bundle_install(project)
|
|
414
|
-
|
|
415
|
-
FileUtils.rm_rf(File.join(project, 'raider-results'))
|
|
416
|
-
result = run_in_project(project, "#{azure_env_prefix} bundle exec cucumber features/ --format pretty",
|
|
417
|
-
timeout: 120)
|
|
418
|
-
expect(result[:success]).to be(true), "STDOUT: #{result[:stdout]}\nSTDERR: #{result[:stderr]}"
|
|
419
|
-
expect_azure_ci_block(project)
|
|
420
|
-
end
|
|
421
|
-
end
|
|
422
269
|
end
|
|
423
270
|
|
|
424
271
|
# An empty skeleton (examples: false) still passes its run, so its CI is green until tests are added
|
|
@@ -442,17 +289,36 @@ describe 'End-to-End Project Generation and Execution' do
|
|
|
442
289
|
expect(result[:stdout]).to include('0 examples, 0 failures')
|
|
443
290
|
end
|
|
444
291
|
end
|
|
292
|
+
end
|
|
445
293
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
294
|
+
# Browser e2e helpers shared by the failure video and the trace replay contexts
|
|
295
|
+
def browser_installed?(browser)
|
|
296
|
+
if browser == 'firefox'
|
|
297
|
+
ENV['FIREFOX_BINARY'] ? File.executable?(ENV['FIREFOX_BINARY']) : app_or_command?('Firefox', 'firefox')
|
|
298
|
+
else
|
|
299
|
+
app_or_command?('Google Chrome', 'google-chrome') || app_or_command?('Chromium', 'chromium')
|
|
300
|
+
end
|
|
301
|
+
end
|
|
449
302
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
303
|
+
def app_or_command?(app, command)
|
|
304
|
+
File.directory?("/Applications/#{app}.app") || system("command -v #{command} > /dev/null 2>&1")
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
# A separate project, so the default projects keep resolving raider_reporter 1.x from RubyGems
|
|
308
|
+
def generate_video_project(framework, automation)
|
|
309
|
+
name = "video_#{framework}_#{automation}"
|
|
310
|
+
unless LazyProjectGenerator::GENERATED.include?(name)
|
|
311
|
+
generate_framework(framework:, automation:, name:)
|
|
312
|
+
LazyProjectGenerator::GENERATED.add(name)
|
|
313
|
+
use_local_ruby_raider(name)
|
|
314
|
+
expect(run_in_project(name, 'bundle install --quiet', timeout: 300)[:success]).to be(true)
|
|
455
315
|
end
|
|
316
|
+
FileUtils.rm_rf(File.join(name, 'raider-results'))
|
|
317
|
+
name
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
def results(project)
|
|
321
|
+
JSON.parse(File.read(File.join(project, 'raider-results', 'run.json')))['results']
|
|
456
322
|
end
|
|
457
323
|
|
|
458
324
|
# Failure video replay against real browsers. Needs an ffmpeg with libvpx (RAIDER_FFMPEG_PATH), because the
|
|
@@ -470,31 +336,6 @@ describe 'End-to-End Project Generation and Execution' do
|
|
|
470
336
|
skip "#{browser} is not installed" unless browser_installed?(browser)
|
|
471
337
|
end
|
|
472
338
|
|
|
473
|
-
def browser_installed?(browser)
|
|
474
|
-
if browser == 'firefox'
|
|
475
|
-
ENV['FIREFOX_BINARY'] ? File.executable?(ENV['FIREFOX_BINARY']) : app_or_command?('Firefox', 'firefox')
|
|
476
|
-
else
|
|
477
|
-
app_or_command?('Google Chrome', 'google-chrome') || app_or_command?('Chromium', 'chromium')
|
|
478
|
-
end
|
|
479
|
-
end
|
|
480
|
-
|
|
481
|
-
def app_or_command?(app, command)
|
|
482
|
-
File.directory?("/Applications/#{app}.app") || system("command -v #{command} > /dev/null 2>&1")
|
|
483
|
-
end
|
|
484
|
-
|
|
485
|
-
# A separate project, so the default projects keep resolving raider_reporter 0.10+ from RubyGems
|
|
486
|
-
def generate_video_project(framework, automation)
|
|
487
|
-
name = "video_#{framework}_#{automation}"
|
|
488
|
-
unless LazyProjectGenerator::GENERATED.include?(name)
|
|
489
|
-
generate_framework(framework:, automation:, name:)
|
|
490
|
-
LazyProjectGenerator::GENERATED.add(name)
|
|
491
|
-
use_local_ruby_raider(name)
|
|
492
|
-
expect(run_in_project(name, 'bundle install --quiet', timeout: 300)[:success]).to be(true)
|
|
493
|
-
end
|
|
494
|
-
FileUtils.rm_rf(File.join(name, 'raider-results'))
|
|
495
|
-
name
|
|
496
|
-
end
|
|
497
|
-
|
|
498
339
|
def video_env(overrides = {})
|
|
499
340
|
{ 'HEADLESS' => 'true', 'RAIDER_FFMPEG_PATH' => ffmpeg_path, 'RAIDER_CACHE_DIR' => cache_dir,
|
|
500
341
|
'RAIDER_TOKEN' => nil, 'RAIDER_ENDPOINT' => nil, 'VIDEO' => nil }.merge(overrides)
|
|
@@ -527,45 +368,6 @@ describe 'End-to-End Project Generation and Execution' do
|
|
|
527
368
|
SPEC
|
|
528
369
|
end
|
|
529
370
|
|
|
530
|
-
def add_cucumber_video_feature(project, firefox_binary)
|
|
531
|
-
File.write(File.join(project, 'features/video_replay.feature'), <<~FEATURE)
|
|
532
|
-
Feature: Video replay
|
|
533
|
-
|
|
534
|
-
Scenario: A passing scenario
|
|
535
|
-
Given the video page is open
|
|
536
|
-
Then the video page title is "Video"
|
|
537
|
-
|
|
538
|
-
Scenario: A failing scenario
|
|
539
|
-
Given the video page is open
|
|
540
|
-
Then the video page title is "deliberate video failure"
|
|
541
|
-
FEATURE
|
|
542
|
-
File.write(File.join(project, 'features/step_definitions/video_replay_steps.rb'), <<~STEPS)
|
|
543
|
-
# frozen_string_literal: true
|
|
544
|
-
|
|
545
|
-
Given('the video page is open') do
|
|
546
|
-
browser.goto('#{page_url}')
|
|
547
|
-
browser.text_field(id: 'name').set('typed')
|
|
548
|
-
browser.button(id: 'go').click
|
|
549
|
-
end
|
|
550
|
-
|
|
551
|
-
Then('the video page title is {string}') do |title|
|
|
552
|
-
raise "expected title \#{title}" unless browser.h1(id: 'title').text == title
|
|
553
|
-
end
|
|
554
|
-
STEPS
|
|
555
|
-
config = File.join(project, 'config/config.yml')
|
|
556
|
-
File.write(config, File.read(config).sub(/^browser: .*$/, 'browser: firefox'))
|
|
557
|
-
# Test setup only: the generated templates do not read FIREFOX_BINARY.
|
|
558
|
-
File.write(File.join(project, 'features/support/zz_firefox_binary.rb'), <<~RUBY) if firefox_binary
|
|
559
|
-
# frozen_string_literal: true
|
|
560
|
-
|
|
561
|
-
Selenium::WebDriver::Firefox.path = ENV['FIREFOX_BINARY'] if ENV['FIREFOX_BINARY']
|
|
562
|
-
RUBY
|
|
563
|
-
end
|
|
564
|
-
|
|
565
|
-
def results(project)
|
|
566
|
-
JSON.parse(File.read(File.join(project, 'raider-results', 'run.json')))['results']
|
|
567
|
-
end
|
|
568
|
-
|
|
569
371
|
def video_files(project)
|
|
570
372
|
Dir.glob(File.join(project, 'raider-results', '**', '*.{webm,mp4}'))
|
|
571
373
|
end
|
|
@@ -631,28 +433,621 @@ describe 'End-to-End Project Generation and Execution' do
|
|
|
631
433
|
expect(Dir.glob(File.join(cache_dir, '**', '*'))).to be_empty
|
|
632
434
|
end
|
|
633
435
|
end
|
|
436
|
+
end
|
|
437
|
+
|
|
438
|
+
# Trace replay against headless Chrome, and one example on headless Firefox. The page is served over HTTP from this process (never file://), so
|
|
439
|
+
# WebDriver BiDi reports real network and console entries. raider_reporter ~> 1.0 resolves from RubyGems, or
|
|
440
|
+
# from a checkout at RAIDER_REPORTER_PATH. The example with video on also needs RAIDER_FFMPEG_PATH.
|
|
441
|
+
# Set TRACE_FIXTURE_DIR to keep the failing RSpec example's trace.zip (and an unzipped copy) there.
|
|
442
|
+
context 'Trace replay', :slow do
|
|
443
|
+
let!(:server) { TracePageServer.new }
|
|
444
|
+
let(:cache_dir) { Dir.mktmpdir('raider-cache') }
|
|
445
|
+
|
|
446
|
+
after do
|
|
447
|
+
server.stop
|
|
448
|
+
FileUtils.rm_rf(cache_dir)
|
|
449
|
+
end
|
|
450
|
+
|
|
451
|
+
# Typed into the secret fields; neither may reach the zip.
|
|
452
|
+
def secrets
|
|
453
|
+
%w[hunter2 s3cr3t]
|
|
454
|
+
end
|
|
455
|
+
|
|
456
|
+
# Typed into a plain field; it is kept as the step's value.
|
|
457
|
+
def plain_value
|
|
458
|
+
'plain-trace-name'
|
|
459
|
+
end
|
|
460
|
+
|
|
461
|
+
def skip_unless_trace_prerequisites(project, browser = 'chrome')
|
|
462
|
+
skip "#{browser == 'chrome' ? 'Google Chrome' : 'Firefox'} is not installed" unless browser_installed?(browser)
|
|
463
|
+
version = run_in_project(project, %(bundle exec ruby -e "require 'raider_reporter/version'; print RaiderReporter::VERSION"))
|
|
464
|
+
skip "the bundle does not resolve raider_reporter ~> 1.0 (set RAIDER_REPORTER_PATH): #{version[:stderr].lines.last}" unless
|
|
465
|
+
version[:success] && Gem::Version.new(version[:stdout]) >= Gem::Version.new('1.0')
|
|
466
|
+
end
|
|
467
|
+
|
|
468
|
+
def trace_env(overrides = {})
|
|
469
|
+
{ 'HEADLESS' => 'true', 'VIDEO' => 'off', 'TRACE' => nil, 'RAIDER_CACHE_DIR' => cache_dir,
|
|
470
|
+
'RAIDER_TOKEN' => nil, 'RAIDER_ENDPOINT' => nil }.merge(overrides)
|
|
471
|
+
end
|
|
472
|
+
|
|
473
|
+
def trace_attachments(result)
|
|
474
|
+
result['attachments'].select { |attachment| attachment['name'] == 'trace' }
|
|
475
|
+
end
|
|
476
|
+
|
|
477
|
+
def trace_files(project)
|
|
478
|
+
Dir.glob(File.join(project, 'raider-results', '**', '*trace.zip'))
|
|
479
|
+
end
|
|
480
|
+
|
|
481
|
+
def trace_zip(project, attachment)
|
|
482
|
+
File.join(project, 'raider-results', attachment['path'])
|
|
483
|
+
end
|
|
484
|
+
|
|
485
|
+
# { entry name => bytes } for every entry of the zip.
|
|
486
|
+
def zip_entries(path)
|
|
487
|
+
Zip::File.open(path) { |zip| zip.entries.to_h { |entry| [entry.name, entry.get_input_stream.read] } }
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
def result_named(project, name)
|
|
491
|
+
results(project).find { |result| result['full_name'].include?(name) }
|
|
492
|
+
end
|
|
493
|
+
|
|
494
|
+
def expect_run(result, exit_code: 1)
|
|
495
|
+
expect(result[:exit_code]).to eq(exit_code), "STDOUT: #{result[:stdout]}\nSTDERR: #{result[:stderr]}"
|
|
496
|
+
expect(result[:stderr]).not_to include('[trace]')
|
|
497
|
+
end
|
|
498
|
+
|
|
499
|
+
def expect_valid_trace(path)
|
|
500
|
+
expect(TraceFormatChecker.problems(path)).to be_empty
|
|
501
|
+
end
|
|
502
|
+
|
|
503
|
+
def keep_fixture(path)
|
|
504
|
+
dir = ENV.fetch('TRACE_FIXTURE_DIR', nil)
|
|
505
|
+
return unless dir
|
|
506
|
+
|
|
507
|
+
FileUtils.rm_rf(File.join(dir, 'unzipped'))
|
|
508
|
+
FileUtils.mkdir_p(File.join(dir, 'unzipped'))
|
|
509
|
+
FileUtils.cp(path, File.join(dir, 'trace.zip'))
|
|
510
|
+
zip_entries(path).each do |name, bytes|
|
|
511
|
+
FileUtils.mkdir_p(File.dirname(File.join(dir, 'unzipped', name)))
|
|
512
|
+
File.binwrite(File.join(dir, 'unzipped', name), bytes)
|
|
513
|
+
end
|
|
514
|
+
end
|
|
515
|
+
|
|
516
|
+
# The RSpec examples' names, spec file and readers, shared by the Chrome and Firefox examples.
|
|
517
|
+
def failing
|
|
518
|
+
'fails after driving the page'
|
|
519
|
+
end
|
|
520
|
+
|
|
521
|
+
def passing
|
|
522
|
+
'passes after driving the page'
|
|
523
|
+
end
|
|
524
|
+
|
|
525
|
+
# Drives the page with plain Selenium and the runtime's matchers, so the trace has action steps.
|
|
526
|
+
# Each example prints the driver's webSocketUrl, which is set only while tracing is on.
|
|
527
|
+
def add_rspec_trace_spec(project)
|
|
528
|
+
File.write(File.join(project, 'spec/trace_replay_spec.rb'), <<~SPEC)
|
|
529
|
+
# frozen_string_literal: true
|
|
530
|
+
|
|
531
|
+
require_relative '../helpers/spec_helper'
|
|
532
|
+
|
|
533
|
+
describe 'Trace replay' do
|
|
534
|
+
it '#{failing}' do
|
|
535
|
+
driver.navigate.to('#{server.url}start')
|
|
536
|
+
puts "TRACE_E2E_WEBSOCKET=\#{driver.capabilities[:web_socket_url].inspect}"
|
|
537
|
+
driver.find_element(id: 'pw').send_keys('#{secrets[0]}')
|
|
538
|
+
driver.find_element(id: 'pw2').send_keys('#{secrets[1]}')
|
|
539
|
+
form = driver.find_element(id: 'form')
|
|
540
|
+
form.find_element(id: 'name').send_keys('#{plain_value}')
|
|
541
|
+
driver.find_element(id: 'go').click
|
|
542
|
+
expect { driver.find_element(id: 'status') }.to have_text('answered by /api', wait: 5)
|
|
543
|
+
expect { driver.find_element(id: 'status').text }.to eq('answered by /api')
|
|
544
|
+
expect { driver.find_element(id: 'title') }.to have_text('deliberate trace failure', wait: 1)
|
|
545
|
+
end
|
|
546
|
+
|
|
547
|
+
it '#{passing}' do
|
|
548
|
+
driver.navigate.to('#{server.url}')
|
|
549
|
+
puts "TRACE_E2E_WEBSOCKET=\#{driver.capabilities[:web_socket_url].inspect}"
|
|
550
|
+
driver.find_element(id: 'name').send_keys('ok')
|
|
551
|
+
expect { driver.find_element(id: 'title') }.to have_text('Trace')
|
|
552
|
+
end
|
|
553
|
+
end
|
|
554
|
+
SPEC
|
|
555
|
+
end
|
|
556
|
+
|
|
557
|
+
def failing_trace(result)
|
|
558
|
+
expect(trace_attachments(result).size).to eq(1)
|
|
559
|
+
trace_zip(project, trace_attachments(result).first)
|
|
560
|
+
end
|
|
561
|
+
|
|
562
|
+
# Locators as id strategies, the chained find as within, the password steps masked, and no 3.x step shapes.
|
|
563
|
+
def expect_runtime_steps(steps)
|
|
564
|
+
by_id = ->(step) { step['locator'].is_a?(Hash) && step['locator']['strategy'] == 'id' && step['locator']['selector'].is_a?(String) }
|
|
565
|
+
expect(steps.select { |step| step['action'] == 'click' }).to all(satisfy(&by_id)).and(be_any)
|
|
566
|
+
expect(steps.select { |step| step['action'] == 'click' }.first['source']['file']).to end_with('spec/trace_replay_spec.rb')
|
|
567
|
+
typed = steps.select { |step| step['action'] == 'send_keys' }
|
|
568
|
+
expect(typed).to all(satisfy(&by_id))
|
|
569
|
+
expect(typed.last['locator']['within']).to be_a(Array).and(be_any)
|
|
570
|
+
expect(typed.first(2)).to all(include('value' => nil, 'secret' => true))
|
|
571
|
+
expect(steps.map { |step| step['kind'] }).not_to include('group')
|
|
572
|
+
expect(steps.map { |step| step['action'] }).not_to include('cucumber_step')
|
|
573
|
+
end
|
|
574
|
+
|
|
575
|
+
def steps_of(path)
|
|
576
|
+
TraceFormatChecker.read(path).first['steps']
|
|
577
|
+
end
|
|
578
|
+
|
|
579
|
+
# BiDi screenshots, so window_handle worked as the browsing context id: .jpg entries that are JPEGs.
|
|
580
|
+
def expect_jpeg_screenshots(path, names)
|
|
581
|
+
screenshots = names.grep(%r{\Asteps/\d{4}\.(jpg|png)\z})
|
|
582
|
+
expect(screenshots).not_to be_empty
|
|
583
|
+
expect(screenshots).to all(end_with('.jpg'))
|
|
584
|
+
entries = zip_entries(path)
|
|
585
|
+
screenshots.each { |name| expect(entries[name].byteslice(0, 2).bytes).to eq([0xFF, 0xD8]), name }
|
|
586
|
+
end
|
|
587
|
+
|
|
588
|
+
describe 'Selenium + RSpec on headless Chrome' do
|
|
589
|
+
let(:project) { 'video_rspec_selenium' }
|
|
590
|
+
let(:command) { 'bundle exec rspec spec/trace_replay_spec.rb' }
|
|
591
|
+
|
|
592
|
+
before do
|
|
593
|
+
generate_video_project('rspec', 'selenium')
|
|
594
|
+
skip_unless_trace_prerequisites(project)
|
|
595
|
+
add_rspec_trace_spec(project)
|
|
596
|
+
end
|
|
597
|
+
|
|
598
|
+
after { FileUtils.rm_f(File.join(project, 'spec/trace_replay_spec.rb')) }
|
|
599
|
+
|
|
600
|
+
# A navigate step (Selenium sends get through BiDi with web_socket_url set), and action steps whose
|
|
601
|
+
# elements have a label and a rect.
|
|
602
|
+
def expect_steps(steps)
|
|
603
|
+
expect(steps.map { |step| step['kind'] }).to include('navigate')
|
|
604
|
+
actions = steps.select { |step| %w[click send_keys].include?(step['action']) }
|
|
605
|
+
expect(actions.size).to eq(4)
|
|
606
|
+
expect(actions).to all(include('element' => include('label' => a_kind_of(String)), 'rect' => a_kind_of(Hash)))
|
|
607
|
+
end
|
|
608
|
+
|
|
609
|
+
def expect_network_and_console(trace)
|
|
610
|
+
api = trace['network'].find { |entry| entry['url'].to_s.end_with?('/api') }
|
|
611
|
+
expect(api).to include('method' => 'GET', 'status' => 200, 'mime_type' => 'application/json')
|
|
612
|
+
expect(api['bytes']).to be_positive
|
|
613
|
+
expect(api['duration_ms']).to be >= (TracePageServer::API_DELAY * 1000) - 50
|
|
614
|
+
expect(trace['console']).to include(include('level' => 'error', 'text' => a_string_including('trace e2e error')))
|
|
615
|
+
end
|
|
616
|
+
|
|
617
|
+
# /start redirects to /: two entries, one per hop, both credited to the navigate step.
|
|
618
|
+
def expect_redirect_hops(trace)
|
|
619
|
+
navigate = trace['steps'].find { |step| step['kind'] == 'navigate' }
|
|
620
|
+
start = trace['network'].find { |entry| entry['url'].to_s.end_with?('/start') }
|
|
621
|
+
page = trace['network'].find { |entry| entry['url'] == server.url }
|
|
622
|
+
expect(start).to include('status' => 302, 'step_index' => navigate['index'])
|
|
623
|
+
expect(page).to include('status' => 200, 'step_index' => navigate['index'])
|
|
624
|
+
expect(page['duration_ms']).to be >= (TracePageServer::PAGE_DELAY * 1000) - 50
|
|
625
|
+
end
|
|
626
|
+
|
|
627
|
+
# The same-origin stylesheet inlined as <style>, and the page's <script> gone.
|
|
628
|
+
def expect_sanitised_snapshots(path, names)
|
|
629
|
+
entries = zip_entries(path)
|
|
630
|
+
snapshots = names.grep(%r{\Asteps/\d{4}\.html\z}).map { |name| entries[name] }
|
|
631
|
+
expect(snapshots).not_to be_empty
|
|
632
|
+
expect(snapshots).to all(match(/<style[^>]*>[^<]*#{Regexp.escape(TracePageServer::CSS_RULE)}/))
|
|
633
|
+
expect(snapshots).to all(satisfy { |html| !html.match?(/<script/i) })
|
|
634
|
+
end
|
|
635
|
+
|
|
636
|
+
it 'attaches one trace.zip to the failing example only, valid against raider-trace v1, with network and console',
|
|
637
|
+
:aggregate_failures do
|
|
638
|
+
run = run_in_project(project, command, env: trace_env)
|
|
639
|
+
expect_run(run)
|
|
640
|
+
failed = result_named(project, failing)
|
|
641
|
+
attachment = trace_attachments(failed).first
|
|
642
|
+
path = failing_trace(failed)
|
|
643
|
+
keep_fixture(path)
|
|
644
|
+
|
|
645
|
+
expect(run[:stdout]).to include('TRACE_E2E_WEBSOCKET="ws://')
|
|
646
|
+
expect(attachment).to include('content_type' => 'application/vnd.raider.trace+zip', 'attempt' => 1)
|
|
647
|
+
expect(trace_attachments(result_named(project, passing))).to be_empty
|
|
648
|
+
expect(trace_files(project).size).to eq(1)
|
|
649
|
+
expect_valid_trace(path)
|
|
650
|
+
expect_runtime_steps(steps_of(path))
|
|
651
|
+
|
|
652
|
+
trace, names = TraceFormatChecker.read(path)
|
|
653
|
+
expect(trace['capabilities']).to include('network' => true, 'console' => true)
|
|
654
|
+
expect_steps(trace['steps'])
|
|
655
|
+
expect_jpeg_screenshots(path, names)
|
|
656
|
+
expect_network_and_console(trace)
|
|
657
|
+
expect_redirect_hops(trace)
|
|
658
|
+
expect_sanitised_snapshots(path, names)
|
|
659
|
+
end
|
|
660
|
+
|
|
661
|
+
it 'masks the typed password', :aggregate_failures do
|
|
662
|
+
run = run_in_project(project, command, env: trace_env)
|
|
663
|
+
expect_run(run)
|
|
664
|
+
path = failing_trace(result_named(project, failing))
|
|
665
|
+
|
|
666
|
+
zip_entries(path).each do |name, bytes|
|
|
667
|
+
secrets.each { |secret| expect(bytes.b).not_to include(secret.b), "#{secret} is in #{name}" }
|
|
668
|
+
end
|
|
669
|
+
typed = steps_of(path).select { |step| step['action'] == 'send_keys' }
|
|
670
|
+
expect(typed.size).to eq(3)
|
|
671
|
+
expect(typed.first(2)).to all(include('value' => nil, 'secret' => true))
|
|
672
|
+
expect(typed.last).to include('value' => plain_value, 'secret' => false)
|
|
673
|
+
end
|
|
674
|
+
|
|
675
|
+
it 'writes no trace and no web_socket_url with TRACE=off', :aggregate_failures do
|
|
676
|
+
run = run_in_project(project, command, env: trace_env('TRACE' => 'off', 'BIDI' => 'off'))
|
|
677
|
+
expect_run(run)
|
|
678
|
+
expect(run[:stdout].scan(/^TRACE_E2E_WEBSOCKET=(.*)$/).flatten).to eq(%w[nil nil])
|
|
679
|
+
expect(results(project).flat_map { |result| trace_attachments(result) }).to be_empty
|
|
680
|
+
expect(trace_files(project)).to be_empty
|
|
681
|
+
end
|
|
682
|
+
|
|
683
|
+
it 'keeps traces for passing examples too with TRACE=on', :aggregate_failures do
|
|
684
|
+
run = run_in_project(project, command, env: trace_env('TRACE' => 'on'))
|
|
685
|
+
expect_run(run)
|
|
686
|
+
[failing, passing].each do |name|
|
|
687
|
+
attachments = trace_attachments(result_named(project, name))
|
|
688
|
+
expect(attachments.size).to eq(1), "#{name} has #{attachments.size} traces"
|
|
689
|
+
expect_valid_trace(trace_zip(project, attachments.first)) if attachments.one?
|
|
690
|
+
end
|
|
691
|
+
expect(trace_files(project).size).to eq(2)
|
|
692
|
+
end
|
|
693
|
+
|
|
694
|
+
# Spec §2 Cost: tracing on failing tests (the default) costs under 15% of the wall-clock time.
|
|
695
|
+
# One warm-up run, then the modes interleaved, three runs each, compared by their medians.
|
|
696
|
+
# Opt-in: CI runs the integration specs on every PR, and runner jitter is the size of the margin.
|
|
697
|
+
it 'keeps the suite within 15% of its TRACE=off wall-clock time' do
|
|
698
|
+
skip 'set TRACE_OVERHEAD=1 to measure trace overhead' unless ENV['TRACE_OVERHEAD']
|
|
699
|
+
|
|
700
|
+
run_in_project(project, command, env: trace_env)
|
|
701
|
+
times = Hash.new { |hash, key| hash[key] = [] }
|
|
702
|
+
3.times do
|
|
703
|
+
{ 'off' => 'off', 'default' => nil }.each do |mode, value|
|
|
704
|
+
started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
705
|
+
expect_run(run_in_project(project, command, env: trace_env('TRACE' => value)))
|
|
706
|
+
times[mode] << (Process.clock_gettime(Process::CLOCK_MONOTONIC) - started)
|
|
707
|
+
end
|
|
708
|
+
end
|
|
709
|
+
off, traced = times.values_at('off', 'default').map { |runs| runs.sort[1] }
|
|
710
|
+
overhead = (traced - off) / off
|
|
711
|
+
puts format("\n[trace overhead] TRACE=off %<off>s, default %<default>s, medians %<o>.2fs vs %<t>.2fs: %<p>+.1f%%",
|
|
712
|
+
off: times['off'].map { |time| time.round(2) }, default: times['default'].map { |time| time.round(2) },
|
|
713
|
+
o: off, t: traced, p: overhead * 100)
|
|
714
|
+
expect(overhead).to be < 0.15
|
|
715
|
+
end
|
|
716
|
+
|
|
717
|
+
it 'attaches video.webm and trace.zip to the failing example with video on', :aggregate_failures do
|
|
718
|
+
ffmpeg = ENV.fetch('RAIDER_FFMPEG_PATH', '')
|
|
719
|
+
skip 'RAIDER_FFMPEG_PATH is not set to an executable ffmpeg with libvpx' unless
|
|
720
|
+
File.file?(ffmpeg) && File.executable?(ffmpeg)
|
|
721
|
+
|
|
722
|
+
run = run_in_project(project, command, env: trace_env('VIDEO' => nil, 'RAIDER_FFMPEG_PATH' => ffmpeg))
|
|
723
|
+
expect_run(run)
|
|
724
|
+
expect(run[:stderr]).not_to include('[video]')
|
|
725
|
+
attachments = result_named(project, failing)['attachments']
|
|
726
|
+
expect(attachments.map { |attachment| attachment['content_type'] })
|
|
727
|
+
.to include('video/webm', 'application/vnd.raider.trace+zip')
|
|
728
|
+
expect(attachments.map { |attachment| File.basename(attachment['path']) })
|
|
729
|
+
.to include(a_string_ending_with('video.webm'), a_string_ending_with('trace.zip'))
|
|
730
|
+
expect_valid_trace(failing_trace(result_named(project, failing)))
|
|
731
|
+
end
|
|
732
|
+
end
|
|
634
733
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
let(:
|
|
734
|
+
# The same RSpec project with config.yml set to firefox; Selenium Manager fetches geckodriver.
|
|
735
|
+
describe 'Selenium + RSpec on headless Firefox' do
|
|
736
|
+
let(:project) { 'video_rspec_selenium' }
|
|
737
|
+
let(:config) { File.join(project, 'config/config.yml') }
|
|
738
|
+
# Read before the switch to firefox and written back after, so the Chrome examples keep chrome.
|
|
739
|
+
let(:original_config) { File.read(config) }
|
|
638
740
|
|
|
639
741
|
before do
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
742
|
+
generate_video_project('rspec', 'selenium')
|
|
743
|
+
skip_unless_trace_prerequisites(project, 'firefox')
|
|
744
|
+
File.write(config, original_config.sub(/^browser: .*$/, 'browser: firefox'))
|
|
745
|
+
add_rspec_trace_spec(project)
|
|
643
746
|
end
|
|
644
747
|
|
|
645
748
|
after do
|
|
646
|
-
|
|
647
|
-
FileUtils.rm_f(File.join(project, '
|
|
749
|
+
File.write(config, original_config) if File.exist?(config)
|
|
750
|
+
FileUtils.rm_f(File.join(project, 'spec/trace_replay_spec.rb'))
|
|
648
751
|
end
|
|
649
752
|
|
|
650
|
-
it 'attaches
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
753
|
+
it 'attaches a trace.zip valid against raider-trace v1, with network, console and BiDi JPEG screenshots',
|
|
754
|
+
:aggregate_failures do
|
|
755
|
+
run = run_in_project(project, 'bundle exec rspec spec/trace_replay_spec.rb', env: trace_env, timeout: 240)
|
|
756
|
+
expect_run(run)
|
|
757
|
+
path = failing_trace(result_named(project, failing))
|
|
758
|
+
expect_valid_trace(path)
|
|
759
|
+
expect_runtime_steps(steps_of(path))
|
|
760
|
+
|
|
761
|
+
trace, names = TraceFormatChecker.read(path)
|
|
762
|
+
expect(trace['browser']).to include('name' => 'firefox')
|
|
763
|
+
expect(trace['capabilities']).to include('network' => true, 'console' => true)
|
|
764
|
+
expect_jpeg_screenshots(path, names)
|
|
765
|
+
api = trace['network'].find { |entry| entry['url'].to_s.end_with?('/api') }
|
|
766
|
+
expect(api).to include('status' => 200)
|
|
767
|
+
expect(api && api['duration_ms']).to be_a(Integer).and be_positive
|
|
768
|
+
end
|
|
769
|
+
end
|
|
770
|
+
|
|
771
|
+
# mock_request / block_request through WebDriver BiDi, on a page that fetches /api/* and a cross-origin URL
|
|
772
|
+
# that exists nowhere (so it only answers when mocked). Chrome by default; Edge and Firefox run only when
|
|
773
|
+
# RAIDER_E2E_BROWSERS (comma separated) lists them.
|
|
774
|
+
describe 'Network mocking' do
|
|
775
|
+
let(:project) { 'video_rspec_selenium' }
|
|
776
|
+
let(:original_config) { File.read(config) }
|
|
777
|
+
|
|
778
|
+
def config
|
|
779
|
+
File.join(project, 'config/config.yml')
|
|
780
|
+
end
|
|
781
|
+
|
|
782
|
+
def spec_path
|
|
783
|
+
File.join(project, 'spec/network_mocking_spec.rb')
|
|
784
|
+
end
|
|
785
|
+
|
|
786
|
+
def opted_in?(browser)
|
|
787
|
+
ENV.fetch('RAIDER_E2E_BROWSERS', '').split(',').map(&:strip).include?(browser)
|
|
788
|
+
end
|
|
789
|
+
|
|
790
|
+
def skip_unless_mocking_prerequisites(browser)
|
|
791
|
+
skip "set RAIDER_E2E_BROWSERS=#{browser} to run network mocking on #{browser}" unless browser == 'chrome' || opted_in?(browser)
|
|
792
|
+
skip 'Microsoft Edge is not installed' if browser == 'edge' && !File.directory?('/Applications/Microsoft Edge.app')
|
|
793
|
+
skip_unless_trace_prerequisites(project, browser == 'firefox' ? 'firefox' : 'chrome')
|
|
794
|
+
end
|
|
795
|
+
|
|
796
|
+
def write_spec(body)
|
|
797
|
+
File.write(spec_path, <<~SPEC)
|
|
798
|
+
# frozen_string_literal: true
|
|
799
|
+
|
|
800
|
+
require_relative '../helpers/spec_helper'
|
|
801
|
+
|
|
802
|
+
describe 'Network mocking' do
|
|
803
|
+
#{body.lines.map { |line| line.strip.empty? ? line : " #{line}" }.join}
|
|
804
|
+
end
|
|
805
|
+
SPEC
|
|
806
|
+
end
|
|
807
|
+
|
|
808
|
+
def mocking_run(overrides = {})
|
|
809
|
+
run_in_project(project, 'bundle exec rspec spec/network_mocking_spec.rb', env: trace_env(overrides), timeout: 240)
|
|
810
|
+
end
|
|
811
|
+
|
|
812
|
+
def mock_example(browser)
|
|
813
|
+
write_spec(<<~BODY)
|
|
814
|
+
it 'mocks, blocks, edits and removes' do
|
|
815
|
+
driver.navigate.to('#{server.url}mock')
|
|
816
|
+
users = mock_request('#{server.url}api/users', json: { users: ['ana'] })
|
|
817
|
+
block_request('**/api/fail')
|
|
818
|
+
mock_request('**/api/echo') { { continue: { headers: { 'x-raider' => 'yes' } } } }
|
|
819
|
+
mock_request('http://mock.raider.test/api/cors', json: { ok: true })
|
|
820
|
+
driver.find_element(id: 'users').click
|
|
821
|
+
expect { driver.find_element(id: 'users-out') }.to have_text('ana', wait: 5)
|
|
822
|
+
driver.find_element(id: 'fail').click
|
|
823
|
+
expect { driver.find_element(id: 'fail-out') }.to have_text('request failed', wait: 5)
|
|
824
|
+
driver.find_element(id: 'echo').click
|
|
825
|
+
expect { driver.find_element(id: 'echo-out') }.to have_text('echo yes', wait: 5)
|
|
826
|
+
driver.find_element(id: 'cors').click
|
|
827
|
+
expect { driver.find_element(id: 'cors-out') }.to have_text('cors true', wait: 5)
|
|
828
|
+
expect { users.calls.size }.to eq(1)
|
|
829
|
+
expect { users.called? }.to be(true)
|
|
830
|
+
remove_mock(users)
|
|
831
|
+
driver.find_element(id: 'users').click
|
|
832
|
+
expect { driver.find_element(id: 'users-out') }.to have_text('real', wait: 5)
|
|
833
|
+
expect { users.calls.size }.to eq(1)
|
|
834
|
+
puts 'NETWORK_MOCKING_#{browser.upcase}_DONE'
|
|
835
|
+
end
|
|
836
|
+
BODY
|
|
837
|
+
end
|
|
838
|
+
|
|
839
|
+
def switch_browser(name)
|
|
840
|
+
# The generated config carries browser arguments for chrome and firefox only.
|
|
841
|
+
edge_args = " edge:\n - no-sandbox\n"
|
|
842
|
+
File.write(config, original_config.sub(/^browser: .*$/, "browser: #{name}").sub(/^ firefox:/, "#{edge_args} firefox:"))
|
|
843
|
+
end
|
|
844
|
+
|
|
845
|
+
# Skips when the browser is unavailable or not opted in; otherwise points the config at it.
|
|
846
|
+
def use_browser(name)
|
|
847
|
+
skip_unless_mocking_prerequisites(name)
|
|
848
|
+
original_config
|
|
849
|
+
switch_browser(name)
|
|
850
|
+
end
|
|
851
|
+
|
|
852
|
+
before { generate_video_project('rspec', 'selenium') }
|
|
853
|
+
|
|
854
|
+
after do
|
|
855
|
+
File.write(config, original_config) if File.exist?(config)
|
|
856
|
+
FileUtils.rm_f(spec_path)
|
|
857
|
+
end
|
|
858
|
+
|
|
859
|
+
%w[chrome edge firefox].each do |name|
|
|
860
|
+
it "mocks, blocks, edits headers and removes a mock on headless #{name}", :aggregate_failures do
|
|
861
|
+
use_browser(name)
|
|
862
|
+
mock_example(name)
|
|
863
|
+
run = mocking_run('TRACE' => 'off')
|
|
864
|
+
expect_run(run, exit_code: 0)
|
|
865
|
+
expect(run[:stdout]).to include("NETWORK_MOCKING_#{name.upcase}_DONE")
|
|
866
|
+
end
|
|
867
|
+
end
|
|
868
|
+
|
|
869
|
+
def write_failing_spec
|
|
870
|
+
write_spec(<<~BODY)
|
|
871
|
+
it 'fails after mocking' do
|
|
872
|
+
driver.navigate.to('#{server.url}mock')
|
|
873
|
+
mock_request('#{server.url}api/users', json: { users: ['ana'] })
|
|
874
|
+
block_request('#{server.url}api/fail')
|
|
875
|
+
driver.find_element(id: 'users').click
|
|
876
|
+
expect { driver.find_element(id: 'users-out') }.to have_text('ana', wait: 5)
|
|
877
|
+
driver.find_element(id: 'fail').click
|
|
878
|
+
expect { driver.find_element(id: 'fail-out') }.to have_text('request failed', wait: 5)
|
|
879
|
+
expect { driver.find_element(id: 'users-out') }.to have_text('deliberate mocking failure', wait: 1)
|
|
880
|
+
end
|
|
881
|
+
BODY
|
|
882
|
+
end
|
|
883
|
+
|
|
884
|
+
it 'keeps mocked entries in the failing example trace', :aggregate_failures do
|
|
885
|
+
use_browser('chrome')
|
|
886
|
+
write_failing_spec
|
|
887
|
+
expect_run(mocking_run)
|
|
888
|
+
path = failing_trace(result_named(project, 'fails after mocking'))
|
|
889
|
+
keep_fixture(path)
|
|
890
|
+
expect_valid_trace(path)
|
|
891
|
+
network = TraceFormatChecker.read(path).first['network']
|
|
892
|
+
users = network.find { |entry| entry['url'].to_s.end_with?('/api/users') }
|
|
893
|
+
failed = network.find { |entry| entry['url'].to_s.end_with?('/api/fail') }
|
|
894
|
+
expect(users).to include('mocked' => 'fulfilled', 'status' => 200)
|
|
895
|
+
expect(failed).to include('mocked' => 'failed')
|
|
896
|
+
end
|
|
897
|
+
|
|
898
|
+
it 'fails the example with MockError when a block raises', :aggregate_failures do
|
|
899
|
+
use_browser('chrome')
|
|
900
|
+
write_spec(<<~BODY)
|
|
901
|
+
it 'has a raising block' do
|
|
902
|
+
driver.navigate.to('#{server.url}mock')
|
|
903
|
+
mock_request('#{server.url}api/users') { raise 'boom from the block' }
|
|
904
|
+
driver.find_element(id: 'users').click
|
|
905
|
+
expect { driver.find_element(id: 'users-out') }.to have_text('users failed', wait: 5)
|
|
906
|
+
end
|
|
907
|
+
BODY
|
|
908
|
+
run = mocking_run('TRACE' => 'off')
|
|
909
|
+
expect(run[:exit_code]).to eq(1), "STDOUT: #{run[:stdout]}\nSTDERR: #{run[:stderr]}"
|
|
910
|
+
expect(run[:stdout]).to include('NetworkHelper::MockError', 'boom from the block')
|
|
911
|
+
end
|
|
912
|
+
end
|
|
913
|
+
end
|
|
914
|
+
|
|
915
|
+
# match_screenshot against real browsers, on a fixed data: page (no server, no animation). Chrome by default; Edge and
|
|
916
|
+
# Firefox run only when RAIDER_E2E_BROWSERS (comma separated) lists them. The generated spec recolours the page
|
|
917
|
+
# when SHOT_VARIANT=changed. raider_reporter comes from RubyGems (no `comparison` method yet), so the images are
|
|
918
|
+
# attached and one warning is printed; the report's comparisons field is not asserted here.
|
|
919
|
+
context 'Screenshot comparison', :slow do
|
|
920
|
+
let(:cache_dir) { Dir.mktmpdir('raider-cache') }
|
|
921
|
+
let(:baseline) { "screenshots/baselines/#{browser_name}/home.png" }
|
|
922
|
+
let(:original_config) { File.read(config_path) }
|
|
923
|
+
|
|
924
|
+
after do
|
|
925
|
+
File.write(config_path, original_config) if File.exist?(config_path)
|
|
926
|
+
FileUtils.rm_rf(File.join(project, 'screenshots'))
|
|
927
|
+
FileUtils.rm_f(File.join(project, 'spec/screenshot_comparison_spec.rb'))
|
|
928
|
+
FileUtils.rm_rf(cache_dir)
|
|
929
|
+
end
|
|
930
|
+
|
|
931
|
+
def config_path
|
|
932
|
+
File.join(project, 'config/config.yml')
|
|
933
|
+
end
|
|
934
|
+
|
|
935
|
+
def shot_page
|
|
936
|
+
html = '<body style="margin:0;font-family:monospace"><h1 id="title">Screenshot</h1><p>Fixed content</p></body>'
|
|
937
|
+
"data:text/html,#{ERB::Util.url_encode(html)}"
|
|
938
|
+
end
|
|
939
|
+
|
|
940
|
+
def recolour
|
|
941
|
+
"document.documentElement.style.background = 'rgb(200, 0, 0)'; document.body.style.background = 'rgb(200, 0, 0)'"
|
|
942
|
+
end
|
|
943
|
+
|
|
944
|
+
def shot_env(overrides = {})
|
|
945
|
+
ci = %w[CI GITHUB_ACTIONS GITLAB_CI JENKINS_URL BUILDKITE CIRCLECI TF_BUILD TRAVIS].to_h { |key| [key, nil] }
|
|
946
|
+
ci.merge('HEADLESS' => 'true', 'VIDEO' => 'off', 'TRACE' => 'off', 'RAIDER_CACHE_DIR' => cache_dir,
|
|
947
|
+
'RAIDER_TOKEN' => nil, 'RAIDER_ENDPOINT' => nil, 'SCREENSHOTS' => nil, 'SHOT_VARIANT' => nil).merge(overrides)
|
|
948
|
+
end
|
|
949
|
+
|
|
950
|
+
def use_browser(name)
|
|
951
|
+
opted_in = ENV.fetch('RAIDER_E2E_BROWSERS', '').split(',').map(&:strip).include?(name)
|
|
952
|
+
skip "set RAIDER_E2E_BROWSERS=#{name} to run screenshot comparison on #{name}" unless name == 'chrome' || opted_in
|
|
953
|
+
skip 'Microsoft Edge is not installed' if name == 'edge' && !File.directory?('/Applications/Microsoft Edge.app')
|
|
954
|
+
skip "#{name} is not installed" unless name == 'edge' || browser_installed?(name == 'firefox' ? 'firefox' : 'chrome')
|
|
955
|
+
@browser_name = name
|
|
956
|
+
original_config
|
|
957
|
+
edge_args = " edge:\n - no-sandbox\n"
|
|
958
|
+
File.write(config_path, original_config.sub(/^browser: .*$/, "browser: #{name}").sub(/^ firefox:/, "#{edge_args} firefox:"))
|
|
959
|
+
end
|
|
960
|
+
|
|
961
|
+
attr_reader :browser_name
|
|
962
|
+
|
|
963
|
+
def attachment_names(project)
|
|
964
|
+
results(project).flat_map { |result| result['attachments'].map { |attachment| attachment['name'] } }
|
|
965
|
+
end
|
|
966
|
+
|
|
967
|
+
def comparison_names(project)
|
|
968
|
+
attachment_names(project).grep(/\Acomparison:/)
|
|
969
|
+
end
|
|
970
|
+
|
|
971
|
+
def baseline_path
|
|
972
|
+
File.join(project, baseline)
|
|
973
|
+
end
|
|
974
|
+
|
|
975
|
+
def write_rspec_spec
|
|
976
|
+
File.write(File.join(project, 'spec/screenshot_comparison_spec.rb'), <<~SPEC)
|
|
977
|
+
# frozen_string_literal: true
|
|
978
|
+
|
|
979
|
+
require_relative '../helpers/spec_helper'
|
|
980
|
+
|
|
981
|
+
describe 'Screenshot comparison' do
|
|
982
|
+
it 'matches home' do
|
|
983
|
+
driver.navigate.to('#{shot_page}')
|
|
984
|
+
driver.execute_script("#{recolour}") if ENV['SHOT_VARIANT'] == 'changed'
|
|
985
|
+
match_screenshot('home')
|
|
986
|
+
end
|
|
987
|
+
end
|
|
988
|
+
SPEC
|
|
989
|
+
end
|
|
990
|
+
|
|
991
|
+
# Every failure message in run.json, as text.
|
|
992
|
+
def failure_text(project)
|
|
993
|
+
results(project).to_json
|
|
994
|
+
end
|
|
995
|
+
|
|
996
|
+
def expect_ok(run)
|
|
997
|
+
expect(run[:exit_code]).to eq(0), "STDOUT: #{run[:stdout]}\nSTDERR: #{run[:stderr]}"
|
|
998
|
+
end
|
|
999
|
+
|
|
1000
|
+
def expect_failed(run)
|
|
1001
|
+
expect(run[:exit_code]).to eq(1), "STDOUT: #{run[:stdout]}\nSTDERR: #{run[:stderr]}"
|
|
1002
|
+
end
|
|
1003
|
+
|
|
1004
|
+
# The five runs of the plan, in order; each block is one run of the generated test.
|
|
1005
|
+
def walk_through(command)
|
|
1006
|
+
run = proc do |overrides = {}|
|
|
1007
|
+
FileUtils.rm_rf(File.join(project, 'raider-results'))
|
|
1008
|
+
run_in_project(project, command, env: shot_env(overrides), timeout: 300)
|
|
1009
|
+
end
|
|
1010
|
+
|
|
1011
|
+
expect_ok(run.call) # 1: creates the baseline
|
|
1012
|
+
expect(File).to exist(baseline_path)
|
|
1013
|
+
expect(File.binread(baseline_path)).to start_with("\x89PNG".b)
|
|
1014
|
+
first_bytes = File.binread(baseline_path)
|
|
1015
|
+
|
|
1016
|
+
expect_ok(run.call) # 2: matches
|
|
1017
|
+
expect(comparison_names(project)).to be_empty
|
|
1018
|
+
|
|
1019
|
+
different = run.call('SHOT_VARIANT' => 'changed') # 3: differs
|
|
1020
|
+
expect_failed(different)
|
|
1021
|
+
expect(comparison_names(project)).to include('comparison:home:expected', 'comparison:home:actual', 'comparison:home:diff')
|
|
1022
|
+
expect(failure_text(project)).to include(baseline)
|
|
1023
|
+
expect(File.binread(baseline_path)).to eq(first_bytes)
|
|
1024
|
+
expect(different[:stderr].scan('[screenshots] this raider_reporter has no comparison method').size).to be <= 1
|
|
1025
|
+
|
|
1026
|
+
FileUtils.rm_f(baseline_path) # 4: CI without a baseline
|
|
1027
|
+
missing = run.call('CI' => '1')
|
|
1028
|
+
expect_failed(missing)
|
|
1029
|
+
expect(File).not_to exist(baseline_path)
|
|
1030
|
+
expect(failure_text(project)).to include('no baseline')
|
|
1031
|
+
|
|
1032
|
+
expect_ok(run.call('SCREENSHOTS' => 'update')) # 5: update rewrites
|
|
1033
|
+
expect(File).to exist(baseline_path)
|
|
1034
|
+
expect_ok(run.call('SHOT_VARIANT' => 'changed', 'SCREENSHOTS' => 'update'))
|
|
1035
|
+
expect(File.binread(baseline_path)).not_to eq(first_bytes)
|
|
1036
|
+
end
|
|
1037
|
+
|
|
1038
|
+
%w[chrome edge firefox].each do |name|
|
|
1039
|
+
describe "Selenium + RSpec on headless #{name}" do
|
|
1040
|
+
let(:project) { 'video_rspec_selenium' }
|
|
1041
|
+
|
|
1042
|
+
before do
|
|
1043
|
+
generate_video_project('rspec', 'selenium')
|
|
1044
|
+
use_browser(name)
|
|
1045
|
+
write_rspec_spec
|
|
1046
|
+
end
|
|
1047
|
+
|
|
1048
|
+
it 'creates, matches, fails with images, refuses on CI and updates', :aggregate_failures do
|
|
1049
|
+
walk_through('bundle exec rspec spec/screenshot_comparison_spec.rb')
|
|
1050
|
+
end
|
|
656
1051
|
end
|
|
657
1052
|
end
|
|
658
1053
|
end
|
|
@@ -672,19 +1067,6 @@ describe 'End-to-End Project Generation and Execution' do
|
|
|
672
1067
|
end
|
|
673
1068
|
end
|
|
674
1069
|
|
|
675
|
-
describe 'iOS + Cucumber' do
|
|
676
|
-
it 'generates valid project structure' do
|
|
677
|
-
expect(File).to exist('cucumber_ios/features/support/env.rb')
|
|
678
|
-
expect(File).to exist('cucumber_ios/Gemfile')
|
|
679
|
-
expect(File).to exist('cucumber_ios/features')
|
|
680
|
-
end
|
|
681
|
-
|
|
682
|
-
it 'has valid Ruby syntax in generated files' do
|
|
683
|
-
result = run_in_project('cucumber_ios', 'ruby -c features/support/env.rb')
|
|
684
|
-
expect(result[:success]).to be true
|
|
685
|
-
end
|
|
686
|
-
end
|
|
687
|
-
|
|
688
1070
|
describe 'Android + RSpec' do
|
|
689
1071
|
it 'generates valid project structure' do
|
|
690
1072
|
expect(File).to exist('rspec_android/helpers/spec_helper.rb')
|
|
@@ -698,19 +1080,6 @@ describe 'End-to-End Project Generation and Execution' do
|
|
|
698
1080
|
end
|
|
699
1081
|
end
|
|
700
1082
|
|
|
701
|
-
describe 'Android + Cucumber' do
|
|
702
|
-
it 'generates valid project structure' do
|
|
703
|
-
expect(File).to exist('cucumber_android/features/support/env.rb')
|
|
704
|
-
expect(File).to exist('cucumber_android/Gemfile')
|
|
705
|
-
expect(File).to exist('cucumber_android/features')
|
|
706
|
-
end
|
|
707
|
-
|
|
708
|
-
it 'has valid Ruby syntax in generated files' do
|
|
709
|
-
result = run_in_project('cucumber_android', 'ruby -c features/support/env.rb')
|
|
710
|
-
expect(result[:success]).to be true
|
|
711
|
-
end
|
|
712
|
-
end
|
|
713
|
-
|
|
714
1083
|
describe 'Cross-Platform + RSpec' do
|
|
715
1084
|
it 'generates valid project structure' do
|
|
716
1085
|
expect(File).to exist('rspec_cross_platform/helpers/appium_helper.rb')
|
|
@@ -723,19 +1092,6 @@ describe 'End-to-End Project Generation and Execution' do
|
|
|
723
1092
|
expect(result[:success]).to be true
|
|
724
1093
|
end
|
|
725
1094
|
end
|
|
726
|
-
|
|
727
|
-
describe 'Cross-Platform + Cucumber' do
|
|
728
|
-
it 'generates valid project structure' do
|
|
729
|
-
expect(File).to exist('cucumber_cross_platform/helpers/appium_helper.rb')
|
|
730
|
-
expect(File).to exist('cucumber_cross_platform/Gemfile')
|
|
731
|
-
expect(File).to exist('cucumber_cross_platform/features')
|
|
732
|
-
end
|
|
733
|
-
|
|
734
|
-
it 'has valid Ruby syntax in generated files' do
|
|
735
|
-
result = run_in_project('cucumber_cross_platform', 'ruby -c features/support/env.rb')
|
|
736
|
-
expect(result[:success]).to be true
|
|
737
|
-
end
|
|
738
|
-
end
|
|
739
1095
|
end
|
|
740
1096
|
|
|
741
1097
|
# Verify template system performance (caching working)
|