Given the following js where I set the url...
function fn() {
var root = 'https://google.com';
karate.log('root value is: ', root);
additionalconfig = {
root: root
}
return additionalconfig;
}
and the following feature file...
Feature:
Background:
* callonce read('seturl.js')
* url root
# * url 'https://www.google.com'
Scenario Outline:
# Given url root
Given path 'search'
And params {q: <option>}
When method GET
Then status 200
Examples:
| option |
| karate |
| api |
| test |
| graphql |
The url is being reset on subsequent runs after the first, but according to the documentation, this should not be happening.
reset error being returned:
01: root
<<<<
org.graalvm.polyglot.PolyglotException: ReferenceError: "root" is not defined
- <js>.:program(Unnamed:1)
Documentation referenced above - https://github.com/karatelabs/karate#path
Note that the path 'resets' after any HTTP request is made but not the url.
If the url is passed from a previous file, in the background, it only works for the first call, but if hardcoded (commented out) in the background, it works for all the scenario examples. Setting the url in the scenario itself also only appears to work for the first run as shown below as well.
Additionally, if I change the callonce to simply a call, the feature file works as expected, but that seems contradictory to the documentation - https://github.com/karatelabs/karate#callonce
Karate's callonce keyword behaves exactly like call but is guaranteed to execute only once. The results of the first call are cached, and any future calls will simply return the cached result instead of executing the JavaScript function (or feature) again and again.
As a result of the above tests, I see 2 potential issues based on the documentation actual results of "root" is not defined in subsequent runs
- the url value does get reset if set as a variable
- the callonce feature does not appear to be caching the results