Cucumber - Comments


Advertisements

Comment is basically a piece of code meant for documentation purpose and not for execution. Be it a step definition file or a feature file, to make it more readable and understandable. So, it is important to use/put comments at appropriate places in the file. This also helps while debugging the code. Cucumber feature files can have comments at any place. To put comments, we just need to start the statement with “#” sign.

Different programming languages have got different norms for defining the comments. Let’s see how Cucumber deals with it.

  • Step definition file − If you are using Java as a platform then mark your comments with “//”.

  • Feature File − In case of feature file, we just need to put # before beginning your comment.

Example

The highlighted text in the program refer to the comments in the code.

Feature: annotation 

#This is how background can be used to eliminate duplicate steps 
Background: 
User navigates to Facebook 
Given I am on Facebook login page 

#Scenario with AND 
Scenario: 
When I enter username as "TOM" 
And I enter password as "JERRY" 
Then Login should fail 

#Scenario with BUT 
Scenario: 
When I enter username as "TOM" 
And I enter password as "JERRY" 
Then Login should fail 
But Relogin option should be available
Advertisements