空手道:空手道中是否有一个http请求钩子,在每次API调用后都会自动调用该钩子,并且我可以修改其行为? [英] Karate: Is there a http-request hook in karate, that gets called automatically after every API call, and whose behaviour I can modify?

查看:82
本文介绍了空手道:空手道中是否有一个http请求钩子,在每次API调用后都会自动调用该钩子,并且我可以修改其行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个通用的实现来编写:request-body,request-method&我在任何空手道功能文件中发出的所有HTTP请求的输出文件的响应正文.

I want a common implementation to write the: request-body, request-method & response-body to an output file for all the HTTP requests that I make in any of the karate feature files.

我已经阅读了文档,发现最接近的选项是 afterScenario 钩.但是,如果我想在同一场景中进行多个API调用,这对我没有帮助.

I have read through the documentation, and the closest option that I found was the afterScenario hook. However this doesn't help me in cases where I want to make multiple API calls in the same scenario.

我还尝试通过将karate.prevRequest对象传递给我编写的java函数来使用它.虽然这可以帮助我捕获所需的信息,但我必须在每次API调用之后继续调用我的java函数,这是我不想做的.

I also tried using karate.prevRequest object by passing it to java function that I wrote. While this helps me capture the information that I want, I have to keep calling my java function after every API call, which I don't want to do.

我希望能够编写一个在每次API调用后都会被调用的钩子,并使我能够访问请求正文,请求标头,响应标头,响应正文,请求方法和请求URL.

I want to be able to write a hook that gets called after every API call and gives me access to request-body, request-headers, response-headers, response-body, request-method and request URL.

这应该是相当简单的,显然我似乎在这里遗漏了一些东西.

This should be fairly straight forward, clearly I seem to be missing something here.

推荐答案

首先,我个人认为这是对空手道的滥用,与实际测试相比,您似乎对报告更感兴趣.花点时间考虑一下.空手道具有出色的报告集成功能,以我非常诚实,真诚的意见,您正在浪费时间进行此操作.没有人要求这个.

First, I personally think that this is a mis-use of Karate, and you seem to be more interested in reports than actually doing testing. Take some time to think about it. Karate has excellent report integration and you are just wasting your time doing this in my very honest, sincere opinion. No one has asked for this.

无论如何. 0.9.5.RC4中有一个新的ExecutionHook,详细信息在这里: https ://github.com/intuit/karate/issues/970#issuecomment-557443551

Anyway. There is a new ExecutionHook in 0.9.5.RC4, details here: https://github.com/intuit/karate/issues/970#issuecomment-557443551

您可以实现afterStep,查看它是否是method步骤,然后执行此操作.如果需要更改,请打开一个问题.

You can implement afterStep, see if it is a method step and then do this. If you need changes, open an issue.

只是记住了-在develop分支中,我们添加了一种拦截所有请求和响应的方法: https://twitter.com/karatedsl/status/1195240779213496320 -很高兴获得您的反馈,看看我们是否可以将这个概念与上述挂钩相结合-或在需要时改进界面

just remembered - in the develop branch we added a way to intercept all requests and responses: https://twitter.com/karatedsl/status/1195240779213496320 - will be happy to get your feedback and see if we can merge this concept with the above hook - or improve the interfaces if needed

这篇关于空手道:空手道中是否有一个http请求钩子,在每次API调用后都会自动调用该钩子,并且我可以修改其行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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