Play around with Cucumber Tags


Running a specific scenario from a Feature

cucumber --tags @login_success

You can negate tags with a tilde “~”, e.g.

cucumber --tags ~@wip

(means don’t run features/scenarios tagged with @wip)

Run a feature/scenario with name 

cucumber –name userjourney(Run scenarios which have “user journey” somewhere in the name (and it’s case-sensitive, so it won’t find a scenario named “UserJourney”)


cucumber –format progress

will give you a short form which denotes the result of each scenario in one character, “F” for a failure, “.” for a pass, “-” for skipped steps, “U” for undefined.
You can use multiple formatters and send them to different files, if you have different output destinations you want to send to, e.g.
cucumber -f pretty -f html –out cukes.html -f rerun –out rerun.txt

Tagged Hooks

At times you need to execute the hook for certain scenarios.This can be achieved by associating a BeforeAfterAround or AfterStep hook with one or more tags.

For OR tags, pass the tags in a single string comma separated:

Before('@cucumis, @sativus') do
  # This will only run before scenarios tagged
  # with @cucumis OR @sativus.

For AND tags, pass the tags as separate tag strings:

Before('@cucumis', '~@sativus') do
  # This will only run before scenarios tagged
  # with @cucumis AND NOT @sativus.

You create complex tag conditions using both OR and AND on tags:

Before('@cucumis, @sativus', '@aqua') do
  # This will only run before scenarios tagged
  # with (@cucumis OR @sativus) AND @aqua 

After Step example:

AfterStep('@cucumis', '@sativus') do
  # This will only run after steps within scenarios tagged
  # with @cucumis AND @sativus.

This is useful at the calabash-android hooks were we can control the installation, uninstallation and reset of the application data.

Before('@reset,@reinstall') do |scenario|
@scenario_is_outline = (scenario.class == Cucumber::Ast::OutlineTable::ExampleRow)
if @scenario_is_outline
scenario = scenario.scenario_outline

if scenario.source_tag_names.include? "@reinstall"


if scenario.source_tag_names.include? "@reset"



How to get Cucumber Jenkins Report locally


To get some nice reports for the test run, locally you can use cucumber-sandiwich.jar

Download the jar

Open terminal and navigate to the project folder and start the cucumber-sandwich.jar

java -jar cucumber-sandwich.jar -f out/to/the/folder/where/json/is/present -o /out/of/the/report/folder/

Your cucumber runner should be

cucumber –format json –out cucumber.json


Feature Specific

Tag Overview

Cucumber Test runner formatter on console


When ever the cucumber runner command is specified with html formatter as an output for reports, we don’t get to see the steps/scenarios or current execution state of the tests.

SlowHandCuke is a simple cucumber formatter whose sole purpose is to give you feedback on the currently running step in the console.

All you need to get this working is install slowhandcuke with the below command

sudo gem install slowhandcuke

Once the gem is installed, all you need to do is add the formatter as follows in the command

calabash-android run apk_path — color –format html –out reports.html –format ‘Slowhandcuke::Formatter’

Look at the video

From the video you can see after the step execution is completed, it turns to green which gives us a clear view on the current step execution state.


Building Calabash-Android to Handle Network Scenarios


This version of calabash-android holds wifimanager API implemented which helps to turn off and turn on the wi-fi connectivty on the device at the time of test execution.

1. Download the calabash-android from the below link

2.Make the changes you want to make. You can update the versions file if you want to. (ruby-gem/lib/calabash-android/version.rb)


You need the Android SDK installed as well as bundler and rake. To build and install the gem go to the ruby-gem folder run rake build

cd ruby-gem
rake build

Note that only files that are added to git are included in the gem. That means you have to add any new file to git yourself before building the gem.

3.Now re-launch the terminal and navigate to pkg folder and you will find the gem with the version you complied. Install the gem and check for the calabash-android version.The version should be the one which you had changes in step2.

4. Now launch the test app in console and try the below query command


performAction(‘status_wifi’, ‘disable’)

performAction(‘status_wifi’, ‘enable’)


How to set ANDROID_HOME on mac OS


Follow the steps :

1.Create the .bash_profile file with the command “touch .bash_profile”

2. After you created the file you need to open it using the following command “open -e .bash_profile” (you can also use vi or emacs)

Add the the following text and save the file

export ANDROID_HOME=/Users/saikrishna/Softwares/android-sdks
export PATH=/Users/saikrishna/Softwares/android-sdks/platform-tools:/Users/saikrishna/Softwares/android-sdks/tools:$PATH

replace the path with respective to your system android sdk path

3. Quit the terminal and re-launch and type adb –help



Couple of times at the time of execution we get the below error

android.util.AndroidException: INSTRUMENTATION_FAILED: com.example.test/sh.calaba.instrumentationbackend.CalabashInstrumentationTestRunner
RuntimeError: App did not start

Follow the below steps to over come the issue:

1. Uninstall the testapk which is installed in the device along with the test-server.

2. Create a new folder and place the testapk in the same folder.

3. Navigate to the folder and do calabash-android gen

3. Now execute calabash-android run testapk.

4. Once the application is installed and the sample test is completed.

Now run your test. Hurray!!!! You must no more see the exception


Setup Calabash Android



1.Ruby 1.9.X needs to be installed. Download from here.

2.Extract DevKit into the same folder where ruby is installed . Download from here.

Open Command-line and install the following gems.

gem install calabash-android

gem install calabash-cucumber

gem install bundler — Once the bundler is installed just type bundle install .

Calabash Framework Setup

Calabash Android lets you run cucumber features on Android device or Emulator.Calabash basically supports Ruby .

Generate a Cucumber skeleton

To get started with calabash it might be a good idea to run calabash-android gen. It will create a Cucumber skeleton in the current folder like this:

| |_app_installation_hooks.rb
| |_app_life_cycle_hooks.rb
| |_env.rb
| |_calabash_steps.rb

In this skeleton you find all the predefined steps that comes with calabash. Try to take a look my_first.feature and change it to fit your app.

Writing a test

The Cucumber features goes in the features library and should have the “.feature” extension.

You can start out by looking at features/my_first.feature. You can extend this feature or make your own using some of the predefined steps that comes with Calabash.

Running the test

calabash-android run <path to the apk file>


calabash-android run path-to-apk –format html –out reports.html