将JSON传递到方案大纲

时间:2019-05-15 21:14:18

标签: karate

https://github.com/intuit/karate/issues/554

我有一个多行JSON,我想使用场景大纲对每一行进行迭代

如果我按行号调用,那是有效的,我正在使用动态JSON文件

Data.json

[
{
    "address": {
        "addressLine1": "ttes",
        "addressLine2": "Test"
    },
    "name": {
        "firstName": "TEST",
        "lastName": "TEST"
    },
    "phone": {
        "phoneExtension": "1234",
        "phoneNumber": "999999999"
    },
    "email": {
        "emailAddress": "TEST@TEST.com"
    }
},
{
    "address": {
        "addressLine1": "ttes1",
        "addressLine2": "Test1"
    },
    "name": {
        "firstName": "TEST1",
        "lastName": "TEST1"
    },
    "phone": {
        "phoneExtension": "1234",
        "phoneNumber": "999999999"
    },
    "email": {
        "emailAddress": "TEST@TEST1.com"
    }
}]

如果

Feature: Read from File

Background:
* def Testdata = read('Data.json')

Scenario Outline: [1] Test with multiple records on JSON

Given url_stg
And path 'test','test' 
And request Testdata[0]
When method POST  

Examples:
|Testdata   |

正在处理Testdata [0]。我有动态json,我正在寻找一种自动迭代json的方法。

我的请求正文应为JSON中的一行,如:

{
"address": {
    "addressLine1": "ttes1",
    "addressLine2": "Test1",

},
"name": {
    "firstName": "TEST1",
    "lastName": "TEST1",

},
"phone": {
    "phoneExtension": "1234",
    "phoneNumber": "999999999",
},
"email": {
    "emailAddress": "TEST@TEST1.com"
}

1 个答案:

答案 0 :(得分:1)

在下一版本中,这将变得更加容易,请参见以下票证:https://github.com/intuit/karate/issues/717#issuecomment-489339287

因此,如果您可以从源代码进行构建并进行测试,将会有所帮助。

现在您必须这样做:

And request { address: <address>, name: <name>, phone: <phone>, email: <email> }