Javatpoint Logo
Javatpoint Logo

Feature File in Cucumber Testing

The feature file is the essential segment of cucumber tool, which is used to write acceptance steps for automation testing. Acceptance steps generally follow the application specification.

A feature file is usually a common file which stores feature, scenarios, and feature description to be tested.

The feature file is an entry point, to write the cucumber tests and used as a live document at the time of testing.

Feature File in Cucumber Testing

The extension of the feature file is ".feature". Each functionality of the software must have a separate feature file.

Example:

In order to ensure the working of Login Functionality, we are implementing the cucumber test by creating a feature file. It will verify whether the Login Functionality is working properly or not.

Feature: Login 
Scenario: Login Functionality
Given user navigates to the website javatpoint.com
And there user logs in through Login Window by using Username as "USER" and Password as "PASSWORD"
Then login must be successful.

After performing the automation testing, a table is created as a result of automation testing. This table is used in tags.

The resulting table looks like the following table:

Feature File in Cucumber Testing

Feature file with Multiple Scenario

Feature file can contain multiple scenarios or scenario outlines. We can write all possible Scenarios of a particular feature in a feature file.

Feature File in Cucumber Testing

By using the keyword "Scenario" or "Scenario Outline", One Scenario can be separated from another.

However, a single feature file can contain any number of scenarios but focuses only on one feature such as registration, login etc at a time. Therefore, it is better to keep the scenarios related to a particular feature in a single feature file.

Scenarios can be executed parallel, or you can execute them together in a group. Let's take an example for more clarity:

Example:

Feature File 1:

Feature: Registration 
Background: 
Given user on the homepage  
And user follows "Sign in"  
@regression  
Scenario: Create a New User 
When user fills "registration email textbox" with "chitrali.sharma27@gmail.com"  
And user clicks "create an account button"  
And user enters the following details 
| First Name | Chitrali| 
| Last Name | Sharma| 
| Password | Inquiry@1234 | 
| Date | 17| | Month | 02| | Year | 1992 |  
And user clicks "register button"
Scenario: User does not follow form validations
When user enters wrong characters
Then error message displayed with invalid password
And user returns back on registration page

Feature File 2:

Feature: Login
Background: 
Given user on the login page  
And user follows "Log in"  

@regression @smoke
Scenario: Verification of Login Function  
Given user on the Login Page
And user enters "email address" with "chitrali.sharma27@gmail.com" 
And user enters "password" with "Inquiry@1234"  
And user click "log in" button
Then user should see "My Account" 
Scenario: Unsuccessful login
Given user on the Login Page
And user enters "email address" with "chitrali.sharma27@gmail.com" 
And user enters "password" with "qsder@1234"  
And user clicks "login" button
Then error message displayed with wrong password
And user returns back on login page

Comments in Feature File

If we do not need to execute a particular scenario at a time, then we can comment that scenario.

In Eclipse, to comment a multi-line or use block comment first select all the line to be commented and then press Ctrl + /. Similarly, to remove comments, we need to press Ctrl + \. Other IDEs may contain other shortcuts to do this.

While commenting any scenario, do not forget to comment the complete scenario. Otherwise, remaining lines of scenario which are not commented will be considered as a part of the previous scenario.






Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA