Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetching tags from a feature file using cucumber

Tags:

tags

cucumber

Is there a command line option to list all the tags in your cucumber test suite?

For example, I would want something like: cucumber --show-tags foo.feature

That would give me something like:

@ci @development @regression @wip

The syntax which i have tried was "cucumber -f tag_cloud foo.feature" and its giving me "cannot load tag_cloud(load_error)"

I just wanted to know how to do it exactly.

Do i need to install any api's additionally?? or how it is?

Kindly help me

like image 998
user2190273 Avatar asked Aug 26 '13 11:08

user2190273


People also ask

How do you use tags in Cucumber feature file?

Tag starts with “@”. After “@” you can have any relevant text to define your tag like @SmokeTests just above the scenarios you like to mark. Then to target these tagged scenarios just specify the tags names in the CucumberOptions as tags = {"@SmokeTests"}.

How do you use multiple tags in a feature file?

Yes, having multiple tags in a feature file is a common use case. You use tags to categorize the tests. Instead of running multiple tags/categories at a time, you can structure your feature file to run all the tests you want by placing the tag the correct place.


1 Answers

I believe the --show-tags option was deprecated. Instead, you have to use a custom formatter.

Nat Ritmeyer had a good custom formatter for this task - https://gist.github.com/natritmeyer/2995205.

1) Copy the following into a "list_tags.rb" file in your "features/support" directory:

=begin

Copyright (c) 2012, Nathaniel Ritmeyer
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. Neither the name Nathaniel Ritmeyer nor the names of contributors to
this software may be used to endorse or promote products derived from this
software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

=end


require 'cucumber/formatter/console'
require 'cucumber/formatter/io'

module Cucumber
  module Formatter
    class ListTags
      include Io
      include Console

      def initialize(step_mother, path_or_io, options)
        @io = ensure_io(path_or_io, "list_tags")
        @all_tags = []
      end

      def tag_name(tag_name)
        @all_tags << tag_name
      end

      def after_features(features)
        @all_tags.uniq.sort.each {|tag| @io.puts tag}
      end
    end
  end
end

2) Then run cucumber using:

cucumber -d -f Cucumber::Formatter::ListTags

This does a (dry) run of your features and formats the results using the custom formatter. The results are a list of tags. For example:

@feature1
@feature2
@scenario1
@smoke1
@smoke2
like image 84
Justin Ko Avatar answered Oct 07 '22 22:10

Justin Ko