我正在尝试将空手道用于e2e测试,并且从最小的设置开始。我想在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");
}
}
答案 0 :(得分:4)
请在karate-config.js中使用以下代码
function(){
return priceBaseUrl='http://localhost:8080';
}
答案 1 :(得分:1)
当我看到此内容时:
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