다음과 같이 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] 삭제
몇 마디 만하겠습니다