空手道 - 设置全局请求标题
因此,我设法编写了一堆测试,在每个功能文件中,我都设置了相同的请求标题。
例如:
Given url appUrl
And path '/path'
* header Accept = 'application/json'
我想知道是否有一种设置标头的方法,以便在运行每个方案之前设置它。我已经阅读了文档,并尝试了呼叫方法,如Akarate-config.js:
karate.callSingle('classpath:api/Utilities/Feature/header.feature');
header.feature看起来如下所示:
Feature: common routing that sets the headers for all features
Background:
* configure headers = { Accept : 'application/json' }
和示例功能,我希望标题可以预设:
Feature: Header Preset
Scenario: I expect the header to be set
Given url appUrl
And path '/path'
When method get
Then status 200
* print response
#I expect the response to be returned in JSON format
但是我无法使此功能正常工作。我认为我不了解呼叫方法的工作方式。一些指针会有所帮助。谢谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
忽略
现在就呼叫
,然后专注于配置头< /代码>
。
我认为您缺少一个步骤 - 这是为了确保
配置标头
在每个方案
之前已被“应用”。如果您100%确定此应用“全球”,则只需在karate-config.js
中执行此操作:否则,您使用
background> Background
(在每个功能中):通常有更多常见的步骤,因此您将它们放在每个测试中的“常见”功能文件和
调用
中。请参阅: https://github.com/intuit/karate#shared-scopeIgnore
callSingle
for now and focus onconfigure headers
.I think you are missing one step - which is to ensure that
configure headers
has been "applied" before eachScenario
. If you are 100% sure that this applies "globally", just do this inkarate-config.js
:Else you use the
Background
(in each feature):Typically you have more steps that are common, so you have them in a "common" feature file and
call
that for every test. Refer: https://github.com/intuit/karate#shared-scope对于自定义标题 - 在每个功能文件
set -headers.js中 -
For custom headers - in each feature file
set-headers.js -