Running cucumber projects

From Test Automation Wiki
Revision as of 09:53, 27 June 2016 by Gijsp (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 Command Prompt and go to the project folder
  • cd C:\Ruby\projects\cucumber-tutorial\
  • With the TAB key, the console will try to finish what you're writing. Try the following
  • cd /
    cd C:\Ru :tab: \pr :tab: \cu :tab: :enter:
    

Also make sure you have Firefox installed on your computer.

Running the calculator

Go to the command prompt you have opened and write the following in the project folder:

cucumber -t @addition

And press enter

Note: It is possible that you will see an error like cannot load such file --

watir-webdriver-performance (LoadError). 90% of the time this means you're missing a gem. In this case it can be solved by writing gem install watir-webdriver-performance

Error creating thumbnail: Unable to save thumbnail to destination

</blocknote>

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 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 command prompt and try out a few more commands. Before entering these commands, look at the calculator.featue file and try to guess what scenarios will run.

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

Pro tip: When in command prompt, 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:

  • 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
  • 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.