2

I have created a common library with steps.feature source that we used in different repos of tests. But in one scope of tests we need to use header Datasource-Type: 'test' and in others not. Sample of feature where we call other steps.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 

I am satisfied with the option to globally set this header in one of the projects in karate-config.js, but it does not work correctly.

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

Headers are passed for some reason only for the first call (only for * def getToken = call read('classpath:com/coommons/karate/token-service.feature') )

In case with *configure headers {} my header appears only in Given When Then post featureService, but not in other calling steps.feature.

Please, advice how to set this header Datasource-Type: 'test' everywhere from feature where we call other steps.feature and without hardcoded this header directly in steps.

Belinka_23
  • 31
  • 2

1 Answers1

1

If you do karate.configure() the headers should apply to all calls, so if it doesn't happen - it can be a bug, so please follow this process: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue

There was a bug related to this, so please ensure you are on the latest version: 1.1.0 or 1.2.0.RC1

Also note that if you set a header to null it will not be passed at all.

And finally let me say that too many calls and re-use can be a bad thing, so please read this: https://stackoverflow.com/a/54126724/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248