Udemy REST Assured free

Cucumber with Java: Comments in Feature File and Step Definition File

Comment is basically a piece of code meant for documentation purpose and not for execution. To make Feature File and Step Definition File more readable and understandable. It is important to use comments at appropriate places in the file. This also helps while debugging the code.

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

Cucumber feature files can have comments at any place. To put comments, we just need to start the statement with “#” sign.Feature file only support comments with # sign. You need to put # at beginning of your comment. You want to do single line or multiple comment you need to put # before all lines. Parser will ignore every line which start with #.

To comment multi line or use block comment select all the line and press Ctrl + / in Eclipse. Other IDE may have other shortcuts for doing this. Similarly to remove comment press Ctrl + / again.

Below is the example:

#This is sample scenario
#It use several gherkin keyword and tag

Scenario: Title of your scenario
  Given I want to write a step with precondition
  And some other precondition
  When I complete action
  And some other action
  And yet another action
  Then I validate the outcomes
  And check more outcomes

In above code first 2 lines are comments.

Video Tutorial: Cucumber Comments in Feature File and Step Definition File