[英]In Json array of strings, how can I match a part of string is present? Karate DSL
I have a Json array of strings as below.我有一个 Json 字符串数组,如下所示。
How can I validate whether it contains today's date 2021-10-11 or the word PROCESSING-1 as a sub string in it?如何验证它是否包含今天的日期2021-10-11或单词PROCESSING-1作为其中的子字符串? BTW, I am trying it with Karate DSL
顺便说一句,我正在尝试使用空手道 DSL
[
"TEST1019005-2021-10-19T18:19:41.271055Z-PROCESSING-2",
"TEST1019005-2021-10-19T18:19:41.271055Z-PROCESSING-1",
"TEST1019002-2021-10-19T14:50:16.810678Z-PROCESSING-2",
"TEST1019002-2021-10-19T14:50:16.810678Z-PROCESSING-1",
"TEST1019002-2021-10-19T14:50:16.810678Z-PROCESSING-0",
"777777-2021-10-19T09:24:33.064845Z-PROCESSING-2",
"777777-2021-10-19T08:23:10.213230Z-PROCESSING-1",
"777777-2021-10-19T08:23:10.213230Z-PROCESSING-0",
"TEST1018001-2021-10-18T16:31:32.643392Z-PROCESSING-0",
"TEST1013001-2021-10-13T15:13:59.974540Z-PROCESSING-0",
"777777-2021-10-13T14:17:45.727585Z-PROCESSING-2",
"Test01-2021-10-11T20:20:05.968159Z-PROCESSING-1",
"Test01-2021-10-11T20:20:05.968159Z-PROCESSING-0",
"333333333-2021-10-11T20:11:26.474697Z-PROCESSING-0",
"333333333-2021-10-08T21:43:28.251925Z-PROCESSING-0",
"232623234-2021-10-08T21:27:04.363014Z-PROCESSING-0",
]
Here's part of the solution:这是解决方案的一部分:
* def today =
"""
function() {
var Formatter = Java.type("java.time.format.DateTimeFormatter");
var LocalDate = Java.type("java.time.LocalDate");
var dtf = Formatter.ofPattern("yyyy-MM-dd");
return dtf.format(LocalDate.now());
}
"""
* match each response contains today()
The rest is up to you.剩下的就看你了。 Note that there is a
#regex
match option as well: https://github.com/karatelabs/karate#fuzzy-matching请注意,还有一个
#regex
匹配选项: https : //github.com/karatelabs/karate#fuzzy-matching
Also refer these answers: https://stackoverflow.com/a/60945563/143475另请参阅这些答案: https : //stackoverflow.com/a/60945563/143475
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.