Skip to content

Commit

Permalink
test: ✅ rewrite scoped test step
Browse files Browse the repository at this point in the history
  • Loading branch information
gingerbenw committed Jul 10, 2023
1 parent 6878def commit c4751bd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
12 changes: 9 additions & 3 deletions test/browser/features/resource-load-spans.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ Feature: Resource Load Spans
And the trace payload field "resourceSpans.0.scopeSpans.0.spans.1" string attribute "http.flavor" equals "1.1"

# Image status code and body size have patchy browser coverage
And on the browser Chrome 109: the trace payload field "resourceSpans.0.scopeSpans.0.spans.1" integer attribute "http.status_code" equals 200
And on Chrome versions >= 109:
"""
the trace payload field "resourceSpans.0.scopeSpans.0.spans.1" integer attribute "http.status_code" equals 200
"""

# Actually Safari 16.4 but our test devices currently use 16.3, this can be dropped to 16 when the devices update
And on the browsers Chrome 54, Android 54, Safari 17, iOS 17, Firefox 45, Edge 17: the trace payload field "resourceSpans.0.scopeSpans.0.spans.1" integer attribute "http.response_content_length" equals 2202
And on the browsers Chrome 54, Android 54, Safari 17, iOS 17, Firefox 45, Edge 17: the trace payload field "resourceSpans.0.scopeSpans.0.spans.1" integer attribute "http.response_content_length_uncompressed" equals 2202
And on Chrome versions >= 54, Android versions >= 54, Safari versions >= 17, iOS versions >= 17, Firefox versions >= 45, Edge versions >= 17:
"""
the trace payload field "resourceSpans.0.scopeSpans.0.spans.1" integer attribute "http.response_content_length" equals 2202
the trace payload field "resourceSpans.0.scopeSpans.0.spans.1" integer attribute "http.response_content_length_uncompressed" equals 2202
"""
30 changes: 21 additions & 9 deletions test/browser/features/steps/browser-steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,29 @@
end
end

Then(/^on the (?:browser|browsers) (.*): (.+)/) do |spec, step_text|
current_platform = $browser.name
current_version = $browser.version

browsers = spec.split(",")
Then(/^on ((?:[A-z]+ versions (?:>=?|<=?|==) [0-9.]+(?:, )?)+):$/) do |browser_specs, steps_to_run|
spec_matcher = /^([A-z]+) versions (>=?|<=?|==) ([0-9.]+)$/

for browser in browsers do
name, version = browser.split(" ")
step(step_text) if current_platform.casecmp(name).zero? && current_version >= version.to_i
end
browser_specs.split(", ").each do |browser_spec|
browser_spec.scan(spec_matcher) do |name, operator, version|
should_run_steps = $browser.name.casecmp?(name) && $browser.version.send(operator, version.to_i)

# make sure this step is debuggable!
$logger.debug("#{$browser.name} == #{name} && v#{$browser.version} #{operator} #{version}? #{should_run_steps}")

if should_run_steps
steps_to_run.each_line(chomp: true) do |step_to_run|
step(step_to_run)
end
else
indent = " " * 4
# e.g. "a step\nanother step\n" -> " 1) a step\n 2) another step"
steps_indented = steps_to_run.each_line.map.with_index(1) { |step, i| "#{indent}#{i}) #{step.chomp}" }.join("\n")

$logger.info("Skipping steps on #{$browser.name} v#{$browser.version}:\n#{steps_indented}")
end
end
end
end

module Maze
Expand Down

0 comments on commit c4751bd

Please sign in to comment.