Authorisation Key in Karate API [duplicate] - api

I would like to update my common headers (Accept and Content-Type) just in one feature file. however, I would like to use Authorization token which already configured in Karate.config.cs file.
Could you please help me with this?

This is explained in detail in the docs: https://github.com/intuit/karate#configure-headers
* configure headers = read('classpath:my-headers.js')
And you can refer to variables declared in karate-config.js anywhere in Karate. Again read the docs, and there are multiple examples. Next time please ask a more specific question: https://stackoverflow.com/help/minimal-reproducible-example

Related

Cached response increments the number of hits in the server when we use that access token in another API hit [duplicate]

I have multiple feature files in my project. One of the feature file creates tokens. I want to call this feature only once at the start of the test and then use the tokens in the other feature without executing the token feature again and again.
Can someone please help me with this ?
Look at callSingle() in karate-config.js and please refer the docs: https://github.com/intuit/karate#hooks
var result = karate.callSingle('classpath:tokens.feature');

Refference JSON schema from "define" API YAML file in Postman instead of creating a variable with actual JSON

I have an API in Postman that has defined JSON schemas for every request\response.
I also have a collection of tests that i use for testing this API.
But I don't know how to connect these two substances(things)
I have been searching for a solution for quite a while now and havent found an example set-up or a tutorial how? instead of creating a variable with actual schema in my test collection, I want to reuse already existing schema from API by $ref or some other link method.
This is my first question here, writing it just cause i haven't found a proper answer but functionality that i seek sounds really basic and logical.
Update from Valentin Despa:
"Please note that the API definition is written in a specification like Open API (or similar). It is not the same as the JSON schema which refers to the response body only."
So we can't validate response using that schema.

Is there any way to update the values of the feature file from the internally called feature file [duplicate]

I need to post a request to get an authorization token and include it in the header for all subsequent test requests. This token changes every time but it is valid for the entire test session as long as I keep sending requests. In each feature file I can call another feature file to get this token. But I don't want to do this for every feature file. I just want to get the token one time at the start of the test and use it for all feature files. How do I do that? I've read the Karate information on GitHub but did not find the answer.
The second example in the demos answers all your questions: karate-demo.
EDIT1: Sorry, I read your question too fast. You can use karate.call() in karate-config.js so it applies to all feature files. I don’t recommend this because you will always have some features where you DONT need this. Just use a call to a feature and don’t over-engineer your tests.
EDIT2: I thought about this a little more, if you are comfortable with Java, you could make a call to a singleton at the start of each feature (or even in the global karate-config.js) and in that singleton cache the value of the auth token. So you can do exactly what you need and it will be flexible.
EDIT3: based on this question - we added this functionality to Karate as a karate.callSingle() operation, here's the doc: https://github.com/intuit/karate/tree/develop#the-karate-object

Karate integration with type config

can we use any config framework like type config for java in karate? it can be used to pick up the values of keys mentioned in configuration file as per requirement.we have been using rest assured and type config.
One word of advice is you need to un-learn a lot of "Java things" when you start with Karate. There is no need for type-config. Please see the documentation: https://github.com/intuit/karate#configuration
Also see this example for a example of "picking up keys" like you say: https://stackoverflow.com/a/49693808/143475
If you have a specific need, please ask a new question, and provide good examples. Anything is possible in Karate.

Is it possible to look at a URL and determine if it's using Struts?

example:
http://www.boston.com/travel?p1=Levelone_Nav_travel
will we be able to say if this website code is developed using Struts framework ? If so how, details please.
Not necessarily.
The HTTP headers sometimes include relevant information, but not reliably.