.. Badges
|License|
TemplatedData
=============
.. contents::
:local:
Introduction
------------
TemplatedData is Robot Framework library for dynamically generated test data using robot variables and Jinja templating.
Requirements
------------
Python 3.6+ and Robot Framework 3.2.1+.
TemplatedData will most likely work on other versions but it's not tested on them.
Installation
------------
You can install TemplateData by running::
pip install robotframework-templateddata
Usage
--------
You need to import TemplatedData as library first::
*** Settings ***
Library TemplatedData
TemplatedData will replace all occurences of robot variables (${var}) in file or variable using current robot context
and scopes. All test data in below examples are saved under 'test_data.txt' files
Test data::
my variable is ${var}
Robot code::
${var} Set Variable ${10}
${data} Get Templated Data From Path test_data.txt
Log ${data} # it should print `my variable is 10`
Default values
~~~~~~~~~~~~~~~~~~
If the variable is not found it will be replaced with empty string. You can override that behaviour::
${data} Get Templated Data From Path test_data.txt default_empty=${5}
Log ${data} # it should print `my variable is 5`
You can also set default value of variable with `:` symbol.
Test data::
my variable is ${var} and ${var2:some string}
Robot code::
${var} Set Variable ${10}
${data} Get Templated Data From Path test_data.txt
Log ${data} # it should print `my variable is 10 and some string`
Return value type
~~~~~~~~~~~~~~~~~~
Return value can be either text/string (default) or json.
Test data::
{ "key": "${var}" }
Robot code::
${data} Get Templated Data From Path test_data.txt var=value return_type=json
Log ${data} # it should print `{ "key": "value" }` and ${data} will be of type json
Jinja templating
~~~~~~~~~~~~~~~~~~
TemplatedData can also render the Jinja templates using Robot Framework variables. To enable Jinja template pass ``jinja_template`` as argument to
library import or method call::
*** Settings ***
Library TemplatedData jinja_template=${True}
OR
*** Keywords ***
Load Data
${data} Get Templated Data From Path data.template jinja_template=${True}
Test data (Jinja template)::
{
"accounts": [
{ "id": {{ ${account_id:5} }} },
{ "id2": "{{ ${account_id2} }}" }
],
"users": [
{%- for user, amount in ${users.items()} %}
{
"name": "{{ user }}",
"amount": {{ amount }}
}{{ "," if not loop.last }}
{%- endfor %}
]
}
Robot code::
${data} Get Templated Data From Path data.template jinja_template=${True}
Example data output::
{
"accounts": [
{ "id": 10 },
{ "id2": "10" }
],
"users": [
{
"name": "bartek",
"amount": 5
},
{
"name": "tymoteusz",
"amount": 10
},
{
"name": "pawel",
"amount": -1
}
]
}
.. Badges links
.. |License|
image:: https://img.shields.io/pypi/l/robotframework-robocop
:alt: PyPI - License
Raw data
{
"_id": null,
"home_page": "https://github.com/bhirsz/robotframework-templateddata",
"name": "robotframework-templateddata",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Bartlomiej Hirsz",
"author_email": "bartek.hirsz@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/7f/60/7380b083186472b6c5c64ef5ac0858c3e048a9bd3c32051e7976d3fdf9ef/robotframework-templateddata-1.4.0.tar.gz",
"platform": "any",
"description": ".. Badges\n\n|License|\n\nTemplatedData\n=============\n.. contents::\n :local:\n\nIntroduction\n------------\nTemplatedData is Robot Framework library for dynamically generated test data using robot variables and Jinja templating.\n\nRequirements\n------------\nPython 3.6+ and Robot Framework 3.2.1+.\n\nTemplatedData will most likely work on other versions but it's not tested on them.\n\nInstallation\n------------\nYou can install TemplateData by running::\n\n pip install robotframework-templateddata\n\nUsage\n--------\nYou need to import TemplatedData as library first::\n\n *** Settings ***\n Library TemplatedData\n\nTemplatedData will replace all occurences of robot variables (${var}) in file or variable using current robot context\nand scopes. All test data in below examples are saved under 'test_data.txt' files\n\nTest data::\n\n my variable is ${var}\n\nRobot code::\n\n ${var} Set Variable ${10}\n ${data} Get Templated Data From Path test_data.txt\n Log ${data} # it should print `my variable is 10`\n\nDefault values\n~~~~~~~~~~~~~~~~~~\n\nIf the variable is not found it will be replaced with empty string. You can override that behaviour::\n\n ${data} Get Templated Data From Path test_data.txt default_empty=${5}\n Log ${data} # it should print `my variable is 5`\n\nYou can also set default value of variable with `:` symbol.\n\nTest data::\n\n my variable is ${var} and ${var2:some string}\n\nRobot code::\n\n ${var} Set Variable ${10}\n ${data} Get Templated Data From Path test_data.txt\n Log ${data} # it should print `my variable is 10 and some string`\n\nReturn value type\n~~~~~~~~~~~~~~~~~~\n\nReturn value can be either text/string (default) or json.\n\nTest data::\n\n { \"key\": \"${var}\" }\n\nRobot code::\n\n ${data} Get Templated Data From Path test_data.txt var=value return_type=json\n Log ${data} # it should print `{ \"key\": \"value\" }` and ${data} will be of type json\n \nJinja templating\n~~~~~~~~~~~~~~~~~~\n\nTemplatedData can also render the Jinja templates using Robot Framework variables. To enable Jinja template pass ``jinja_template`` as argument to \nlibrary import or method call::\n\n *** Settings ***\n Library TemplatedData jinja_template=${True}\n \n OR\n \n *** Keywords ***\n Load Data\n ${data} Get Templated Data From Path data.template jinja_template=${True}\n\nTest data (Jinja template)::\n\n {\n \"accounts\": [\n { \"id\": {{ ${account_id:5} }} },\n { \"id2\": \"{{ ${account_id2} }}\" }\n ],\n \"users\": [\n {%- for user, amount in ${users.items()} %}\n {\n \"name\": \"{{ user }}\",\n \"amount\": {{ amount }}\n }{{ \",\" if not loop.last }}\n {%- endfor %}\n ]\n }\n\nRobot code::\n \n ${data} Get Templated Data From Path data.template jinja_template=${True}\n \nExample data output::\n \n {\n \"accounts\": [\n { \"id\": 10 },\n { \"id2\": \"10\" }\n ],\n \"users\": [\n {\n \"name\": \"bartek\",\n \"amount\": 5\n },\n {\n \"name\": \"tymoteusz\",\n \"amount\": 10\n },\n {\n \"name\": \"pawel\",\n \"amount\": -1\n }\n ]\n }\n\n.. Badges links\n\n.. |License|\n image:: https://img.shields.io/pypi/l/robotframework-robocop\n :alt: PyPI - License\n",
"bugtrack_url": null,
"license": "Apache License 2.0",
"summary": "Robot Framework library for generating test data from templates",
"version": "1.4.0",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "693f2dff73100aa546b282fd51c5cda4abaadb5875aba5218d6c262c2af913bb",
"md5": "09a9ec5a1cd9164fe071cd82af2b7091",
"sha256": "2bdbfe9a84f42b0911eef48dd2a5ec7e64e5cac89a8c78471ae58216994a55f6"
},
"downloads": -1,
"filename": "robotframework_templateddata-1.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "09a9ec5a1cd9164fe071cd82af2b7091",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 8528,
"upload_time": "2023-04-24T18:24:47",
"upload_time_iso_8601": "2023-04-24T18:24:47.488957Z",
"url": "https://files.pythonhosted.org/packages/69/3f/2dff73100aa546b282fd51c5cda4abaadb5875aba5218d6c262c2af913bb/robotframework_templateddata-1.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7f607380b083186472b6c5c64ef5ac0858c3e048a9bd3c32051e7976d3fdf9ef",
"md5": "e67bd2e9d8646ac215c33f9d73ee6af0",
"sha256": "53e1900b2a7bda62acdf324d38933e1bf44f6d63f6116397cebeab7feeb3c92b"
},
"downloads": -1,
"filename": "robotframework-templateddata-1.4.0.tar.gz",
"has_sig": false,
"md5_digest": "e67bd2e9d8646ac215c33f9d73ee6af0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8002,
"upload_time": "2023-04-24T18:24:49",
"upload_time_iso_8601": "2023-04-24T18:24:49.743087Z",
"url": "https://files.pythonhosted.org/packages/7f/60/7380b083186472b6c5c64ef5ac0858c3e048a9bd3c32051e7976d3fdf9ef/robotframework-templateddata-1.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-24 18:24:49",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "bhirsz",
"github_project": "robotframework-templateddata",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "robotframework-templateddata"
}