从csv文件中使用 \n 读取数据在Karate中。

huangapple go评论55阅读模式
英文:

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 | &lt;Data&gt; |
    * print body

and it prints.

{
  &quot;DataFromCSV&quot;: [
    {
      &quot;label&quot;: &quot; 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.&quot;,
      &quot;toolTip&quot;: &quot;Test&quot;
    }
  ]
}

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 -

{
  &quot;DataFromCSV&quot;: [
    {
      &quot;label&quot;: &quot; 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.&quot;,
      &quot;toolTip&quot;: &quot;Test&quot;
    }
  ]
}

答案1

得分: 0

这是为了使其成为有效的JSON。请阅读这个链接:https://stackoverflow.com/a/68411097/143475

当你"解包"它时,你会得到你想要的结果,试试这个实验:

  • def data = { label: '一些 \n 文本' }
  • 打印 data
  • 打印 data.label

欢迎您提交一个更改JSON规范的请求 从csv文件中使用 \n 读取数据在Karate中。

英文:

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: &#39;some \n text&#39; }
* print data
* print data.label

You are most welcome to submit a change request to the JSON spec 从csv文件中使用 \n 读取数据在Karate中。

huangapple
  • 本文由 发表于 2023年7月6日 11:04:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76625227.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定