Siya
Siya

Reputation: 307

Multiline comments in Robot framework

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

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

Upvotes: 18

Views: 84614

Answers (10)

Nihitha Nina
Nihitha Nina

Reputation: 1

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

Upvotes: 0

user6731023
user6731023

Reputation:

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.

Upvotes: 2

Pikesh Jain
Pikesh Jain

Reputation: 11

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

Upvotes: 1

Kapil
Kapil

Reputation: 173

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

Upvotes: 0

M.GR
M.GR

Reputation: 51

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

Upvotes: 0

Joe
Joe

Reputation: 11

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)

Upvotes: 1

mathze
mathze

Reputation: 538

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

Upvotes: 1

Laurent Bristiel
Laurent Bristiel

Reputation: 6935

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.

Upvotes: 17

Brandon Olson
Brandon Olson

Reputation: 639

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.

Upvotes: 1

Bryan Oakley
Bryan Oakley

Reputation: 386342

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.

Upvotes: 34

Related Questions