将屏幕快照附加到JSON报告 [英] Attaching screenshots to json report

查看:60
本文介绍了将屏幕快照附加到JSON报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将屏幕截图附加到空手道JSON报告中最简单的方法是什么?

What is the easiest way to attach screenshots to Karate JSON report?

我们测试REST API,我们的测试用例需要在Web端执行一些操作(登录Web应用程序,执行验证,截屏).我们已经处理了一些静态方法,这些方法使用Java互操作机制从Karate调用. 我要做的是编写一些通用的可重用代码,以附加在测试执行过程中拍摄的屏幕截图. 我不想重复步骤:

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')

每次将屏幕快照附加到报告时. 最好直接从Java代码中附加已截取的屏幕截图,以免在场景中暴露此类细节. 有这种可能性吗?

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?

推荐答案

由于您似乎是高级用户-可以尝试一下. karate对象的类型为

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.

在编写JS包装程序时,我也没有发现任何问题,这样一来,屏幕截图就成为您的方案中的一线好手了.

I also see nothing wrong with writing a JS wrapper so that the screen-shot taking becomes a one-liner in your scenarios.

这篇关于将屏幕快照附加到JSON报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆