空手道-需要帮助来断言日期范围的单维数组 [英] Karate- Need help to assert a single dimension array for date range

查看:17
本文介绍了空手道-需要帮助来断言日期范围的单维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图断言一维数组中的值.我曾尝试使用 match,但看起来无法断言日期范围.

下面是对象数组:

<预><代码>["2019-04-24T17:41:28","2019-04-24T17:41:27.975","2019-04-24T17:41:27.954","2019-04-24T17:41:27.93","2019-04-24T17:41:27.907","2019-04-24T17:41:27.886","2019-04-24T17:41:27.862","2019-04-24T17:41:27.84","2019-04-24T17:41:27.816",2019-04-24T17:41:27.792"]

我试图断言以下日期范围之间的每个值:

MinDate:2019-04-24T17:25:00.000000+00:00MaxDate:2019-04-24T17:50:00.000000+00:00

我尝试了以下方法,但均无效:

* 匹配 dateCreated == '#[]?_.value >= fromDate'* eval for(var i = 0; i < responseJson.response.data.TotalItemCount; i++) dateCreated.add(responseJson.response.data.Items[i].DateCreated) karate.assert(dateCreated[i] >=从日期)

关于如何去做的任何提示/技巧.

解决方案

给你:

* def dateToLong ="""职能) {var SimpleDateFormat = Java.type('java.text.SimpleDateFormat');var sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");返回 sdf.parse(s).time;}"""* def min = dateToLong('2019-04-24T17:25:00.000')* def max = dateToLong('2019-04-24T17:50:00.000')* def isValid = function(x){ var temp = dateToLong(x);返回温度 >= min &&温度 <= 最大值 }* 定义响应 ="""["2019-04-24T17:41:27.975","2019-04-24T17:41:27.954","2019-04-24T17:41:27.93","2019-04-24T17:41:27.907","2019-04-24T17:41:27.886","2019-04-24T17:41:27.862","2019-04-24T17:41:27.84","2019-04-24T17:41:27.816",2019-04-24T17:41:27.792"]"""* 匹配每个响应 == '#?已验证(_)'

如果您对任何关键字有疑问,请参阅文档.我删除了列表中的第一个日期,因为它不一致,但是如果需要,您有足够的信息来处理它 - 您可能需要在某处使用一些条件逻辑.

I am trying to assert the values inside a single dimensional array. I have tried using match but it looks like the date ranges cannot be asserted.

Below is the object array:

[
"2019-04-24T17:41:28",
"2019-04-24T17:41:27.975",
"2019-04-24T17:41:27.954",
"2019-04-24T17:41:27.93",
"2019-04-24T17:41:27.907",
"2019-04-24T17:41:27.886",
"2019-04-24T17:41:27.862",
"2019-04-24T17:41:27.84",
"2019-04-24T17:41:27.816",
"2019-04-24T17:41:27.792"
]

I am trying to assert each values between the following date ranges:

MinDate:2019-04-24T17:25:00.000000+00:00
MaxDate:2019-04-24T17:50:00.000000+00:00

I have tried the following but none works:

* match dateCreated == '#[]? _.value >= fromDate'
 * eval for(var i = 0; i < responseJson.response.data.TotalItemCount; i++) dateCreated.add(responseJson.response.data.Items[i].DateCreated)  karate.assert(dateCreated[i] >= fromDate)

Any hint/tip on how to go about it.

解决方案

Here you go:

* def dateToLong =
"""
function(s) {
  var SimpleDateFormat = Java.type('java.text.SimpleDateFormat');
  var sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
  return sdf.parse(s).time;
} 
"""
* def min = dateToLong('2019-04-24T17:25:00.000')
* def max = dateToLong('2019-04-24T17:50:00.000')
* def isValid = function(x){ var temp = dateToLong(x); return temp >= min && temp <= max }

* def response =
"""
[
"2019-04-24T17:41:27.975",
"2019-04-24T17:41:27.954",
"2019-04-24T17:41:27.93",
"2019-04-24T17:41:27.907",
"2019-04-24T17:41:27.886",
"2019-04-24T17:41:27.862",
"2019-04-24T17:41:27.84",
"2019-04-24T17:41:27.816",
"2019-04-24T17:41:27.792"
]
"""
* match each response == '#? isValid(_)'

Please refer the docs if you have doubts about any of the keywords. I removed the first date in the list because it was not consistent, but you have enough info to handle it if needed - you may need some conditional logic somewhere.

这篇关于空手道-需要帮助来断言日期范围的单维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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