Htmlcuke
A custom Html formatter for Cucumber that provides specific functionality.
This formatter removes (if necessary) any color codes wrapped around puts statements within a suite that is using the colorized or similar gem.
The formatter also embeds a screenshot link of the last window focused in a failed test and opens the shot in a new tab upon clicking the link as well as providing custom buttons with hover and switch-text click functionality to hide/show all pending, failed, or passed tests.
Installation
Add this line to your application's Gemfile:
gem 'htmlcuke'
And then execute:
$ bundle
Or install it yourself as:
$ gem install htmlcuke
Usage
This usage case assumes you have the directories reports and reports/screens located in the same directory within which your test will run.
Add this line to your cucumber.yml, Rakefile, or command line arguments:
--format Htmlcuke::Formatter --out reports/cucumber_$(date '+%Y.%m.%d-%H.%M.%S').html
The --out assumes you will output the .html files to the reports directory under the naming convention cucumber + timestamp, feel free to change this as you see fit.
A sample after hook in hooks.rb would be:
After do |scenario|
Dir::mkdir('reports') unless File.directory?('reports')
Dir::mkdir('reports/screens') unless File.directory?('reports/screens')
if scenario.failed?
if scenario.respond_to?('scenario_outline')
screenshot_format = "./reports/screens/FAILED_#{(scenario.scenario_outline.title + ' ' + scenario.name).gsub(' ','_').gsub(/[^0-9A-Za-z_]/, '')}.png"
else
screenshot_format = "./reports/screens/FAILED_#{scenario.name.gsub(' ','_').gsub(/[^0-9A-Za-z_]/, '')}.png"
end
(File.(screenshot_format), 'image/png', 'Failed Screenshot')
end
end
Contributing
- Fork it ( https://github.com/[my-github-username]/htmlcuke/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request