Robot Style
Robot Style
Structure
Structure follow: Settings => *** Settings ***
Variables => Test Cases/Tasks
=> Keywords
*** Variables ***
Library Acustom
Library Bcustom
Library Ccustom
Library Dcustom
Vertical Spacing
Two spaces between sections
One space between
Tests/Tasks
No space in the settings
section of Tests/Tasks or
Keywords
No space after settings
section of Tests/Tasks or
Keywords
No spaces between template
Test/Task data line
One space Between
Keywords
No space between
continuation lines
One space at the very end of
the file
Horizontal Spacing
Separator >= 4 spaces *** Settings ***
Library String
represented by ···· Library DataDriver my_data_file.csv
Indentation n time 4 spaces dialect=UserDefined delimiter=.
(where n is the level of Library Telnet timeout=3s
indentation) and n never newline=CLRF encoding=UTF-8
Resource $
exceeds 5, hence nesting {resourcedir}/mykeywords.resource
depth cannot exceed 4 steps Resource $
in a keyword. {resourcedir}/myotherkeywords.resou
rce
A line length of 120
Test Tags mytag
characters is recommended
Trailing whitespaces should
be avoided
The *** Settings *** and ***
Variables *** section should
always be left aligned
without any indentation
Arguments *** Settings ***:
be separated with 4 spaces
and be aligned in columns
Comment
Comments should be *** Keywords ***
## Comment about Some Keyword here
avoided, write your code Some Keyword
readable or use the Called Keyword One
[Documentation]. The only ## Comment about Called Keyword
valid use of comments is for Two here
Called Keyword Two ## TODO
TODO's that should be fixed fix weird behaviour.
soon.
Comments should be
aligned with the block
they belong to.
Inline comments have
one indentation before
the #
Line Continuation
Try limiting the number *** Keywords ***
Custom Keyword With Various
of arguments to 5 Optional Arguments
One argument per [Arguments] ${first arg}=the
continuation line. first argument
Continuation line should ... ${second
arg}=${123}
not be indented. ... ${third arg}=$
Line continuation {some list}
character (...) should be ... ${fourth arg}=$
{some dict}
placed at the beginning ... ${fifth arg}=the
last argument
of the new row. Do Something
No empty lines between
arguments.
No empty continuation
lines between
arguments (i.e., lines
containing only '...')
If many arguments are
required, consider
representing them as a
list or a dictionary.
Note: If Test Cases include
Keywords with relatively
short names and with only a
few arguments, then
arguments can be
accommodated on a single
line if the maximum length of
the line is not exceede
Variables Name
GLOBAL variables use upper- ${UPPER_CASED}
case letters.
SUITE variables use upper- ${UPPER_CASED}
case letters.
Note: Variables declared within
the *** Variables *** section are
Suite level in scope
TEST variables use upper- ${UPPER_CASED}
case letters.
Note: Variables in Data driver
data are Test level in scope
LOCAL variables use lower- ${lower_cased}
case letters.
Keyword arguments use ${lower_cased}
lower-case letters.
Declaring Variable Scope
Properly:
It is advised to not
reuse GLOBAL or SUITE
variable names in lower
scoped contexts.
Variable Assignment Syntax
When use ‘=’ for assign *** Keywords ***
Setting Variables
variable => be sure that it is ${var} = Set Variable
formatted ${var} = good
(The reason for a space ${var}= Set Variable not
immediately after a variable great, but seen commonly
is to make the variable more
readable)
Naming Convention
Test case file name: It’s
*.robot file
and start with test case ID in test
report
Convention: 1.1. Settings:
Recommend: For easier navigation, libraries in each group can be sorted
alphabetically. Additionally, extra new lines can be used to separate the
builtin, 3rd party and custom libraries.
*** Settings ***
Documentation
Metadata
Library BuiltIn
Library 3rd Party
Library Custom
Resource
Variables
Suite Setup
Suite Teardown
Test Setup
Test Teardown
Test Template
Test Timeout
Test Tags
Library Browser
Library JSONLibrary
Library SSHLibrary
Library Acustom
Library Bcustom
Library Ccustom
Library Dcustom
1.2. Variables
Convention: Simple variables (scalar, list, dictionary) variables should be
listed first. Composite variables (variables composed of other variables)
should be listed after simple variables.
Best practices:
*** Variables ***
${VARIABLE} This is a Variable
${COMPOSITE VARIABLES} ${VARIABLE} with other variables.
1.3. Keywords
Convention:
Best practices:
*** Settings ***
Documentation This is documentation
... robot -d Results -i example-tag Tasks
Library Collections
Resource ../Resources/ExampleResource.resource
## Adding vertical white space can be used to separate task code blocks
FOR ${item} IN @{EXAMPLE LIST VARIABLE}
IF len($item)> 4
This Is A Complex Keyword With Sections ${item}
Append To List ${IS LARGER THAN FOUR} ${item}
END
END
Length Should Be ${IS LARGER THAN FOUR} ${EXPECTED LENGTH}