空手道karate-config.js不是js函数 [英] Karate karate-config.js not a js function

查看:229
本文介绍了空手道karate-config.js不是js函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将空手道用于e2e测试,并且从最小的设置开始.我想在karate-config.js中创建一些配置项以供测试使用,但空手道报告该文件不是js函数,因此测试尝试获取配置失败:

I'm trying use karate for e2e tests and have started with a minimal setup. 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:

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");
    }
}

推荐答案

请在karate-config.js中使用以下代码

Please use below code in the karate-config.js

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

这篇关于空手道karate-config.js不是js函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆