Issue
I am trying to read the karate config in my mock server as per the documentation at https://karatelabs.github.io/karate/karate-netty/#background
Feature: stateful mock server
Background:
* call read('classpath:karate-config.js')
Scenario: pathMatches('/api/xml') && methodIs('post')
...
...
However i get an error on the line the call read is placed.
js failed:
>>>>
01: start('validateLocalCps.mock')
<<<<
org.graalvm.polyglot.PolyglotException: mock-server background failed - /cas_testing/auth/target/test-classes/auth/token/validateLocalCps.mock:4
- com.intuit.karate.core.MockHandler.<init>(MockHandler.java:116)
- com.intuit.karate.core.MockServer$Builder.build(MockServer.java:132)
- com.intuit.karate.core.ScenarioBridge.startInternal(ScenarioBridge.java:855)
- com.intuit.karate.core.ScenarioBridge.start(ScenarioBridge.java:817)
- <js>.:=>(Unnamed:1)
classpath:auth/token/validateLocalSuccess.feature:7
I am using karate version 1.2.0
My karate-config.js is inside src/test/java where as the feature files and mocks are inside other subdirectories.
How should i write this call so that i can read the config from my mock.
Solution
Read up on what the classpath:
means in the docs: https://github.com/karatelabs/karate#classpath
If still stuck, follow this process: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue
That said, teams usually never need to use karate-config.js
in mocks, it should be used only for tests. My suggestion is just keep it simple, read some data from a file side-by-side with your mock if needed.
Answered By - Peter Thomas
Answer Checked By - Senaida (JavaFixing Volunteer)