将自定义步骤定义添加到空手道框架 [英] Adding custom step definitions to Karate framework

查看:14
本文介绍了将自定义步骤定义添加到空手道框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从复杂"响应标头中提取解析的字段,并在稍后的测试中使用该值.

I have a need to extract a field parsed from a "complex" response header and use that value later in the test.

似乎空手道中的header"关键字是为设置请求标头而设置的,而不是解析响应标头.

It seems that the "header" keyword in Karate is set up for setting request headers, not parsing response headers.

有没有办法添加自定义步骤定义来维护对场景变量存储的访问?似乎变量存储在 StepDefs 类中是私有的,似乎没有办法轻松扩展它.

Is there a way to add a custom step definition maintaining access to the scenario variable stores? It appears the variable stores are private in the StepDefs class, and there doesn't seem to be a way to extend it easily.

推荐答案

您可以访问响应标头.请查看 responseHeaders 的文档.

You can get access to the response headers. Please look at the documentation for responseHeaders.

也就是说,match header 捷径很可能就是您的身份正在寻找.

That said, the match header short-cut is most likely what you are looking for.

空手道的理念是您永远不需要编写自定义步骤定义.

Karate's philosophy is that you never need to write custom step-definitions.

edit:一些示例,听起来您只需要对 Location 标头进行一些字符串操作吗?您可以自由地将 JS 代码混合到空手道表达式中.

edit: some examples, sounds like you just need to do some string manipulation of the Location header ? You can freely mix JS code into Karate expressions.

* def location = responseHeaders['Location'][0]
# assume location = 'foo?bar=baz'
* def bar = location.substring(location.indexOf('bar=') + 4)

这篇关于将自定义步骤定义添加到空手道框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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