I am working on API testing project and have incorporated Karate to do so. Now my requirement is to create a server which will respond to the endpoint.All this is done but my requirement is to access variables defined in karate-config file in Server feature. I am unable to do so.
For example:
Feature: Sample server
Scenario: pathMatches('\variablevalue) ** methodIs('get')
- def response = default_env
Note: default_env is a variable in karate-config.js file and holds some default value.
Great question, we deliberately did not want to mix the karate-config.js
concept with the Karate server-side.
Normally when you instantiate a mock server via the API you can pass a Java Map
and all key-values will end up as Karate variables.
But here's a trick, you can do this in the Background
* call read('classpath:karate-config.js')
And this will have the exact same effect you are looking for ! Do let me know if this works, I will make sure this is updated in the documentation.
Note that you can use JSON if all you need is some seed-data:
* def cats = read('cats.json')