Karate 有没有一种方法可以将负载中的json数组值用作可选字段?空手道DSL

Karate 有没有一种方法可以将负载中的json数组值用作可选字段?空手道DSL,karate,Karate,我开始使用空手道DSL进行API测试。我以前做过一些基本的测试。 我混合了动态数据驱动测试,所以我已经阅读了文档和用法。我正在使用独立的jar文件。现在,问题是我试图使用一个json文件,如下所示: [ { "name": null, "type": "informational", "description": "Poseidon was one of the Twelve O

我开始使用空手道DSL进行API测试。我以前做过一些基本的测试。 我混合了动态数据驱动测试,所以我已经阅读了文档和用法。我正在使用独立的jar文件。现在,问题是我试图使用一个json文件,如下所示:

[
  {
    "name": null,
    "type": "informational",
    "description": "Poseidon was one of the Twelve Olympians in ancient Greek religion and myth, god of the sea, storms.",
    "tags": null,
    "myAuth": null
  },
  {
    "name": "RegressionTestKarate-dsfdgfdgdfsgfdgsfdgfdsgfdsgsdfg",
    "type": "transactional",
    "description": null,
    "tags": ["regression", "poseidon", "suite", "test"],
    "myAuth": null
  }
]
在我的*.feature中,我使用数据发送如下请求:

* def myJson = { name: "##(name)", type: '##(type)', description: '##(description)', tags: '##(tags)' }    
Given url poseidonHostUrl
    And path "v1/projects"
      And request myJson
      When method post
      Then assert responseStatus == 400 || responseStatus == 401 || responseStatus == 403
因此,当我运行脚本时,当标签数组不为null时,它的替换并不像预期的那样。它字面上取以下值:
[…]“tags”:“##(tags)”

谢谢

正如上面的示例所示,您的标记数据是一个数组或null,因此您应该尝试这样做

* def myJson = { name: '##(name)', type: '##(type)', description: '##(description)', tags: '##[] #string' }    
Given url poseidonHostUrl
And path "v1/projects"
And request myJson
When method post
Then assert responseStatus == 400 || responseStatus == 401 || responseStatus == 403

抱歉,我已尝试使用建议的选项,但仍然存在相同的问题。它没有替换阵列。@Ricardgo请按照以下过程操作: