-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing header in spite of "configure headers" #2539
Comments
Likely due to no shared scope here. Can you try this instead: |
That works indeed, at least in the simplified example files. In my real tests I'd like to have the call configurable, though (we have a development mode that doesn't need it), so it really looks like
Any idea how I can have that with |
Yes, that can be achieved by putting the conditional within the called feature/js instead. However, this would be arguably less readable since someone would have to check the called file to find out the condition, plus it's a wasted read/call to the file in dev. Tho, maybe that's all you need given that there's no shared scope overload for callSingle. @ptrthomas , how would you feel about |
@dvargas46 yes I think that makes sense. interesting why this has not come up before. I was looking at the existing reference example:
so even the examples, the pattern is - a) callSingle returns some data b) that data is used to configure headers "centrally" in karate-config.js |
@ptrthomas I think you are right, I believe what you outlined would be the recommended pattern to use here too. For example, it could looks something like this to set the auth header globally instead using callSingle: karate-config.js function fn() {
const config = {}
const headers = {}
if (karate.env !== 'dev') {
// configure headers with authentication only in non-dev environments - callSingle only called once
const results = karate.callSingle('header.feature', {username: 'myUsername'})
headers.Authorization = results.authHeader
}
//
// any other headers or config variables can also be set ...
//
karate.configure('headers', headers)
return config
} header.feature @ignore
Feature: Header
Scenario: Return Authorization header
# or perform some operation with the input first, like Base64 encoding of credentials, etc.
* def authHeader = 'Basic 12345' test.feature Feature: Test
Background:
* url 'http://example.com'
# set any scenario specific headers as needed
* header X-TOKEN = 'token-needed-here'
Scenario: Some test
When method GET
Then status 200 |
To be able to run my tests with an external authentication tool, I have tried to factor out the authentication request into a separate file, but the
configure headers
in that file does not seem to have any effect in the tests.The problem can already be reproduced with the attached files (without any real authentication and just a dummy call to example.com):
header.feature
test.feature
Running
shows that header.feature is called properly, but the GET call in test.feature does not have the "Authorization" header that should have been set.
testfiles.zip
The text was updated successfully, but these errors were encountered: