Skip to main content

Behat 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.

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 PhpStorm. 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

@tag1
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.

In PHP we have Single Line and Multi Line Comments, you can use these types of comments in your step definition file because your step definition file is written in PHP, click here to know how to write comments in PHP.

Note: the comment block starts with /**, and not the usual /*. This is important for Behat to be able to parse such comments as annotations!

Tags
Submitted by tgoswami on October 6, 2020

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.