【问题标题】:Karate Mocks- `How to create a mocks to get a value from json using the key空手道模拟-`如何创建模拟以使用键从 json 获取值
【发布时间】:2022-02-27 16:34:11
【问题描述】:

空手道模拟-`如何创建模拟以使用键从 json 中获取值。 在下面的示例中,我想使用 id 获取名称,我无法检索

response.json

{

"2727": "湿婆", “2728”:“卡维”

}

demo-mock.feature

功能:有状态的模拟服务器

背景:

* def company = read('response.json')

场景:pathMatches('/companies/search/{id}}')

* def name = company.id 
* def response = name

test.feature

功能:集成测试

背景:

* def port = karate.env == 'mock' ? karate.start('demo-mock.feature').port : 8080
* url 'http://localhost:' + port + '/companies/search'

@模拟 场景:获取公司名称

Given path '2727'
When method get
Then status 200

【问题讨论】:

    标签: karate


    【解决方案1】:

    【讨论】:

    • 嗨彼得,我尝试了上述方法,仍然无法获取 id 值。得到响应为空。场景:pathMatches('/companies/search/{id}}') * def id = pathParams.id * def response = id 响应:> GET localhost:59233/companies/search/2727 1 > Accept-Encoding: gzip,deflate 1 > Connection: Keep- Alive 1 > Host: localhost:59233 1 > User-Agent: Apache-HttpClient/4.5.5 (Java/12.0.2) 09:15:03.236 响应时间(以毫秒为单位):122.74 1
    • @Siva 对不起,我放弃了。你的问题本身不清楚这个评论更糟。请遵循以下说明:github.com/intuit/karate/wiki/How-to-Submit-an-Issue
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-15
    • 1970-01-01
    相关资源
    最近更新 更多