シェーンRowatt:
私は、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");
}
}
Raghuver:
空手-config.jsの中にコードの下に使用してください
function() {
return priceBaseUrl='http://localhost:8080';
}