英文:
Reading Data with \n from csv file in Karate
问题
以下是我维护在csv文件中的数据:
数据
"[{'label': ' Karate is the only open-source tool to combine API test-automation, mocks, performance-testing and even UI automation into a single, unified framework.\n 1. The syntax is language-neutral, and easy for even non-programmers. Assertions and HTML reports are built-in, and you can run tests in parallel for speed.','toolTip': 'Test'}]""
以下是我的feature文件中的场景:
And set body
| path | values |
| DataFromCSV | <Data> |
- print body
然后它会打印出以下内容。
{
"DataFromCSV": [
{
"label": " Karate is the only open-source tool to combine API test-automation, mocks, performance-testing and even UI automation into a single, unified framework.\n 1. The syntax is language-neutral, and easy for even non-programmers. Assertions and HTML reports are built-in, and you can run tests in parallel for speed.",
"toolTip": "Test"
}
]
}
在csv文件中有一个单独的\n,是否可以在将这些数据接收到feature文件时添加一个新行。
在场景中打印后的期望输出 -
{
"DataFromCSV": [
{
"label": " Karate is the only open-source tool to combine API test-automation, mocks, performance-testing and even UI automation into a single, unified framework.
1. The syntax is language-neutral, and easy for even non-programmers. Assertions and HTML reports are built-in, and you can run tests in parallel for speed.",
"toolTip": "Test"
}
]
}
英文:
Below is the data, I have maintained in the csv file
Data
"[{'label': ' Karate is the only open-source tool to combine API test-automation, mocks, performance-testing and even UI automation into a single, unified framework.\n 1. The syntax is language-neutral, and easy for even non-programmers. Assertions and HTML reports are built-in, and you can run tests in parallel for speed.','toolTip': 'Test'}]"
Below is my scenario inside feature
And set body
| path | values |
| DataFromCSV | <Data> |
* print body
and it prints.
{
"DataFromCSV": [
{
"label": " Karate is the only open-source tool to combine API test-automation, mocks, performance-testing and even UI automation into a single, unified framework.\n 1. The syntax is language-neutral, and easy for even non-programmers. Assertions and HTML reports are built-in, and you can run tests in parallel for speed.",
"toolTip": "Test"
}
]
}
There is single \n in the csv, is it possible to add a new line when we receive this data in feature file.
Expected output after printing in scenario -
{
"DataFromCSV": [
{
"label": " Karate is the only open-source tool to combine API test-automation, mocks, performance-testing and even UI automation into a single, unified framework.
1. The syntax is language-neutral, and easy for even non-programmers. Assertions and HTML reports are built-in, and you can run tests in parallel for speed.",
"toolTip": "Test"
}
]
}
答案1
得分: 0
这是为了使其成为有效的JSON。请阅读这个链接:https://stackoverflow.com/a/68411097/143475
当你"解包"它时,你会得到你想要的结果,试试这个实验:
- def data = { label: '一些 \n 文本' }
- 打印 data
- 打印 data.label
欢迎您提交一个更改JSON规范的请求
英文:
That's to make it valid JSON. Read this please: https://stackoverflow.com/a/68411097/143475
When you "unpack" it, you get what you want, try this experiment:
* def data = { label: 'some \n text' }
* print data
* print data.label
You are most welcome to submit a change request to the JSON spec
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论