September 08, 2015

Triggering Cucumber tag from a Cucumber step

I am working on a legacy web application that has limited unit test and dependency on multiple applications.  To reduce the manual testing effort, we had to write end-to-end UI tests with help of Cucumber, Capybara.

We had to chain few tests (generally BAD PRACTICE) as there was no way to create the seed data in every end-to-end test. We had to reuse the data from other scenarios. Rather than going into further details, here is an example where you can trigger another cucumber tag from a step:


Feature: As a Cucumber user
  I want to run other feature from a step

  Scenario: run job
    Given no exception is raised

  Scenario: run job
    Given exception is raised

  Scenario: Child
    Given I trigger @success_child_process job
    And no exception is raised
    And I trigger @failure_child_process job


Given /^no exception is raised$/ do
  # do nothing here

Given /^exception is raised$/ do
  raise 'Exception is raised'

Given /^I trigger (@.*) job$/ do |tag|
  CucumberChildProcess.run_tag tag


require 'childprocess'

module CucumberChildProcess

  def self.run_tag(tag) "Triggering the child process for tag '#{tag}'"
    process ='bundle'), 'exec', 'cucumber', '-t', tag)!
    process.start "********* CHILD PROCESS LOGS for tag '#{tag}' - START **********"
    process.wait "********* CHILD PROCESS LOGS for tag '#{tag}' - END **********"
    raise "Child process failed while running the tag '#{tag}'. Check the log for more information. Exit code: #{process.exit_code}" unless process.exit_code == 0 "Successfully executed the tag '#{tag}' as Child process"

  def self.find_executable(cmd)
    ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
      next if path.empty?
      path = File.join(path, cmd)
      ['.exe', '.bat'].each do |ext|
        return path + ext if File.exists?(path + ext)
    raise "Unable to find command '#{cmd}' in the PATH"


  1. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
    software testing training in chennai

  2. This site is very good to me. Because this site has much more sense post. So I am posting at the site. I would like to know more of the unknown.
    Top posts and takes a lot of good to me and to all of the beautiful and the good.
    laptop chiplevel training in hyderabad

  3. Wow!! What a great blog!! I really liked your article and appreciate your work.
    I have found this article while searching on internet and I would recommend this to everyone.
    laptop chip level training in hyderabad

  4. This article is well written and quite informative.
    More articles should be written and you have just found a follower.and more visit.
    mainframe training in hyderabad

  5. Wow cool site I have already withdrawn money from here. Actually my girlfriend advised me and I decided to risk the risk and you elegant uk casino I wish you more victories

  6. Very good post.
    All the ways that you suggested for find a new post was very good.
    Keep doing posting and thanks for sharing
    matlab training in hyderabad