【问题标题】:Karate API - How to parameterize below Json post request空手道 API - 如何在 Json 发布请求下参数化
【发布时间】:2018-09-19 11:48:39
【问题描述】:

如何在代码中参数化项目块:-

Scenario Outline: parameterization


* text query =
"""
{
    "add":"Product",
    "item":[
        {"pn":"12345","qn":1,"m":"mk"} 
      ]

}
"""
    Given url baseURL
    And request { query: '#(query)' }
    And header Accept = 'application/json'
    When method post
    Then status 200

    Examples:
      | item_num  |
      | 12345 |
      | 67890 |

【问题讨论】:

    标签: karate


    【解决方案1】:
    Scenario Outline:
    * def json = { add: 'Product', item: [{ pn: '<itemNum>', qn: 1, m: 'mk'}]}
    * print json
    
    Examples:
      | itemNum  |
      | 12345 |
      | 67890 |
    

    【讨论】:

    • 感谢您的有用回复,但是当我插入上面的解决方案是我的代码时,我收到了一个错误。它在 com.intuit.karate.junit4.Karate 后方法失败 - 空手道版本:0.8.008:48:19.261 错误 com.intuit.karate - http 请求失败:null 功能:DataTable 场景大纲:测试 * def json = { add: 'Product', item: [{ pn: '', qn: 1, m: 'mk'}]} * print json 给定 url 'localhost/add' 并请求 json 当方法 post Then status 200 例子: |项目编号 | | 12345 | | 67890 |
    • @Sam - 现在是我要求您遵循这些说明的时候了。一切顺利:github.com/intuit/karate/wiki/How-to-Submit-an-Issue
    • 它在将 json 转换为字符串并将字符串作为请求正文传递后确实有效。我不确定它是否正确。这里是更新的代码:场景大纲:* def json = { add: 'Product', item: [{ pn: '', qn: 1, m: 'mk'}]} * print json * def reqBody = json 给定 url 'localhost/add';并请求 reqBody 当方法 post 时状态 200 示例: |项目编号 | | 12345 | | 67890 |示例:|项目编号 | | 12345 | | 67890 |
    • @sam 我也不确定
    • 将数据保存在 json 文件中然后我们可以读取该数据是一个好习惯吗?
    猜你喜欢
    • 2020-06-07
    • 2019-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-26
    • 2019-03-18
    • 2019-08-17
    相关资源
    最近更新 更多