java 参数已使用但未定义

camsedfj  于 2023-02-18  发布在  Java
关注(0)|答案(1)|浏览(101)

试图从响应对象中检索一个项目进行验证,但得到一个错误。我做错了什么?
我的代码:

@And("^Delete record for member 0000000555for SC_1_1 scenario")
public void deleteClaimsInserted_SC_1_1() {

  Response deleteClaimsInsertedSC1 = SerenityRest.given().auth().oauth2(RestAssuredOAuth2.access_token_code)
           .header("platform", "DR2")
           .contentType("application/json")
           .header("Accept", "application/json")
           .queryParam("mbrId", "000000055564627500")
           .queryParam("custId", "444")
           .queryParam("clntId", "2")
           .queryParam("grpId", "1")
           .queryParam("bnftPrdBgnDt", "2019-01-01")
           .get(deleteClaimsURI)
           .then()
           .statusCode(200)
           .extract().response();

   int validateClaimsDeleteSuccess = deleteClaimsInsertedSC1.jsonPath().getInt("deleted H96 records");
   System.out.println(validateClaimsDeleteSuccess);
   if (validateClaimsDeleteSuccess > 0) {
       System.out.println(successfullDeletion);
   } else {
       System.out.println(failedDeletion);
   }

   softAssert.assertAll();
}

错误
失败场景:C:/用户/dt234939/IdeaProjects/裁定-自动化/src/测试/资源/功能/调整/comAccum/SCR。功能:6 #SIT_MVP1_PI5_ADJCPE_SC_1_1-SCR阶段-低于限值
1个场景(1个未通过)5个步骤(1个未通过,4个通过)0m29.568s

**java.lang.IllegalArgumentException: The parameter "H96" was used but not defined. Define parameters using the JsonPath.params(...) function**
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:59)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:237)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:257)
    at io.restassured.internal.path.json.JSONAssertion.getAsJsonObject(JSONAssertion.groovy:50)
    at io.restassured.internal.path.json.JSONAssertion$getAsJsonObject.callCurrent(Unknown Source)
    at io.restassured.internal.path.json.JSONAssertion.getResult(JSONAssertion.groovy:28)
    at io.restassured.path.json.JsonPath.get(JsonPath.java:203)
    at io.restassured.path.json.JsonPath.getInt(JsonPath.java:237)
    at com.domanirx.automation.adjudication.adjcpe.comAccum.steps.steps.deleteClaimsInserted_SC_1_1(steps.java:6801)
    at ✽.Delete claim record for member 000000055564627500 for SC_1_1 scenario(C:/Users/dt234939/IdeaProjects/adjudication-automation/src/test/resources/features/adjcpe/comAccum/SCR.feature:10)
Caused by: groovy.lang.MissingPropertyException: No such property: H96 for class: Script1
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:67)
    at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:51)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:309)
    at Script1.run(Script1.groovy:1)
    at groovy.lang.GroovyShell.evaluate(GroovyShell.java:441)
    at groovy.lang.GroovyShell.evaluate(GroovyShell.java:479)
    at groovy.lang.GroovyShell.evaluate(GroovyShell.java:450)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.codehaus.groovy.runtime.callsite.PlainObjectMetaMethodSite.doInvoke(PlainObjectMetaMethodSite.java:43)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrap.invoke(PogoMetaMethodSite.java:179)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:70)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:127)
    at io.restassured.internal.path.json.JSONAssertion.eval(JSONAssertion.groovy:80)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.codehaus.groovy.runtime.callsite.PlainObjectMetaMethodSite.doInvoke(PlainObjectMetaMethodSite.java:43)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:190)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:58)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:184)
    at io.restassured.internal.path.json.JSONAssertion.getAsJsonObject(JSONAssertion.groovy:46)
    at io.restassured.internal.path.json.JSONAssertion$getAsJsonObject.callCurrent(Unknown Source)
    at io.restassured.internal.path.json.JSONAssertion.getResult(JSONAssertion.groovy:28)
    at io.restassured.path.json.JsonPath.get(JsonPath.java:203)
    at io.restassured.path.json.JsonPath.getInt(JsonPath.java:237)
    at com.domanirx.automation.adjudication.adjcpe.comAccum.steps.steps.deleteClaimsInserted_SC_1_1(steps.java:6801)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at cucumber.runtime.Utils$1.call(Utils.java:31)
    at cucumber.runtime.Timeout.timeout(Timeout.java:16)
    at cucumber.runtime.Utils.invoke(Utils.java:25)
    at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:37)
    at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:40)
    at cucumber.api.TestStep.executeStep(TestStep.java:102)
    at cucumber.api.TestStep.run(TestStep.java:83)
    at cucumber.api.TestCase.run(TestCase.java:58)
    at cucumber.runner.Runner.runPickle(Runner.java:80)
    at cucumber.runtime.Runtime.runFeature(Runtime.java:119)
    at cucumber.runtime.Runtime.run(Runtime.java:104)
    at cucumber.api.cli.Main.run(Main.java:36)
    at cucumber.api.cli.Main.main(Main.java:18)

Process finished with exit code 1
5kgi1eie

5kgi1eie1#

您应该将getInt("deleted H96 records");更改为getInt("\"deleted H96 records\"");
因为字段名中有空格,所以需要用引号引起来,否则会破坏jsonpath语法。

相关问题