by Mark Beaman July 31st, 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 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

                    o Under ‘Name’ type in ‘Cucumber’

                    o 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

Pro's and Con's

Setup with Examples

- Cucumber Structure
- Cucumber Framework 
         o Feature File
               ♣ Creating a Feature File
                       ♣ Right Click on your Feature Folder
                          ♣ Under ‘File Name’ type in your Feature Name with .feature at the end
                          ♣ Click on ‘Finish’ Button (A Feature File would be generated)
 

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.

                                o TestRunner.Class

                                           ♣ Used to Execute Chosen Scenarios / Test Scripts

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
♣ 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).
 
                       o Hook.class 
                              ♣ @Before - executes the Website with chosen Browser
                              ♣ @After - executes screenshots for Pass / Fail into Report
The CucumberReportStep.Class is below: 
                    - Cucumber Reporting 
                             o Custom Extent Reporting
                                   ♣ I’ve added this within the TestRunner.Class along with the Config
              ♣ Config.xml (can be found on Extent Report Website)
Mark Beaman's picture
about the author: Mark Beaman
Mark is a Automation Engineer having over 3+ years experience in both Manual and Automation Testing. He possesses strong skills in Test Automation with selenium and Data Migration Testing with Apache Jmeter. He likes to experiment with different Technologies such as Cucumber, ApachePOI and Docker