如何匹配具有未在JSON ARRAY中传递NULL的空字段('')的响应 [英] How to match the reponse having empty fields(' ') which are not passing NULL in an JSON ARRAY

查看:53
本文介绍了如何匹配具有未在JSON ARRAY中传递NULL的空字段('')的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何匹配具有未传递NULL的空字段('')的响应,如果我尝试在每个响应中匹配#notnull,则脚本正在通过.但我在响应中看到很少的空白字段

How to match the reponse having empty fields(' ') which are not passing NULL, If I try #notnull in match each response, the script is getting pass. but I see few empty fields in the response

推荐答案

如果服务器返回空格,但您想将其验证为null,则说明您或服务器有误.

If your server is returning blank spaces but you want to validate them as null, either you or the server is wrong.

也就是说,您可以使用空手道轻松验证任何内容:

That said, you can easily validate anything you want using Karate:

* def isBlank = function(s){ return s ? ('' + s).trim() === '' : true }
* def foo = { bar: ' ' }
* match foo == { bar: '#? isBlank(_)' }

或者您甚至可以使用RegEx:

Or you could even use a RegEx:

* match foo == { bar: '#regex [ ]*' }

请参阅文档.

这篇关于如何匹配具有未在JSON ARRAY中传递NULL的空字段('')的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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