Robot Framework Libraries¶
etr provides the following Robot libraries that provides additional keywords when using the
robot plugin:
EtrUtilsEtrJson
Notational conventions:
Positional and thus mandatory arguments are enclosed with
<>, e.g.<timeout>.Optional and thus keyword arguments are enclosed with
[], e.g.[interval]. When used the optional argument is passed asinterval=VALUE.
EtrUtils¶
Keywords¶
Get Random PortReturns a random free port.
Example:
*** Settings ***
Library EtrUtils
*** Test Cases ***
Example Test
${port} = Get Random Port
Start Process myServer --port ${port}
Wait For Connection <host> <port> <timeout> [reason] [interval]Wait for TCP connection to be accepted on host on port or give up specified time timeout. timout must be be in Robot Framework’s time format, e.g.
2 s,1 min,1 minute 2 seconds.
Example:
*** Settings ***
Library EtrUtils
*** Test Cases ***
Example
# In this example we assume the web-server is started in
# e.g. a suite setup.
Wait For Connection localhost 80 6s reason=Wait for web server
Wait For Path <pathname> <timeout> [reason] [interval]Wait for path element pathname (e.g. file or directory) to exist or give up specified time timout must be be in Robot Framework’s time format, e.g.
2 s,1 min,1 minute 2 seconds.
Example:
*** Settings ***
Library Process
Library EtrUtils
*** Test Cases ***
Example
# Start process that should write pid-file when it is started.
Start Process <daemon writing daemon.pid>
# Now we wait for the PID file to be created
Wait For Path daemon.pid 6s reason=Wait for pidfile
EtrJson¶
Robot library that provides JSON-related keywords.
New in version 3.0.
Keywords¶
Decode Json <input str>Decodes <input str> and returns JSON result. Decoded objects use robot
robot.utils.DotDicttype which supports dot-access:${dict.key}.
Example:
*** Settings ***
Library EtrJson
*** Test Cases ***
Example Test
# Decode simple string
${value} = Decode Json "hi"
Should Be Equal As Strings "hi" ${value}
# Decode JSON object, which is represented as as DotDict
${value} = Decode Json {"key": "value"}
# Normal dictionary style
Should Be Equal As Strings "value" ${value["key"]}
# Dot-access
Should Be Equal As Strings "value" ${value.key}
Encode Json <input> [pretty]Encodes <input> and returns JSON string. Optionally pretty-printing the result if the optional parameter pretty is
True.
Example:
*** Settings ***
Library EtrJson
*** Test Cases ***
Example Test
# Encode simple string
${r} = Encode Json string
Should Be Equal "string" ${r}
# Create a dictionary to encode
${int} = Convert To Integer 1
&{dict} = Create Dictionary int-key=${int} string-key=string
${r} = Encode Json ${dict}
Should Be Equal As Strings ${r} {"int-key": 1, "string-key": "string"}