如何调用有条件的header的另一个特性



我创建了一个带有步骤的公共库。我们在不同测试版本中使用的特性源。但在一个测试范围中,我们需要使用标题Datasource-Type: 'test',而在其他范围中则不需要。我们调用其他步骤的特征示例。feature:

Background:
* header Datasource-Type = 'test'
* def getToken = call read('classpath:com/coommons/karate/token-service.feature') 
* configure headers = { Authorization: #(getToken), Datasource-Type : 'test'} 
* def createSmth = call read('classpath:com/commons/karate/createSmth.feature') 
* def accId = createSmth.accId
* def id = createSmth.id

Scenario: Do Smth 

* def createSmthElse = call read('classpath:com/commons/karate/createSmthElse.feature') { Token: #(token) } 
* call read('classpath:com/commons/karate/putSmth.feature') 
* def createSmthElseAnother = call read('classpath:com/commons/karate/createSmthElseAnother.feature') 
Given url featureService
And path '/.../details/employeeSorting' 
And request {} 
When method post 
Then status 200 

我很满意在karate-config.js的一个项目中全局设置这个头,但它不能正常工作。

karate.configure('headers', { 'Datasource-Type': 'test' });

头文件由于某种原因仅在第一次调用时传递(仅对于* def getToken = call read('classpath:com/coommons/karate/token-service.feature'))

在使用*configure headers{}的情况下,my header只出现在Given When Then post featureService中,而不在其他调用步骤中。feature.

请建议如何设置这个标题Datasource-Type: 'test'无处不在的功能,我们调用其他步骤。

如果你做karate.configure()头应该适用于所有调用,所以如果它不发生-它可能是一个bug,所以请遵循这个过程:https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue

有一个与此相关的错误,所以请确保您使用的是最新版本:1.1.0或1.2.0.RC1

还需要注意的是,如果你设置了一个标题为null,它将不会被传递。

最后让我说太多的调用和重用可能是一件坏事,所以请阅读这个:https://stackoverflow.com/a/54126724/143475

相关内容

最新更新