Karate 带有空手道DSL don'的嵌入式表达式;t替换json中的值
所以基本上我只是从空手道测试框架开始,可能遗漏了一些非常简单的东西,但我似乎无法正确地解析嵌入的表达式。如果我有一个像这样的功能文件,它可以通过两种方式执行相同的操作:Karate 带有空手道DSL don'的嵌入式表达式;t替换json中的值,karate,Karate,所以基本上我只是从空手道测试框架开始,可能遗漏了一些非常简单的东西,但我似乎无法正确地解析嵌入的表达式。如果我有一个像这样的功能文件,它可以通过两种方式执行相同的操作: Feature: Test Service Background: * url 'http://testurl:8080' * def localDateTime = Java.type('java.time.LocalDateTime') Scenario: Successful request
Feature: Test Service
Background:
* url 'http://testurl:8080'
* def localDateTime = Java.type('java.time.LocalDateTime')
Scenario: Successful request
* def createDateTime = LocalDateTime.now()
* def testRequest =
"""
{
createDateTime: "#(createDateTime)",
expiryDateTime:"#(localDateTime.now().plusMinutes(5))"
}
"""
* print testRequest
* set testRequest.createDateTime = createdTime
* print testRequest
然后当它到达打印行时,我得到如下输出,其中值是空的js对象{}
16:43:28.580[main]INFO com.intuit.karate-[print]{“createDateTime”:{},“ExpireDateTime”:{}16:43:28.586[main]DEBUG com.jayway.jsonpath.internal.pathciler-使用缓存路径:$true[]
此外,我还可以看到它似乎在为第一个print语句设置路径,如下所示:
16:32:30.612[main]DEBUG com.jayway.jsonpath.internal.CompiledPath-评估路径:$['createDateTime']
16:32:30.613[main]DEBUG com.jayway.jsonpath.internal.JsonReader-设置路径$['createDateTime']新值2017-09-14T16:32:30.566
16:32:30.629[main]DEBUG com.jayway.jsonpath.internal.CompiledPath-评估路径:$['expiryDateTime']
16:32:30.629[main]DEBUG com.jayway.jsonpath.internal.JsonReader-设置路径$['expiryDateTime']新值2017-09-14T16:37:30.621
有谁能向我解释一下为什么我无法将实际日期插入testRequest
谢谢。如果您将这些日期对象转换为字符串,我认为您的问题将得到解决
* def LocalDateTime = Java.type('java.time.LocalDateTime')
* def createDate = LocalDateTime.now() + ''
* def expiryDate = LocalDateTime.now().plusMinutes(5) + ''
* def testRequest = { createDateTime: '#(createDate)', expiryDateTime: '#(expiryDate)' }
* print karate.pretty(testRequest)
以上内容适用于我,这是输出:
06:11:47.010 [main] INFO com.intuit.karate - [print] {
"createDateTime": "2017-09-15T06:11:46.983",
"expiryDateTime": "2017-09-15T06:16:46.990"
}
似乎就是这样。非常感谢。