Running cucumber projects

From Test Automation Wiki
Revision as of 14:17, 14 March 2017 by MartijnP (talk | contribs)
Jump to: navigation, search

First things first

  • In your project, open \features\calculator.feature. You should recognize the file from the previous part of this tutorial.
  • Open CMD and go to the project folder
  • cd C:\Ruby\projects\<your project name>\
  • With the TAB key, the console will try to finish what you're writing.
  • Try the following to get to your project:
  • cd /
    cd C:\Ru :tab: \pr :tab: \<first 2 letters from the name of your project> :tab: :enter:
    

Running the calculator

In CMD you have opened, write the following bundle exec cucumber -t @addition and press "Enter"

It will show an empty line for a moment, quickly open and close a browser and you will see the following output:

Error creating thumbnail: Unable to save thumbnail to destination

So, what happened?

By writing bundle exec cucumber -t @addition you said: "Hey Ruby, I want to use Cucumber to look at this folder I am in now. Also, I want only to run things that contain the tag @addition". At this point cucumber starts reading the project, looking for the feature files and filtering out the Features, Scenarios or Scenario Outlines and then run them.

In this case you will first see some settings of this run, we will talk about this later. After this it will show the Feature that contains @addition or that has a scenario with @addition. Then it will show the scenario it is about to run.

After all scenarios related to @addition have run, it will show a summary of how many steps and scenario's succeeded, failed and were undefined.

In this case it will show all steps as "undefined". If you think about it, it's quite logical. Cucumber doesn't speak English, so how can it know what we mean by these lines of text? How to make Cucumber understand these steps will be discussed in the next chapter.

More tag filtering

Go to CMD and try out a few more commands. Before entering these commands, look at the calculator.feature file and try to guess what scenarios will run.

    bundle exec cucumber -t @subtraction
    bundle exec cucumber -t @calculator
    bundle exec cucumber -t @calculator -t ~@addition -t ~@add
    bundle exec cucumber -t @calculator -t ~@addition -t ~@add
    bundle exec cucumber -t @calculator -t @both

Pro tip: When in CMD, use the arrow up key, so show your last entered command.

You might have noticed, that when running a Scenario Outline, it will show the steps for every time it's running a new row. In the end, it will also show 4 undefined steps for every outline that it went through.

If you're wondering what will happen with different tags, feel free to play around a bit.

Other commands

Cucumber has many more commands to use when running scripts. You can see them all by writing the following:

cucumber --help

That is double minus sign. This will give you a list of all the cucumber commands. Lets go trough the most commonly used.

Examples:

  • bundle exec cucumber -t @calculator -f html >> output.html
    • Will create a file in your project folder named output.html' with the results of your test-run. ← try this yourself
  • bundle exec cucumber -t @calculator -f usage >> usage.txt
    • Will show all the step definitions in your project, ordered by most time spent to least time spent.