空手道API测试在读取karate-config.js时给出了javascript评估失败错误

时间:2020-08-07 07:08:49

标签: karate

我刚开始使用空手道,并且想使用karate-config.js对其进行配置。 在Maven中,我有

    <dependency>
        <groupId>com.intuit.karate</groupId>
        <artifactId>karate-core</artifactId>
        <version>0.6.0</version>
    </dependency>

    <dependency>
        <groupId>com.intuit.karate</groupId>
        <artifactId>karate-apache</artifactId>
        <version>0.6.0</version>
    </dependency>

    <dependency>
        <groupId>com.intuit.karate</groupId>
        <artifactId>karate-junit4</artifactId>
        <version>0.6.0</version>
    </dependency>

然后我将karate-config.js放在资源文件夹下:

function() {
    var env = karate.env; // get java system property 'karate.env'

    karate.log('karate.env selected environment was:', env);
    karate.configure("ssl", true)

    if (!env) {
    env = 'dev'; //env can be anything: dev, qa, staging, etc.
    }

    var config = {
    env: env,

    AM_USERNAME: 'devuser',
    AM_PASSWORD: 'devpass',
    AM_HOST: 'https://am.'+env+'.example.net',
    AM_AUTHENTICATE_PATH: '/am/json/realms/root/authenticate',

...

starter.java

@RunWith(Karate.class)
@CucumberOptions(features = "classpath:karate")
public class StartCucumberApiTest {
}

但是当我尝试跑步时,我得到了:

java.lang.RuntimeException:引导程序配置错误,对karate-config.js的评估失败: 引起原因:java.lang.RuntimeException:JavaScript评估失败:function(){ var env = karate.env; //获取Java系统属性'karate.env'

似乎Java无法评估karate-config.js

  1. 为什么它是用于配置的javascript?
  2. 很显然,java无法解析此javascript配置文件,那么如何使karate-config.js正常工作?

谢谢

0 个答案:

没有答案