Attaching screenshots to json report

坚强是说给别人听的谎言 提交于 2020-08-08 03:41:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!