Adding custom step definitions to Karate framework(将自定义步骤定义添加到空手道框架)
问题描述
我需要从复杂"响应标头中提取解析的字段,并在稍后的测试中使用该值.
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)
这篇关于将自定义步骤定义添加到空手道框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将自定义步骤定义添加到空手道框架
基础教程推荐
- 在螺旋中写一个字符串 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01