Please note, this is a STATIC archive of website www.javatpoint.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
Javatpoint Logo
Javatpoint Logo

What is a feature in cucumber testing?

A feature is a functionality or standalone unit of a software application. In other words, the feature is a parameter which is used to test the requirements of the customer from the software product.

Let's understand it through a very common example of a social networking site.

Few basic features of the social networking site can be determined as -

  • Create and delete the user from the social networking site.
  • User login functionality to access the social networking site.
  • Sharing videos or photos on the social networking site.
  • Sending a friend request.
  • Logout or sign out.

At the time of testing, it is the best practice that we should determine the features first, before deriving the test scripts to be tested.

Hence from the above discussion, it is clear that, when we talk about cucumber, each independent functionality of the product or web application can be called as a feature. A feature typically has a list of scenarios to be tested for that feature, and the feature and its description are stored in the feature file.

There can be numerous features of a software product. Hence for the better management of features, we should create a separate feature file for each feature.

Sr.No Feature Feature Filename
1 Login Feature Login.feature
2 Share Post Feature sharePost.feature
3 Create an Account Feature AccountCreation.feature
4 Delete an Account Feature AccountDelete.feature

The keyword "Feature" represents a feature under the test in Gherkin language.

Note: It is recommended that write a small description of features beneath the keyword feature in the feature file.

Example:

Suppose, the feature login functionality of a social networking site is under the test. Hence, we need to test it as per the following aspects:

  • If both credentials, i.e., username and the password are correct, then the user should log in into the social networking site.
  • If the username is incorrect, but the password is correct, then the user should be shown an error message.
  • If the user name is correct, but the password is incorrect, then the user should be shown an error message.
  • After the successful login, the user should be navigated to My Account or Profile page.
feature in cucumber testing

Now, we are going to create a feature file for the login feature of the social networking site:

Feature: Login functionality
Scenario: Successful Login with Valid entries
Given user navigates to the website facebook.com	
And user logs in through Login link by using username as "[email protected]" and password as "prity123sharma"

Then login must be successful.
Scenario:  Unsuccessful Login with Invalid entries
Given user navigates to the website facebook.com
When username is incorrect, but the password is correct
user logs in through Login link by using Username as "[email protected]" and Password as "prity123sharma"
When username is correct, but the password is incorrect
user logs in through Login link by using username as "[email protected]" and Password as "12345678"
Then login must be unsuccessful.

According to the above example, we can create feature files as per the particular feature. A feature file is always based on the behavior of an application under specific circumstances.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA