Karate 空手道模拟-`如何创建模拟以使用键从json获取值

Karate 空手道模拟-`如何创建模拟以使用键从json获取值,karate,Karate,空手道模拟-`如何创建模拟以使用键从json获取值。 在下面的示例中,我想使用id获取名称,iam无法检索 response.json { “2727”:“湿婆”, “2728”:“卡维” } demo-mock.feature 特性:有状态模拟服务器 背景: * def company = read('response.json') * def port = karate.env == 'mock' ? karate.start('demo-mock.feature').port : 808

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

response.json

{

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

}

demo-mock.feature

特性:有状态模拟服务器

背景:

* def company = read('response.json')
* def port = karate.env == 'mock' ? karate.start('demo-mock.feature').port : 8080
* url 'http://localhost:' + port + '/companies/search'
场景:路径匹配(“/companys/search/{id}}”)

测试特性

特点:集成测试

背景:

* def company = read('response.json')
* 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
阅读文档:

阅读文档:


嗨,Peter,我尝试了上述方法,但仍然无法获得id值。正在获取空响应。场景:pathMatches('/companys/search/{id}')*def id=pathParams.id*def response=id response:>GET 1>接受编码:gzip,deflate 1>连接:Keep Alive 1>主机:localhost:59233 1>用户代理:Apache HttpClient/4.5.5(Java/12.0.2)09:15:03.236响应时间(毫秒):122.74 1<200 1<内容类型:文本/plain@Siva对不起,我放弃了。你的问题本身是不清楚的,这个评论更糟糕。按照以下说明操作:嗨,Peter,我尝试了上述方法,但仍然无法获得id值。正在获取空响应。场景:pathMatches('/companys/search/{id}')*def id=pathParams.id*def response=id response:>GET 1>接受编码:gzip,deflate 1>连接:Keep Alive 1>主机:localhost:59233 1>用户代理:Apache HttpClient/4.5.5(Java/12.0.2)09:15:03.236响应时间(毫秒):122.74 1<200 1<内容类型:文本/plain@Siva对不起,我放弃了。你的问题本身是不清楚的,这个评论更糟糕。请按照以下说明操作: