如何设置基数 API?我看到第一个 API 的回复添加了双引号
How can I set base API? I see double quotes getting added from the first API's response
Given path '/api/metrics/product/ABC'
When method get
* def id = get response
* print id
* def basePathProducts = '/another/api/' + id + '/param'
Given path basePathProducts
When method GET
Then status 200
12:59:28.447 [main] INFO com.intuit.karate.StepDefs - [print] "5ca627bf3edd851238e59c9e" 2019 年 4 月 16 日 12:59:28 下午 org.glassfish.jersey.logging.LoggingInterceptor 严重日志:2 * 发送客户端在主线程 2 上请求 > GET
http://localhost:8080/API/ANOTHER/API/%225ca627bf3edd851238e59c9e%22/PARAM
你的post真难懂
尝试使用
Given url yourURLVariable + 'another/api/'+ id + '/param'
更多信息请参考:
编辑:
你的参数有问题。
* def id = "5ca627bf3edd851238e59c9e"
* print id
给予:
13:24:19.783 [print] 5ca627bf3edd851238e59c9e
所以你的变量 id
是 "5ca627bf3edd851238e59c9e"
而不是 5ca627bf3edd851238e59c9e
我认为你把事情搞得太复杂了,你错过了 path
语法是为你通常需要做的事情而设计的。
不要 def basePathProducts
并执行此操作,看看如何将 id
变量轻松插入路径:
Given path 'another', 'api', id, 'param'
* def newresp = function(id){ return id.slice(1, -1); }
* def id = newresp(response)
我添加这些是为了从响应中删除第一个和最后一个字符,在我的例子中是双引号。感谢您的回复!
Given path '/api/metrics/product/ABC'
When method get
* def id = get response
* print id
* def basePathProducts = '/another/api/' + id + '/param'
Given path basePathProducts
When method GET
Then status 200
12:59:28.447 [main] INFO com.intuit.karate.StepDefs - [print] "5ca627bf3edd851238e59c9e" 2019 年 4 月 16 日 12:59:28 下午 org.glassfish.jersey.logging.LoggingInterceptor 严重日志:2 * 发送客户端在主线程 2 上请求 > GET
http://localhost:8080/API/ANOTHER/API/%225ca627bf3edd851238e59c9e%22/PARAM
你的post真难懂
尝试使用
Given url yourURLVariable + 'another/api/'+ id + '/param'
更多信息请参考:
编辑: 你的参数有问题。
* def id = "5ca627bf3edd851238e59c9e"
* print id
给予:
13:24:19.783 [print] 5ca627bf3edd851238e59c9e
所以你的变量 id
是 "5ca627bf3edd851238e59c9e"
而不是 5ca627bf3edd851238e59c9e
我认为你把事情搞得太复杂了,你错过了 path
语法是为你通常需要做的事情而设计的。
不要 def basePathProducts
并执行此操作,看看如何将 id
变量轻松插入路径:
Given path 'another', 'api', id, 'param'
* def newresp = function(id){ return id.slice(1, -1); }
* def id = newresp(response)
我添加这些是为了从响应中删除第一个和最后一个字符,在我的例子中是双引号。感谢您的回复!