Difference between revisions of "Running cucumber projects"

From Test Automation Wiki
Jump to: navigation, search
Line 10: Line 10:
 
</ul>
 
</ul>
 
<ul>
 
<ul>
     <li>Open Command Prompt and go to the project folder</li>
+
     <li>Open CMD and go to the project folder</li>
 
     <source>cd C:\Ruby\projects\cucumber-tutorial\</source>
 
     <source>cd C:\Ruby\projects\cucumber-tutorial\</source>
     <li>With the TAB key, the console will try to finish what you're writing. Try the following</li>
+
     <li>With the TAB key, the console will try to finish what you're writing.</li>
 +
    <li>Try the following to get to your project:</li>
 
<source>
 
<source>
 
cd /
 
cd /
cd C:\Ru :tab: \pr :tab: \cu :tab: :enter:
+
cd C:\Ru :tab: \pr :tab: \'''<first 2 letters from the name of your project>''' :tab: :enter:
 
</source>
 
</source>
 
</ul>
 
</ul>
  
<p>Also make sure you have Firefox installed on your computer.</p>
 
  
 
<h2>Running the calculator</h2>
 
<h2>Running the calculator</h2>
<p>Go to the command prompt you have opened and write the following in the project folder:</p>
+
<p>In CMD you have opened, write the following <code>bundle exec cucumber -t @addition</code> and press "Enter"</p>
<code class="block">cucumber -t @addition</code>
 
<p>And press enter</p>
 
<blockquote><b>Note:</b> It is possible that you will see an error like <code>cannot load such file --
 
    watir-webdriver-performance (LoadError)</code>. 90% of the time this means you're missing a gem. In this case it can
 
    be solved by writing <code>gem install watir-webdriver-performance</code>
 
  
    [[File:missing-gem-error.png]]
 
</blocknote>
 
 
<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>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 43: Line 36:
 
<p>After all scenarios related to @addition have run, it will show a summary of how many steps and scenario's
 
<p>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.</p>
 
     succeeded, failed and were undefined.</p>
<p>In this case it will show all steps as ‘undefined'. If you think about it, it's quite logical. Cucumber doesn't
+
<p>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
 
     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.</p>
 
     will be discussed in the next chapter.</p>
 +
  
 
<h2>More tag filtering</h2>
 
<h2>More tag filtering</h2>
<p>Go to command prompt and try out a few more commands. Before entering these commands, look at the calculator.featue
+
<p>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.</p>
 
     file and try to guess what scenarios will run.</p>
 
<source>
 
<source>
Line 57: Line 51:
 
     cucumber -t @calculator -t @both
 
     cucumber -t @calculator -t @both
 
</source>
 
</source>
<p><b>Pro tip</b>: When in command prompt, 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>
 
<p>You might have noticed, that when running a Scenario Outline, it will show the steps for every time it's running a
 
<p>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.</p>
 
     new row. In the end, it will also show 4 undefined steps for every outline that it went through.</p>
 
<p>If you're wondering what will happen with different tags, feel free to play around a bit.</p>
 
<p>If you're wondering what will happen with different tags, feel free to play around a bit.</p>
 +
  
 
<h2>Other commands</h2>
 
<h2>Other commands</h2>

Revision as of 15:10, 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.

    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 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:

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