简体   繁体   English

空手道:是否可以从场景大纲中匹配 json

[英]Karate: is it possible to match the json from scenario outline

My use case is to have a Scenario Outline implemented with examples and my small Api returns a json output which I want to parameterize.我的用例是用示例实现一个场景大纲,我的小 Api 返回一个 json output 我想参数化。

My use case is something like我的用例类似于

Scenario Outline : test
    Given url "http://myurl.com"
    And params {"id": "<id>"}
    When method get
     Then match response == "<schema>"

Examples:
| id | schema |
| 123 | {"id":"#present"} |
| 456 | {"id":"#present", "name":"test"} |
| 789 | {"id": "#present", "value":"#present"} |

The problem her is examples are taken as string so the match fails here with error: as it is trying to now compare the response {"id":"#present"} with "{"id":"#present"}" and fails Any way to case it back to json when reading from examples.她的问题是示例被视为字符串,因此匹配在此处失败并出现错误:因为它现在正在尝试将响应 {"id":"#present"} 与 "{"id":"#present"}" 和从示例中读取时,以任何方式将其转换回 json 失败。 Help would be appreciated.帮助将不胜感激。 Thank you谢谢

Add a !添加一个! after the column name.在列名之后。 Refer: https://github.com/intuit/karate#scenario-outline-enhancements参考: https://github.com/intuit/karate#scenario-outline-enhancements

Scenario Outline : test
  Given url "http://myurl.com"
  And params {"id": "#(id)"}
  When method get
  Then match response == schema

Examples:
| id! | schema! |
| 123 | {"id":"#present"} |
| 456 | {"id":"#present", "name":"test"} |
| 789 | {"id": "#present", "value":"#present"} |

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 空手道 DSL:如何将场景大纲变量传递到 json 字符串中 - Karate DSL: How to pass Scenario Outline variables into a json string 如何在空手道框架的场景大纲中添加“abortedStepsShouldPass”配置? - How to add 'abortedStepsShouldPass' configuration inside the scenario outline in Karate framework? 在空手道场景大纲测试中,如何通过变量传递示例表中的参数值 - In Karate Scenario Outline test, how to pass param values in the Examples table through a variable 无法识别在 csv 文件中存储和使用的用于空手道场景的 json 请求正文的正确格式 - Cannot identify proper format for a json request body stored and used in csv file for use in a karate scenario 针对特定情况从POJO生成JSON - Generating JSON from POJO for a specific scenario 空手道模拟测试双打无法识别 headerContains 场景参数 - Karate Mock Test Doubles not recognizing the headerContains scenario parameter 有没有办法为空手道 DSL 中的每个功能/场景分配一个唯一的“ID 密钥” - Is there a way to assign a unique “ID Key” to each feature/scenario in Karate DSL 如何在Karate Framework中从JSON api响应中计算记录数? - How we can count the number of records from JSON api response in Karate Framework? 空手道包含且所有键值不匹配错误 - Karate contains and all key-values did not match error 空手道 - karate.configure('headers', { Accept: 'application/json' }); 在 karate-config.js 文件中无法识别。 它说缺少导入语句 - Karate - karate.configure('headers', { Accept: 'application/json' }); is not recognized in karate-config.js file. It says missing import statements
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM