[英]Karate karate-config.js not a js function
I'm trying use karate for e2e tests and have started with a minimal setup.我正在尝试使用空手道进行 e2e 测试,并且已从最小设置开始。 I want to create some config items in karate-config.js
for use in the tests but karate is reporting that file is not a js function and hence the test fails trying to get the config:我想在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
This is my karate-config.js
:这是我的karate-config.js
:
function fn() {
return {
priceBaseUrl: "http://localhost:8080"
};
}
This is my insurer.feature
test:这是我的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' }
This is the InsurerTest.java
test runner:这是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");
}
}
Please use below code in the karate-config.js请在 karate-config.js 中使用以下代码
function() {
return priceBaseUrl='http://localhost:8080';
}
When I see this:当我看到这个:
Warning: Nashorn engine is planned to be removed from a future JDK release
I suspect you are on Java 9 or 11 ?我怀疑您使用的是 Java 9 还是 11? To be honest, we haven't fully tested Karate on those versions of Java yet.老实说,我们还没有在这些版本的 Java 上完全测试空手道。 Would it be possible for you to confirm that Java 8 (maybe 9 / 10 also) is OK.您是否可以确认 Java 8(也可能是 9 / 10)是可以的。
That said, we are interested in resolving this as soon as possible, so if you can submit a sample project where we can replicate this, please do so: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue也就是说,我们有兴趣尽快解决这个问题,所以如果你能提交一个我们可以复制的示例项目,请这样做: https : //github.com/intuit/karate/wiki/How-to-提交问题
EDIT: Karate 1.0 will use GraalVM instead of Nashorn and will run on even JDK 16: https://software-that-matters.com/2021/01/27/7-new-features-in-karate-test-automation-version-1_0/编辑:Karate 1.0 将使用 GraalVM 而不是 Nashorn,甚至可以在 JDK 16 上运行: https ://software-that-matters.com/2021/01/27/7-new-features-in-karate-test-automation- 版本-1_0/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.