所以基本上我只是从空手道测试框架开始,并且可能缺少一些非常简单的东西,但我似乎无法得到一个嵌入式表达式来正确解决 . 如果我有一个像这样的功能文件,它可以做同样的事情:
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”:{},“expiryDateTime”:{}} 16:43:28.586 [main] DEBUG com.jayway.jsonpath.internal .PathCompiler - 使用缓存路径:$ 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?
谢谢 .
1 回答
我认为如果将这些日期对象转换为字符串,您的问题将得到解决 .
以上对我有用,这是输出: