Multi-line comments in Robot framework
There is no block comment function. However, there is a subtle little trick you can use to comment out entire blocks. It is not documented as a multi-line comment function, but it can be used like this.
This trick works in the knowledge that the robot will ignore any data in tables that are not one of the four recognized tables: keywords, tests, settings, or variables. If you have another table, everything underneath it until the next table is ignored.
the relevant section of the user manual says the following:
2.1.4 Data analysis rules
Ignored data
When Robot Framework parses 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 do the above test, you will see that only tests 1 and test3 are executed. Everything in the "comment" table is ignored.
source to share
No, you need to use it #
before every line you want to comment out.
However, please note that:
- If you are working with plain text files, the entire test before the first sector (settings, variables, or test cases) is free text and you do not need to comment on it.
- some IDEs offer shortcuts to comment multiple lines in one shot, like Ctrl+ /(or Command+ /if you're on a Mac) for PyCharm.
source to share
Ideally, if you want to comment out a line of Robot code, place your cursor on that line and press ctrl + /, it will comment out the line from the beginning of the line. as:
#<<Your Code lines here>>
If you want to specify which specific line or robot keyword is before that line or keyword, just type # and enter a comment. Like:
Click &{Locator} #This keyword clicks on the locator specified.
Also, you have the option to write documentation for the test case. For example: if your test case is about validating the login script, you can write the 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 helps.
source to share