问题
I am looking to pass Authorization Header as a variable to another feature file. Here is an example I am trying to do:
Feature: Resource Creation
Background:
* url baseUrl
Scenario: Create Resource
Given def basictoken = 'Basic Zn*****'
And def token = call read('classpath:endpoints/UserLogin.feature')
Given path 'lobs'
And header X-XSRF-TOKEN = token.xsrftoken
And header Cookie = 'SESSION='+token.scookie+'; '+'XSRF-TOKEN='+token.xsrftoken
And request [{"name":"Boston"}]
When method post
Then status 200
Here is the file it is referring to:
Feature: Common User Login
Background:
* url baseUrl
Scenario:
Given path 'security/user'
And header Authorization = '#(basictoken)'
When method get
Then status 200
Given path 'rname/name'
When method get
Then status 200
And def xsrftoken = responseCookies["XSRF-TOKEN"].value
And def scookie = responseCookies["SESSION"].value
I am getting error when at And header Authorization = '#(basictoken)'
Is there a way I can pass it ? When I hardcode it to its value, I don't see any issue. Could you help us on how to pass variable from one feature file to another. Thanks in advance.
回答1:
Please make this change:
Given def token = call read('classpath:endpoints/UserLogin.feature') { basictoken: 'Basic Zn*****' }
All the best :P
来源:https://stackoverflow.com/questions/45824884/karate-api-testing-passing-variable-from-one-feature-file-to-another