我已阅读:https://stackoverflow.com/search?q=%5Bkarate%5Dcannot+convert+to+map和https://github.com/intuit/karate/issues/544
我正在使用空手道-0.8.0
我有一个功能可以在A目录中重复使用,内容如下:
@ignore
Feature:
Background:
* url baseUrl
* def Sign = Java.type('cruiser.token.Sign')
* configure afterScenario =
"""
function() {
if (karate.info.errorMessage != null) {
karate.log(karate.info.errorMessage);
}
}
"""
Scenario:
* def ck = Sign.execute('#(uid)')
* path '/rest/n/rt/upload'
* cookies ck
* multipart fields '#(fo)'
* multipart file rt = { read: 'classpath:cruiser/http/rt/A/123.mp3', filename: '123.mp3', contentType: 'audio/mp3' }
* method post
* status 200
* match response contains { result: 1 }
在B目录中还有另一个功能文件,内容如下:
Feature:
Background:
Scenario:
* def fo =
"""
{
'title': '你好!',
'description': '很好听哦'
}
"""
* def x = call read('classpath:cruiser/http/rt/A/upload-base.feature') { uid: 33, fo: '#(fo)' }
* match x.response contains { result: 1 }
* print x.response.feed.id
其运行者名称为XRunner.java
mvn test -Dtest=XRunner
时,错误信息:
Running cruiser.http.rt.B.XRunner
11:25:33.138 [main] INFO com.intuit.karate.junit4.Karate - Karate version: 0.8.0
11:25:33.896 [main] ERROR com.intuit.karate - feature call failed: classpath:cruiser/http/rt/A/upload-base.feature
arg: {uid=33, fo={title=你好!, description=很好听哦}}
cannot convert to map: '#(fo)'
Failed scenarios:
cruiser/http/rt/B/x.feature:3 # Scenario:
答案 0 :(得分:2)
这两行都是错误的:
* def ck = Sign.execute('#(uid)')
* multipart fields '#(fo)'
阅读:https://github.com/intuit/karate#rules-for-embedded-expressions
在空手道中,默认情况下表达式是纯JS。所以只要这样做:
* def ck = Sign.execute(uid)
* multipart fields fo