Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
563 views
in Technique[技术] by (71.8m points)

karate - Attaching screenshots to json report

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...