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
Check If File Exists on Remote Server Using Its Url
Best Practice for Passing Many Arguments to Method
Reading and Displaying Data from a .Txt File
Jframe.Dispose() VS System.Exit()
Spring 4 - Addresourcehandlers Not Resolving the Static Resources
Right Way to Write JSON Deserializer in Spring or Extend It
How to Find Out If "Debug Mode" Is Enabled
How to Get Subnet Mask of Local System Using Java
@Preupdate and @Prepersist in Hibernate/JPA (Using Session)
How to Add Days to a Date in Java
Gson.Tojson() Throws Stackoverflowerror
How to Save Parsed and Changed Dom Document in Xml File
How to Create an Instance of Inner Class Using Java Reflection
Why Integer.Max_Value + 1 == Integer.Min_Value
Noclassdeffounderror While Trying to Run My Jar with Java.Exe -Jar...What's Wrong