Console Colours

Marit van Dijk edited this page Sep 9, 2017 · 26 revisions

The console output for Cucumber colours steps according to how execution went. In addition to that, matched step variables are highlighted. Here is an example of how a single step gets printed:

Given I have 487 cucumbers in my belly # features/vegetable_features.feature:49

You can tweak the colours by defining a $CUCUMBER_COLORS variable in your shell, very much like you can tweak the colours of the familiar POSIX command ls with
$LSCOLORS or $LS_COLORS.

Don’t attempt to set it in your support/env.rb file or any other Ruby file. It must be defined before Cucumber starts. You can do it in your Rakefile with ENV['CUCUMBER_COLORS'] = '...'

The colours that you can change are:

Key Default colours
undefined yellow (v0.2.0 and up)
pending yellow
pending_param yellow,bold
failed red
failed_param red,bold
passed green
passed_param green,bold
skipped cyan
skipped_param cyan,bold
comment grey
tag cyan (v0.2.0 and up)

For instance, if your shell has a black background and a green font (like the
“Homebrew” settings for OS X’ Terminal.app), you may want to override passed
steps to be white instead of green. Examples:

export CUCUMBER_COLORS=passed=white
export CUCUMBER_COLORS=passed=white,bold:passed_param=white,bold,underline

Aslak likes to highlight all parameters in magenta, so he uses this:

export CUCUMBER_COLORS=pending_param=magenta:failed_param=magenta:passed_param=magenta:skipped_param=magenta

(If you’re on Windows, use SET instead of export).

To see what colours and effects are available, just run this in your shell:

ruby -e "require 'rubygems'; require 'term/ansicolor'; puts Term::ANSIColor.attributes"

Although not listed in the output, you can also use grey.

Windows

Windows users can get colours by installing ANSICON or cmder