Getting callSingle() cached result is an exception. Here login feature calling basic-auth.js in background which provides basic auth and login endpoint returns bearer token in response. Whenever tried to call feature file with callSingle its throwing exception and getting error as org.graalvm.polyglot.PolyglotException: ReferenceError: "baseURL" is not defined.
Missing something here? tried to go through previous issues but unable to resolve it. Can someone help whats wrong here. Let me know if you need any more details.
login feature file -
Feature: Login API
Background:
* url baseURL
* def param = {refId: 'ABC123', institutionId: '1234'}
* def token = call read('file:src/test/java/scripts/basic-auth.js') { username: 'abc, password: 'test123' }
@smoke
Scenario: Login
* path '/test/login'
* request requestPayload = read('file:src/test/java/payloads/loginPayload.json')
* header Authorization = token
* headers param
* method post
* status 200
* def auth = response.payLoad.authorization
* print auth
config file -
function fn() {
var env = karate.env; // get system property 'karate.env'
karate.log('karate.env system property was:', env);
if (!env) {
env = 'sit';
}
var config = {
env: env,
baseURL : '',
authorisation: auth()
}
if (env == 'qa') {
config.baseURL = 'http://testqa.com/'
userName = 'abc'
passWord = 'test123'
} else if (env == 'sit') {
config.baseURL = 'http://testsit.com/'
userName = 'abc'
passWord = 'test123'
}
// var auth = karate.callSingle('file:src/test/java/examples/01_login/login.feature')
// config.auth
// karate.log(auth)
function auth() {
var auth = karate.callSingle('file:src/test/java/examples/01_login/login.feature')
karate.log(auth)
return auth;
}
return config;
}
Tried to look through existing issues and examples however unable to resolve it. Appreciate if you can provide help or any pointers. Whenever commented callSingle there is no issues and there is no error for baseURL. Thanks in advance.