Data Driven Testing in Cucumber

What is Cucumber data driven testing?

In very simple terms, cucumber data driven testing means that you can pass data from cucumber feature files to your test cases. For example, let us consider that you are automating the login flow of some application. In this case, you can pass user name and password as test data from your feature file to selenium code.

Data-Driven Testing in Cucumber

1. Parameterization without Example Keyword:
Parameterization without Example Keyword
Using Regular Expression: 
("^user enters \"(.*)\" and \"(.*)\"$")
("^user enters \"([^\"]*)\" and \"([^\"]*)\"$")

2. Data-Driven Testing in Cucumber using Scenario Outline
Parameterization with Example Keyword

Parameterization with Examples Keyword
       Using Regular Expression: 
(“user enters (.*) and (.*)$")

Scenario Outline – This is used to run the same scenario for 2 or more different sets of test data. E.g. In our scenario, if you want to register another user you can data drive the same scenario twice.

Examples – All scenario outlines have to be followed with the Examples section. This contains the data that has to be passed on to the scenario.

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      | 9 |
Please refer below Youtube video for detail explanation:


What is Data table in Cucumber?

Data Tables are handy for passing a list of values to a step definition. Cucumber provides a rich API for manipulating tables from within step definitions.
Data Tables are also used to handle large amount of data. Tables in Cucumber feature files are represented by using the pipeline “|” sign.
Please refer below Youtube video for detail explanation:



No comments:

Post a Comment