Multiline comments in Robot framework

51,566

Solution 1

There is no block comment feature. However, there's a subtle little trick you can use to comment out whole blocks. It's not documented to be a multiline comment feature but it can be used like that.

This trick works by knowing that robot will ignore any data in tables that are not one of the four recognized tables: keywords, tests, settings or variables. If you have some other table, anything under it up until the next table will be ignored.

The relevant section of the user guide says this:

2.1.4 Rules for parsing the data

Ignored data

When Robot Framework parses the test data, it ignores:

  • All tables that do not start with a recognized table name in the first cell.
  • ...

For example:

*** Test Cases *** 
| test 1 
| | log | this is test one

*** comment ***
| test 2
| | log | this is test two

*** Test Cases ***
| test 3
| | log | this is test three

If you run the above test you'll see that only test 1 and test3 are executed. Everything in the "comment" table are ignored.

Solution 2

No, you have to use # in front of every line you want to comment.

Nevertheless note that:

  • if you are working with plain text format files, the whole test before your first section (settings, variable or test cases) is free text and you don't have to comment it.
  • some IDE propose shortcuts to comment multiple lines in one shot, for instance Ctrl+/ (or Command+/ if you're on Mac) for PyCharm.

Solution 3

One other trick for those who want to comment in and out a lot of lines is to use ctrl + /. That will comment out either the line that your cursor is on, or whatever lines you have highlighted. You can then highlight the lines and use ctrl + / again to un-comment them.

Solution 4

To comment and uncomment use Ctrl+? after selecting multiple lines.

Share:
51,566
Siya
Author by

Siya

Updated on May 27, 2021

Comments

  • Siya
    Siya almost 3 years

    Is there is any way to comment multiple lines in Robot framework.

    In python we have option like ''' and ''''.

  • Siya
    Siya over 9 years
    Thank you so much Bryan. Comment keyword is working :)
  • SHAHS
    SHAHS over 6 years
    helped me to understand what it means by the separate comments section in an existing file. Thanks.