When karate-config.js fails it prints error for ea

2019-08-06 10:09发布

问题:

Karate-Netty version 0.9.2

Whenever my karate-config.js evaluation fails it prints:

16:49:28.753 [ForkJoinPool-1-worker-1] ERROR com.intuit.karate - evaluation of 'karate-config.js' failed: javascript function call failed: unexpected 'configure' key: 'followRedirectss'
16:49:28.761 [ForkJoinPool-1-worker-1] ERROR com.intuit.karate - javascript function call failed: unexpected 'configure' key: 'followRedirectss'
16:49:28.762 [ForkJoinPool-1-worker-1] ERROR com.intuit.karate - failed function body: function fn(){   
   << MY SUPER AMAZING SCRIPT HERE >>
}

Note here I made if fail on purpose with trivial error just to provoke it ^

After the error it would print it for every scenario in every feature file I have, so having 55 feature files with 304 scenarios and karate-config.js with 104 lines you can imagine that this gets bad very fast.

So karate-config 5 lines long with intentional fail + 2 features with single scenario look something like this:

Generating a RSA private key
.+++++++++++++++++++++++++++
...+++++++++++++++++++++++++++
writing new private key to 'key.pem'
-----
17:06:36.217 [main] INFO  com.intuit.karate.netty.Main - Karate version: 0.9.2
17:06:36.426 [main] INFO  com.intuit.karate.Runner - Karate version: 0.9.2
17:06:37.434 [ForkJoinPool-1-worker-1] ERROR com.intuit.karate - javascript function call failed: unexpected 'configure' key: 'followRedirectss'
17:06:37.435 [ForkJoinPool-1-worker-1] ERROR com.intuit.karate - failed function body: function fn(){   
  karate.configure('followRedirectss', false);
  // imagine having additional ~100 lines here
  // and additional 54 features
}
17:06:37.436 [ForkJoinPool-1-worker-1] ERROR com.intuit.karate - evaluation of 'karate-config.js' failed: javascript function call failed: unexpected 'configure' key: 'followRedirectss'
17:06:37.554 [pool-1-thread-1] INFO  com.intuit.karate.Runner - <<fail>> feature 1 of 2: src/features/null/null.feature
---------------------------------------------------------
feature: src/features/null/null.feature
report: target/src.features.null.null.json
scenarios:  1 | passed:  0 | failed:  1 | time: 0.0000
---------------------------------------------------------
17:06:37.584 [ForkJoinPool-1-worker-1] ERROR com.intuit.karate - javascript function call failed: unexpected 'configure' key: 'followRedirectss'
17:06:37.585 [ForkJoinPool-1-worker-1] ERROR com.intuit.karate - failed function body: function fn(){   
  karate.configure('followRedirectss', false);
  // imagine having additional ~100 lines here
  // and additional 54 features
}
17:06:37.586 [ForkJoinPool-1-worker-1] ERROR com.intuit.karate - evaluation of 'karate-config.js' failed: javascript function call failed: unexpected 'configure' key: 'followRedirectss'
17:06:37.589 [pool-1-thread-1] INFO  com.intuit.karate.Runner - <<fail>> feature 2 of 2: src/features/null/null.1.feature
---------------------------------------------------------
feature: src/features/null/null.1.feature
report: target/src.features.null.null.1.json
scenarios:  1 | passed:  0 | failed:  1 | time: 0.0000
---------------------------------------------------------
Karate version: 0.9.2
======================================================
elapsed:   1.16 | threads:    1 | thread time: 0.00 
features:     2 | ignored:    0 | efficiency: 0.00
scenarios:    2 | passed:     0 | failed: 2
======================================================
failed features:
src.features.null.null: null.feature:3 - evaluation of 'karate-config.js' failed: javascript function call failed: unexpected 'configure' key: 'followRedirectss'
src.features.null.null.1: null.1.feature:3 - evaluation of 'karate-config.js' failed: javascript function call failed: unexpected 'configure' key: 'followRedirectss'

Exception in thread "main" picocli.CommandLine$ExecutionException: there are test failures
    at com.intuit.karate.netty.Main$1.handleExecutionException(Main.java:133)
    at picocli.CommandLine.parseWithHandlers(CommandLine.java:1157)
    at com.intuit.karate.netty.Main.main(Main.java:139)

Any way to avoid this and to have fail on karate-config.js cause run to stop all together?

回答1:

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.



标签: karate