简体   繁体   English

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

[英]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.

相关问题 Karate-config.js 文件未在 eclipse 中保存为 JS 文件 - Karate-config.js file is not saved as JS file in eclipse 空手道 0.9.5.RC5 - “重试直到”函数以某种方式不尊重我在 karate-config.js 中的“重试”配置 - Karate 0.9.5.RC5 - 'retry until' function somehow does not respect my 'retry' configuration in karate-config.js Karate-config.js - 是否有可能在其他地方使用 java class 的方法? - Karate-config.js - is it possible to have methods of a java class made available for use elsewhere? 由以下原因引起:com.intuit.karate.exception.KarateException:ReferenceError:空手道配置js文件中未定义“ XMLHttpRequest”异常 - Caused by: com.intuit.karate.exception.KarateException: ReferenceError: “XMLHttpRequest” is not defined Exception in Karate config js file 我如何使用 1 个参数在空手道功能文件中调用 js function - How can i call the js function in karate feature file with 1 argument 空手道 Java Function 问题 - Karate Java Function problems 在模拟服务器中读取空手道配置 - reading karate config in mock server 在空手道中,失败时如何禁用.js文件每一行的output? - In Karate, how to disable the output of every line of the .js file when is failing? 在空手道配置中使用 Spring Boot 的配置 - Using Spring Boot's configuration in karate config 如何在 JUnit 测试中访问 Karate 配置参数? - How to access Karate config parameters in JUnit tests?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM