【发布时间】:2021-06-17 13:25:05
【问题描述】:
当我使用空手道自动化 API 时,我遇到了一个奇怪的行为,我发现 org.graalvm.polyglot.PolyglotException 在将响应与
Scenario: create a user and then get it by id
* def user = read('resources/request.json')
* def assertResponse = Java.type('util.AssertResponse')
* json expectedresponse = read('resources/response.json')
* set expectedresponse.name = 'Test'
Given url 'https://jsonplaceholder.typicode.com/users'
And request user
When method post
Then status 201
And assert response != null
And print assertResponse.assertStringResponse(expectedresponse, response)
现在我有一个这样的 java 函数定义 -
public static Boolean assertStringResponse(String expected, String actual) throws JSONException {
JSONAssert.assertEquals(expected, actual, JSONCompareMode.STRICT.LENIENT);
return true;
}
当我运行此功能时,它给了我以下错误 -
org.graalvm.polyglot.PolyglotException: TypeError: invokeMember (assertStringResponse) on util.AssertResponse failed due to: Cannot convert '{address={zipcode=54321-6789, suite=Apt. 123, city=Electri, street=Has No Name}, name=Test User, id=11, email=test@user.com, username=tes...'(language: Java, type: com.intuit.karate.graal.JsMap) to Java type 'java.lang.String': Invalid or lossy primitive coercion.
你能帮我解决这个问题吗?
谢谢!
【问题讨论】: