空手道karate-config.js不是js函数

Karate karate-config.js not a js function

我正在尝试使用空手道进行端到端测试,并从最小的设置开始。我想在 karate-config.js 中创建一些配置项用于测试,但空手道报告该文件不是 js 函数,因此测试无法尝试获取配置:

Warning: Nashorn engine is planned to be removed from a future JDK release
12:16:35.264 [Test worker] WARN com.intuit.karate - not a js function or feature file: read('classpath:karate-config.js') - [type: NULL, value: null]
---------------------------------------------------------
feature: classpath:karate/insurer.feature
scenarios:  1 | passed:  0 | failed:  1 | time: 0.0163
---------------------------------------------------------
HTML report: (paste into browser to view) | Karate version: 0.9.1
file:/Users/srowatt/dev/repos/api/price-service/build/surefire-reports/karate.insurer.html
---------------------------------------------------------


-unknown-:4 - javascript evaluation failed: priceBaseUrl, ReferenceError: "priceBaseUrl" is not defined in <eval> at line number 1
org.opentest4j.AssertionFailedError: -unknown-:4 - javascript evaluation failed: priceBaseUrl, ReferenceError: "priceBaseUrl" is not defined in <eval> at line number 1

这是我的 karate-config.js:

function fn() {

    return {
        priceBaseUrl: "http://localhost:8080"
    };
}

这是我的 insurer.feature 测试:

Feature: which creates insurers

Background:
  * url priceBaseUrl
  * configure logPrettyRequest = true
  * configure logPrettyResponse = true

Scenario: basic roundtrip 

# create a new insurer
Given path 'insurers'
And request { name: 'Sammy Insurance', companyCode: '99' }
When method post
Then status 201
And match response == { resourceId: '#number', version: 0, createdBy: 'anonymousUser' }

* def insurerId = response.resourceId

# get insurer by resource id
Given path 'insurers', insurerId
When method get
Then status 200
And match response == { id: '#(id)', name: 'Sammy Insurance', companyCode: '99' }

这是 InsurerTest.java 测试运行程序:

package karate;

import com.intuit.karate.junit5.Karate;

class InsurerTest {

    @Karate.Test
    public Karate testInsurer() {
        return new Karate().feature("classpath:karate/insurer.feature");
    }
}

当我看到这个时:

Warning: Nashorn engine is planned to be removed from a future JDK release

我怀疑你在 Java 9 或 11?老实说,我们还没有在 Java 的那些版本上完全测试空手道。您是否可以确认 Java 8(也许 9 / 10 也可以)是可以的。

也就是说,我们有兴趣尽快解决这个问题,所以如果您可以提交一个我们可以复制它的示例项目,请这样做:https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

编辑:空手道 1.0 将使用 GraalVM 而不是 Nashorn,并且 运行 甚至 JDK 16:https://software-that-matters.com/2021/01/27/7-new-features-in-karate-test-automation-version-1_0/

请在空手道中使用以下代码-config.js

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