Skip to main content

Cucumber

By admin - 31st July 2017

Introduction

Cucumber is a testing framework that helps to bridge the gap between QA and business managers. Tests are written in plain language terms using Gherkin so anyone in the team can understand even if they are not a technical person, with the help of feature files which we create to run the tests, also we can run multiple scenarios in one feature file. Cucumber interprets the tests into the specified programming language and using Selenium to drive the test cases in a browser. 

Installation / Dependencies

 

Cucumber

 

Cucumber Eclipse Feature need to be installed, to create Feature Stories:

Follow instructions:

  • Eclipses is already open
  • Click on ‘Help’ Button/Tab
  • Click on ‘Install new Software…’ Button
  • Click on ‘Add’ Button
    - Under ‘Name’ type in ‘Cucumber’
    - Under ‘Location’ type in ‘http://cucumber.github.com/cucumber-eclipse/update-site’
  • Click on ‘Ok’ Button
  • Select Cucumber in Field, keep clicking ‘Next’ until Completed, followed by ‘Finish’ Button

 

Cucumber_2

 

Pro's And Con's

Pros_Cons

 

Setup With Examples

- Cucumber Structure

Cucumber_Structure

 

- Cucumber Framework 

         o Feature File

               ♣ Creating a Feature File

                       ♣ Right Click on your Feature Folder

 

Cucumber_Framework

 

   ♣ Under ‘File Name’ type in your Feature Name with .feature at the end

   ♣ Click on ‘Finish’ Button (A Feature File would be generated)

 

Cucumber_3

 

Notes:

  • @Tag – used within TestRunner.Class to execute that Particular Scenario or a Group of Scenarios.
  • Scenario: - used to create a single Scenario.
  •  Scenario Outline: with Examples: - used for a single Scenario that’s executed multiple times.
  • Highlighted Yellow – that means no Method/Code has been created and aligned to it.

       - TestRunner.Class

                   ♣ Used to Execute Chosen Scenarios / Test Scripts

Cucumber_4

 

Notes:

  • Feature – location of created Feature Files 
  • Tags – executes Scenario related to Tag(s) listed

             o Single Scenario – “@tag1”

             o Multiple Scenario – “@tag1, @tag2”

             o Execute all, but exclude this Scenario -  “~@tag3”

  • Glue – location for created stepdefinitions 
  • dryRun – true = compiles code to check for Errors, false = Execute functional Scripts
  • format – Cucumber generated Reports

          o StepDefinition.Class

 ♣ Using the TestRunner.Class, execute it via the DryRun as True, this would generate the following:

♣ Copy these Scenario Methods from the Console and add them into your StepDefinition.Class 

 

  • Please Note that these Scenario Methods must be UNIQUE, otherwise Cucumber wouldn’t know which to Execute 

 

♣ Add Code into each Method, to create a full Test

Cucumber_5

 

♣ For the drivers to be linked together with the Hook.Class & StepDefinition.Class, you need to add the following into the StepDefinition.Class (As the Webdriver gets initialised in the Hook.Class firstly, it needs to carry over to the StepDefinition.Class).

Cucumber_6

 

  • Hook.class 
    ♣ @Before - executes the Website with chosen Browser
    ♣ @After - executes screenshots for Pass / Fail into Report

 

Cucumber_7

 

 

The CucumberReportStep.Class is below: 

Cucumber_8

 

  • Cucumber Reporting 

         - Custom Extent Reporting

         ♣ I’ve added this within the TestRunner.Class along with the Config

Cucumber_9

 

    ♣ Config.xml (can be found on Extent Report Website)

 

Cucumber_10

 

Reference Sites

https://cucumber.io/

http://extentreports.relevantcodes.com/java/#configuration

https://sukesh15.gitbooks.io/cucumber-jvm-test-framework-/content/write_your_first_test/decoding_the_feature_file.html

http://toolsqa.wpengine.com/cucumber/gherkin-keywords/

http://toolsqa.com/cucumber/cucumber-tutorial/

https://github.com/email2vimalraj/CucumberExtentReporter


 

About the author: admin
Aingaran Pillai is the Founder and CEO of Zaizi. Having worked on an Alfresco project in Government back in 2006, he liked the technology so much he started Zaizi to work on many more Alfresco implementations. Since then he has built Zaizi to be a leader in providing end-to-end digital solutions, specialising in business automation, open source technologies and cloud platforms.