0% found this document useful (0 votes)
10 views

Robot Style

The Robot Style Guide outlines the structural conventions for organizing Robot Framework files, emphasizing the arrangement of settings, variables, test cases, and keywords. It details spacing rules for vertical and horizontal alignment, naming conventions for variables, and best practices for readability. The guide also advises on limiting argument numbers and using comments judiciously, ensuring clarity and consistency in code formatting.

Uploaded by

quanot
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Robot Style

The Robot Style Guide outlines the structural conventions for organizing Robot Framework files, emphasizing the arrangement of settings, variables, test cases, and keywords. It details spacing rules for vertical and horizontal alignment, naming conventions for variables, and best practices for readability. The guide also advises on limiting argument numbers and using comments judiciously, ensuring clarity and consistency in code formatting.

Uploaded by

quanot
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Robot Style Guide:

Structure
Structure follow: Settings => *** Settings ***
Variables => Test Cases/Tasks
=> Keywords
*** Variables ***

*** Test Cases ***

*** Keywords ***


For easier navigation, libraries in *** Settings ***
Library BuiltIn
each group can be sorted Library Collections
alphabetically. Additionally, extra Library DateTime
new lines can be used to Library OperatingSystem
separate the builtin, 3rd party
and custom libraries. Library Browser
Library JSONLibrary
Library SSHLibrary

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

*** Settings ***


Library BuiltIn
Library Collections
Library DateTime
Library OperatingSystem

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:

1. It is a good idea to put static variable assignments before keyword


calls.
*** Keywords ***
Keyword With Static Variables
[Arguments] ${argument}
${static variable} Set Variable This is a static
variable.
Set Local Variable ${other static variable} Another way to set
a static variable.
${dynamic variable} Catenate SEPARATOR=${SPACE}
${static variable}
... ${other static variable} ${argument}
${another dynamic variable} Evaluate $static
variable.upper()
Log To Console ${dynamic variable}
Should Not Be Equal ${static variable} ${other static
variable}

I. Vertical Spacing ( *.robot and *.resource)


Convention:

① 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 lines
⑥ One space Between Keywords
⑦ No space between continuation lines
⑧ One space for separating code blocks
⑨ One space at the very end of the file

Best practices:
*** Settings ***
Documentation This is documentation
... robot -d Results -i example-tag Tasks

Library Collections
Resource ../Resources/ExampleResource.resource

Suite Setup Suite Setup Keywords


Suite Teardown Suite Teardown Keywords

*** Variables ***


${EXAMPLE SCALAR VARIABLE} This is a suite scope scalar variable
@{EXAMPLE LIST VARIABLE} This is a suite scope list
variable
&{EXAMPLE DICTIONARY VARIABLE} This=is a
... suite=scope
... dictionary=variable

*** Tasks ***


An Example Task
[Documentation] Task documentation
[Tags] standard-example-tag
${RESULT LIST} This Is A Complex Keyword With Sections ${EXAMPLE SCALAR
VARIABLE}
Log To Console ${RESULT LIST}

A More Complex Task


[Documentation] Task documentation
[Tags] standard-example-tag
[Setup] Set Task Variable ${EXPECTED LENGTH} 2
${IS LARGER THAN FOUR} Create List

## 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}

An Example Templated Task


[Documentation] Templated task documentation.
[Tags] templated-example-tag
[Template] This Is A Complex Keyword With Sections
${EXAMPLE DICTIONARY VARIABLE}[This]
${EXAMPLE DICTIONARY VARIABLE}[suite]
${EXAMPLE DICTIONARY VARIABLE}[dictionary]

*** Keywords ***


Suite Setup Keywords
[Documentation] A keyword for setting up a suite
Log To Console Setting up ${SUITE NAME} keywords

Suite Teardown Keywords


[Documentation] A keyword for tearing down a suite
Log To Console Tearing down suite keywords

Task Setup Keywords


[Documentation] A keyword for setting up a task
Log To Console Setting up ${TASK NAME} keywords

Task Teardown Keywords


[Documentation] A keyword for tearing down a task
Log To Console Tearing down task keywords

II. Horizontal Spacing ( *.robot and


*.resource)
1. Separator >= 4 spaces represented by ···· in the following
examples
2. Indentation n time 4 spaces (where n is the level of
indentation) and n never exceeds 5, hence nesting depth
cannot exceed 4 steps in a keyword.
3. Trailing whitespaces should be avoided
4. A line length of 120 characters is recommended
5. The *** Settings *** and *** Variables *** section should
always be left aligned without any indentation.
*** Settings ***
Library Collections
Resource data.resource
Variables vars.robot
*** Variables ***
${VAR} my variable
${VAR2} 2
6. Arguments to *** Settings ***: be separated with 4 spaces + be
aligned in columns
*** Settings ***
Library String
Library DataDriver my_data_file.csv dialect=UserDefined
delimiter=.
Library Telnet timeout=3s newline=CLRF
encoding=UTF-8
Resource ${resourcedir}/mykeywords.resource
Resource ${resourcedir}/myotherkeywords.resource
Test Tags mytag

You might also like