Comment in Cucumber Feature File

Profile picture for user devraj

A comment is fundamentally a piece of code meant for documentation purposes and not for execution. To make Feature File and Step Definition File more readable and understandable. It is essential to use comments at appropriate places in the file. The Comment also helps while debugging the code.

Table of Content

  1. Comment in Step Definition File
  2. Comment in Feature File
  3. Multiple Lines Comment
  4. Video Tutorial

Comment in Step Definition File

Step Definitions files follow the comment style of language it is written in.

In Java, we have Single Line, Multi-Line, and Documentation Comment. You can use these types of comments in your step definition file because your step definition file is written in Java, but in the Feature file, we can not use all these types of comments.

How to comment in the feature file

Cucumber feature files can have comments at any place. We need to start the statement with the "#" sign to put Comments. Feature file only supports comments with a # sign. We put # at the beginning of our Comment. You want to do a single line or multiple line comments; you need to put # before all lines. The parser will ignore every line which starts with #.

How to comment multiple lines in the feature file

To comment multi-line or use block comment, select all the lines and press shortcut

  • Windows Eclipse: Ctrl + / 
  • Windows IntelliJ: Ctrl + /
  • Mac Eclipse: Command + /
  • Mac IntelliJ: Command + /

Similarly to remove comment press Ctrl + / again. Same shortcuts can also be used for single line comment.