StringFormat is a string formatter for Robot Framework. This library is a python .format() wrapper.
*** Settings *** |
|||||
Library | StringFormat | ||||
*** Test Cases *** |
|||||
Format Text | |||||
${url}= | Format String | https://api.domain.com/users/{0}/sites/{1} | paul | internal | |
Should Be Equal | ${url} | https://api.domain.com/users/paul/sites/internal | |||
Format Dictionary Text | |||||
&{data}= | Create Dictionary | hostname=myhost | domain=foo.com | port=8080 | |
${url}= | Format String | http://{hostname}.{domain}:{port} | &{data} | ||
Should Be Equal | ${url} | http://myhost.foo.com:8080 |
StringFormat library utilizes python str.format method to construct formatted string. The format spec depends on what version of python this library being executed on. See the following resources for detail.
- Python 2: https://docs.python.org/2/library/string.html#format-string-syntax
- Python 3: https://docs.python.org/3.4/library/string.html#format-string-syntax