Robot Framework 2.9 added support for multiline literal strings per the docs.
test.robot
*** Variables ***
${example_regex} = SEPARATOR=
... (?m)Setting IP address to [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\n
... Setting MAC address to [0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}\\n
... Setting IP forwarding kernel options
*** Test Cases ***
Show output
Log \n${example_regex} console=yes
robot test.robot
==============================================================================
Test
==============================================================================
Show output
(?m)Setting IP address to [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\nSetting MAC address to [0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}\nSetting IP forwarding kernel options
Show output | PASS |
------------------------------------------------------------------------------
Test | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
A few notes:
- All leading and trailing whitespace is trimmed from each line
- A plain
SEPARATOR=
in the first line specifies no separator
You may also consider using variable files since then you get all the power of Python literal formatting, which can make maintaining things like complicated regular expressions easier. If you're using Robot Framework 3+ and Python 3.5+ (for f
-strings) then it can look like:
vars.py
ip_address_pattern = r'[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
lower_mac_address_pattern = '[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}'
example_regex = (
rf'(?m)Setting IP address to {ip_address_pattern}\n'
rf'Setting MAC address to {lower_mac_address_pattern}\n'
'Setting IP forwarding kernel options'
)
test.robot
*** Settings ***
Variables vars.py
*** Test Cases ***
Show output
Log \n${example_regex} console=yes
Which results in the same output as above.