本文介绍了当karate-config.js失败时,它将为每个功能打印错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

空手道网版本0.9.2

只要我的karate-config.js评估失败,它就会打印:

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 ^

发生错误后,它将在我拥有的每个功能文件中为每个场景打印它,因此,如果有55个具有304个场景的功能文件和具有104行的karate-config.js,您可以想象这会很快变坏.

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.

因此,空手道配置5行,有意失败+ 2种功能(在单个情况下)看起来像这样:

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)

有什么方法可以避免这种情况并且使karate-config.js失败,导致运行全部停止?

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

推荐答案

您知道karate-config.js在每个方案之前都已执行.与此相关的问题被认为是灾难性的".空手道旨在尝试进入下一个场景.

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.

可以随意打开功能请求,甚至可以提供修复程序-但我的猜测是由于callSingle()的概念,很难采用适当的逻辑来执行您所请求的事情.

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.

我个人认为,如果karate-config.js失败,此行为是可以接受的-您必须尽快修复它.您可以始终使用JUnit Runner或IDE集成来处理一项功能,并在继续使用整个套件之前解决此问题.

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-config.js失败时,它将为每个功能打印错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 07:03