Try karate.write(value, filename)
in JavaScript. We have kept this un-documented because we don't encourage it. Also the file will be written only to the current "build" directory which will be target
for Maven projects / stand-alone JAR.
value
can be any data-type, and Karate will write the bytes (or plain-text) out. There is no built-in support for any other format.
Here is an example.
EDIT: for others coming across this answer in the future the right thing to do is:
don't write files in the first place, you never need to do this, and this question is typically asked by inexperienced folks who for some reason think that the only way to "save" a response before validation is to write it to a file. No, please don't waste your time - and please just match
against the response
. You can save it (or parts of it) to variables while you make other HTTP requests. And do not write your tests so that scenarios (or features) depend on other scenarios, this is a very bad practice. Also note that by default, Karate will dump all HTTP requests and responses in the log file (typically in target/karate.log
) and also in the HTML report.
see if karate.write()
works for you as per this answer
write a custom Java (or JS function that uses the JVM) to do what you want using Java interop
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…