The problem is you have created an invalid JSON that happens to have binary streams as the values. Just stick to comparing streams with streams - which will work as you have seen already. If you need to convert the PDF to a string you can do this:
* string aPdf2 = read('classpath:pdf.pdf')
Also you may have missed the difference between embedded-expressions and "enclosed javascript". Did you mean to do this ?
* def out = ({ one: aPdf1, two: aPdf2 })
or:
* def out = { one: '#(aPdf1)', two: '#(aPdf2)' }
Also for more context on JSON and binary values - refer this answer: https://stackoverflow.com/a/52541026/143475
EDIT: so if you want to compare two streams you have to convert them to byte-arrays first. Try this, and you can sub your own implementation of a stream-to-byte converter:
* def Utils = Java.type('com.intuit.karate.FileUtils')
* def stream1 = read('karate-logo.png')
* def bytes1 = Utils.toBytes(stream1)
* def stream2 = read('karate-logo.png')
* def bytes2 = Utils.toBytes(stream2)
* assert java.util.Arrays.equals(bytes1, bytes2)
EDIt - in newer versions of Karate you can "cast" to bytes
, and the match
keyword supports data which is bytes as well
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…