java空手道空手道配置。js不是js函数
我正在尝试使用空手道进行e2e测试,并已从最低设置开始。我想在karate-config.js
中创建一些配置项用于测试,但karate报告该文件不是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");
}
}
# 1 楼答案
请在空手道配置中使用以下代码。js
# 2 楼答案
当我看到这个:
我怀疑你是在使用Java9还是Java11?老实说,我们还没有在这些Java版本上完全测试空手道。您是否可以确认Java8(也可能是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/上运行