Difference between revisions of "Running cucumber projects"

From Test Automation Wiki
Jump to: navigation, search
Line 16: Line 16:
 
<source>
 
<source>
 
cd /
 
cd /
cd C:\Ru :tab: \pr :tab: \'''<first 2 letters from the name of your project>''' :tab: :enter:
+
cd C:\Ru :tab: \pr :tab: \<first 2 letters from the name of your project> :tab: :enter:
 
</source>
 
</source>
 
</ul>
 
</ul>
Line 26: Line 26:
 
<p>It will show an empty line for a moment, quickly open and close a browser and you will see the following output:</p>
 
<p>It will show an empty line for a moment, quickly open and close a browser and you will see the following output:</p>
 
[[File:cmd-cucumber-output.png]]
 
[[File:cmd-cucumber-output.png]]
<p>So, what happened? By writing <code>bundle exec cucumber -t @addition</code> you said: "Hey Ruby, I want to use Cucumber to look
+
<p>So, what happened?  
 +
By writing <code>bundle exec cucumber -t @addition</code> 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
 
     at this folder I am in now. Also, I want only to run things that contain the tag @addition". At this point cucumber
 
     starts
 
     starts
Line 45: Line 46:
 
     file and try to guess what scenarios will run.</p>
 
     file and try to guess what scenarios will run.</p>
 
<source>
 
<source>
     cucumber -t @subtraction
+
     bundle exec cucumber -t @subtraction
     cucumber -t @calculator
+
     bundle exec cucumber -t @calculator
     cucumber -t @calculator -t ~@addition -t ~@add
+
     bundle exec cucumber -t @calculator -t ~@addition -t ~@add
     cucumber -t @calculator -t ~@addition -t ~@add
+
     bundle exec cucumber -t @calculator -t ~@addition -t ~@add
     cucumber -t @calculator -t @both
+
     bundle exec cucumber -t @calculator -t @both
 
</source>
 
</source>
 
<p><b>Pro tip</b>: When in CMD, use the arrow up key, so show your last entered command.</p>
 
<p><b>Pro tip</b>: When in CMD, use the arrow up key, so show your last entered command.</p>
Line 59: Line 60:
 
<h2>Other commands</h2>
 
<h2>Other commands</h2>
 
<p>Cucumber has many more commands to use when running scripts. You can see them all by writing the following:</p>
 
<p>Cucumber has many more commands to use when running scripts. You can see them all by writing the following:</p>
<code class="block">
+
<code>cucumber --help</code>
    cucumber --help
 
</code>
 
 
<p>That is double minus sign. This will give you a list of all the cucumber commands. Lets go trough the most commonly
 
<p>That is double minus sign. This will give you a list of all the cucumber commands. Lets go trough the most commonly
 
     used.</p>
 
     used.</p>
 
<p>Examples:</p>
 
<p>Examples:</p>
 
<ul>
 
<ul>
     <li><code>cucumber -t @calculator -f html >> output.html</code></li>
+
     <li><code>bundle exec cucumber -t @calculator -f html >> output.html</code></li>
 
     <ul>
 
     <ul>
 
         <li>Will create a file in your project folder named output.html' with the results of your test-run. &larr; try
 
         <li>Will create a file in your project folder named output.html' with the results of your test-run. &larr; try
Line 72: Line 71:
 
         </li>
 
         </li>
 
     </ul>
 
     </ul>
     <li><code>cucumber -t @calculator -f usage >> usage.txt</code></li>
+
     <li><code>bundle exec cucumber -t @calculator -f usage >> usage.txt</code></li>
 
     </li>
 
     </li>
 
     <ul>
 
     <ul>

Revision as of 15:13, 14 March 2017

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\cucumber-tutorial\
  • 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.featue 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.