我有2 json,如下所示:
* def first = [{"code":"00","name":"A","iconUrl":"https:env1.test.png"}, {"code":"01","name":"B"}, {"code":"03","name":"C","iconUrl":"https:env1.test.png"}, {"code":"02","name":"D"}]
* def second = [{"iconUrl":"https:env2.test.png", "code":"00","name":"A"}, {"code":"01","name":"B"}, {"iconUrl":"https:env2.test.png", "code":"03","name":"C"}, {"code":"02","name":"D"}]
我想比较2个json对象。所有对象都没有iconUrl,而那些包含url中env的区别的对象。
我尝试了以下方法:
* def first = [{"code":"00","name":"A","iconUrl":"https:env1.test.png"}, {"code":"01","name":"B"}, {"code":"03","name":"C","iconUrl":"https:env1.test.png"}, {"code":"02","name":"D"}]
* def second = [{"iconUrl":"https:env2.test.png", "code":"00","name":"A"}, {"code":"01","name":"B"}, {"iconUrl":"https:env2.test.png", "code":"03","name":"C"}, {"code":"02","name":"D"}]
* def size = second.length
And print " size: ", size
* def fun = function(i){ if (second[i].iconUrl != '#null') second[i].iconUrl = '#string'}
* def foo = karate.repeat(size, fun)
* match first contains second
我的测试失败,因为数组对象不包含iconUrl。如何为不包含iconUrl的对象添加另一个条件?
干得好:
* def fun = function(x){ if (x.iconUrl) x.iconUrl = x.iconUrl.replace('env2', 'env1'); return x }
* def secondFixed = karate.map(second, fun)
* match first == secondFixed
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句