问题
What is the easiest way to attach screenshots to Karate JSON report?
We test REST API and our tests cases require to perform some operation on web side(log into web application, perform verification, take screenshot). We've handled with it writing some static methods which are called from Karate using Java interop mechanism. What I want to do is write some generic, reusable code to attach screenshots taken during test execution. I don't want to repeat steps:
* def bytes = getScreenBytes()
* eval karate.embed(bytes,'image/jpg')
each time when screenshot should be attached to report. It would be perfect to attach taken screenshots directly from java code to not to expose such details in scenarios. Is there such possibility?
回答1:
Since you seem to be an advanced user - you can try this. The karate
object is of type ScriptBridge and you should be able to pass it into your custom Java code (which we normally do not recommend). Now you can call methods in Java such as embed()
etc.
I also see nothing wrong with writing a JS wrapper so that the screen-shot taking becomes a one-liner in your scenarios.
来源:https://stackoverflow.com/questions/55345236/attaching-screenshots-to-json-report