Skip to content

Instantly share code, notes, and snippets.

@prashanth-sams
Created February 29, 2020 13:12
Show Gist options
  • Save prashanth-sams/1a1cf02095f51201f67acd896c088d01 to your computer and use it in GitHub Desktop.
Save prashanth-sams/1a1cf02095f51201f67acd896c088d01 to your computer and use it in GitHub Desktop.
Export Ruby automation results to DataDog - Cucumber
Before do |scenario|
$dd_data ||= []
$dd_passed = $dd_failed = $dd_pending = 0
end
After do |scenario|
if $dd_data
case scenario.status
when :failed
status_id = 0
when :passed
status_id = 1
when :skipped, :pending
status_id = 2
else
raise 'unable to get the scenario status'
end
$dd_data << {'status_id' => status_id, 'scenario' => scenario.name}
end
end
at_exit do
if $dd_data
$dd_data.map do |value|
$dd_failed += 1 if value['status_id'] == 0
$dd_passed += 1 if value['status_id'] == 1
$dd_pending += 1 if value['status_id'] == 2
end
dog = Dogapi::Client.new(ENV['API_KEY'], ENV['APP_KEY'])
dog.batch_metrics do
dog.emit_point("qa.automation.passed", $dd_passed)
dog.emit_point("qa.automation.failed", $dd_failed)
dog.emit_point("qa.automation.pending", $dd_pending)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment