Karate Karate-Config.Js Not a Js Function

Karate karate-config.js not a js function

Please use below code in the karate-config.js

function() {    
return priceBaseUrl='http://localhost:8080';
}

javascript function is not recognized as javascript code

Yes in Karate 0.9.3 onwards we have limited JS function nesting to only the top-level. You can find a full explanation in this comment.

So if you need JS function "name spacing" you can easily achieve this as per the documentation: https://github.com/intuit/karate#multiple-functions-in-one-file

And if you need more complex nesting, switch to using Java code where you can nest functions at any level.

Defining two o more functions in karate-config.js

No. It was never supposed to have been supported, I'm surprised it worked.

Also refer: https://github.com/karatelabs/karate#multiple-functions-in-one-file

not a callable feature or js function' Error when calling JS function from feature file

Here's a guess, you don't need to use call when simply invoking a function:

* def customerAge = util.getDate(object)

The call makes things a little bit easier to read only if it is a function

* def fun = function(x){ return { foo: x } }
* def customerAge = call fun 'bar'
# this will also work
# def customerAge = fun('bar')

Use a js file inside karate-config.js

Try:

var fun = read('basic-auth.js');
var res = fun();

When karate-config.js fails it prints error for each feature

As you know karate-config.js is executed before every scenario. A problem with this is considered "catastrophic". Karate is designed to try and move on to the next scenario.

Feel free to open a feature request and even contribute a fix - but my guess is because of the concept of a callSingle() it would be difficult to have the logic in place to do what you are requesting.

My personal opinion is that this behavior is acceptable, if karate-config.js fails - you have to fix it rather quickly. You can always use the JUnit runner or IDE integration to work on one feature and resolve this before moving on to the whole suite.

How can i call the js function in karate feature file with 1 argument

Karate doesn't support the arrow functions and instead of js map function we should use karate.map and if you want to collect the data from json array then using of JSON path would be better : def configIds = configResponse.configs[*].id



Related Topics



Leave a reply



Submit