18

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

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

10 Answers 10

34

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you so much Bryan. Comment keyword is working :)
helped me to understand what it means by the separate comments section in an existing file. Thanks.
"robot will ignore any data in tables that are not one of the four recognized tables" - that's false since v3.2. The parser has explicit Token.COMMENT_HEADER token for a comment section, which relates to *** comment ***. Any unrecognized table will result in an Token.ERROR being emitted.
17

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.

Comments

2

Ideally, if you want to comment a line of Robot code, please put your cursor on that line and press ctrl+/, it will comment the line from the beginning of the line. like:

#<<Your Code lines here>>

If you want to specify what particular robot line or keyword does in front of that line or keyword, just type # and type your comment.Like:

Click &{Locator}  #This keyword clicks on the locator specified.

Also, you have the option to write the documentation for the test case. For example: If your test case is all about validating login positive scenario, then you can write a documentation as:

Test case name
    [Tags]  Valid_credentials
    [Documentation]  This test case validates Login functionality with valid credentials.
    Your keywords or variable declaration will start here
    .....
    .....
    finish your test case

Hope this simple tip help.

3 Comments

The advice about <kbd>ctrk+/</kbd> is highly dependent not only on which editor you use, but how it is configured.
I am Using JetBrains Pycharm with Intellibot and Robotframework plugins. This IDE is good for Robot test cases development. Also, All the shortcuts which we use for eclipse can be used with some modifications in the shortcut keys.
Correct. The key bindings work for _ you_, but you have no idea what other people reading your answer are using so you can't just state "you comment blocks by typing control-/"
1

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.

Comments

1

As of Robot Framework 3.1 there is a dedicated section/table *** Comments ***

Comments: Additional comments or data. Ignored by Robot Framework.

This was introduced because, as of 3.1 unrecognized sections/tables causes an error. For more information, see https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-data-syntax

Comments

1

I just found that you can do multi line comments like this:

*** Test Cases ***

test1

   ${var1}   Set Variable  someVariable

   Comment   This is a comment
   ...       with multiple
   ...       lines.
  • Works for me. I'm using Robot Framework 4.1.2 (Python 3.8.2 on darwin)

Comments

1

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

Comments

0

Add a section *** Comment *** and put bellow all lines you want to be commented

Comments

0

Ctrl + Q if you are using VS code to comment /uncomment Multiple lines of code

Comments

0

We can use # to comment out multiple lines of code. You can simple use ctrl + /

1 Comment

This solution doesn't work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.