Skip to content

Instantly share code, notes, and snippets.

@briandunn
Created March 5, 2014 19:14
Show Gist options
  • Save briandunn/9374386 to your computer and use it in GitHub Desktop.
Save briandunn/9374386 to your computer and use it in GitHub Desktop.
def get_step_name(scenario)
if Cucumber::Ast::OutlineTable::ExampleRow === scenario
outline = scenario
return outline.backtrace_line
else
scenario.instance_variable_get :@current_step
visitor = scenario.instance_variable_get :@current_visitor
listeners = visitor.instance_variable_get :@listeners
formatter = listeners.first
step = formatter.instance_variable_get :@current_step
step.name
end
end
AfterStep do |scenario|
require 'pry'; binding.pry;
root = "images_#{DateTime.now.strftime("%m%d%y%H%M%S")}"
feature_name = scenario.feature.name.parameterize unless Cucumber::Ast::OutlineTable::ExampleRow === scenario
feature_name = scenario.scenario_outline.name.parameterize if Cucumber::Ast::OutlineTable::ExampleRow === scenario
scenario_name = scenario.name.parameterize
step_name = get_step_name(scenario).parameterize
dir = File.join("gold", root, scenario_name, feature_name)
dir = Rails.root.join(dir)
FileUtils.mkdir_p(dir)
save_screenshot(File.join(dir, "#{step_name}.png"))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment