带有空手道DSL的嵌入表达式不会替换JSON中的值 [英] Embedded expressions with karate DSL don't replace value in json

查看:12
本文介绍了带有空手道DSL的嵌入表达式不会替换JSON中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,基本上我只是从空手道测试框架开始,可能遗漏了一些非常简单的东西,但我似乎无法正确解析嵌入的表达式。如果我有一个类似于so的功能文件,它会以几种方式做同样的事情:

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]infocom.tuit.karate-[print]{"createDateTime":{},"expiryDateTime":{}}16:43:28.586[Main]调试com.jayway.jsonpath.intral.Path编译器-使用缓存路径:$TRUE[]

此外,我还可以看到它似乎正在设置第一个print语句的路径,如下所示:

16:32:30.612[Main]DEBUG com.jayway.jsonpath.inder.CompiledPath-评估路径:$[‘createDateTime’] 16:32:30.613[Main]DEBUG com.jayway.jsonpath.inder.JsonReader-设置路径$[‘createDateTime’]新值2017-09-14T16:32:30.566 16:32:30.629[Main]调试com.jayway.jsonath.内部.CompiledPath-评估路径:$[‘expiryDateTime’] 16:32:30.629[Main]DEBUG com.jayway.jsonpath.inder.JsonReader-设置路径$[‘expiryDateTime’]新值2017-09-14T16:37:30.621

谁能向我解释一下为什么我无法将实际日期插入到测试请求中?

谢谢。

推荐答案

我认为,如果您将这些Date对象转换为字符串,您的问题将得到解决。

* 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"
}

这篇关于带有空手道DSL的嵌入表达式不会替换JSON中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆