Data driven Testing in Cucumber

Using Scenario Outline

Cucumber inherently supports data driven testing using Scenario Outline. Consider the following feature file using Scenario to define the test steps-

   Feature: Check addition in Google calculator
   In order to verify that google calculator work correctly
   As a user of google
   I should be able to get correct addition result

   Scenario: Addition
   Given I open google
   When I enter "2+2" in search textbox
   Then I should get result as "4"


In order to make it data driven we just have to use Scenario Outline along with Examples. Write the following code in feature file-

   Feature: Check addition in Google calculator
   In order to verify that google calculator work correctly
   As a user of google
   I should be able to get correct addition result

   Scenario Outline: Addition
   Given I open google
   When I enter "<calculation>" in search textbox
   Then I should get result as "<result>"
   
   Examples:
	| calculation |result|
	| 3+3	     | 6	|
	| 2+5	     | 70	|

Now the test would run twice with two different set of values. Check the parameterization done in scenario- "When I enter "<calculation>" in search textbox", instead of hard coding the test data, variables are defined in Examples section and used in Scenario Outline section. Also, note that the step definition file will remain same and will require no change for scenario outline.


Pre -> Cucumber Basics Next -> Cucumber With Selenium