参数已被使用,但未定义。

huangapple go评论47阅读模式
英文:

Parameter was used but not defined

问题

尝试从响应对象中检索项目以进行验证,但出现了错误。
问题出在哪里?

我的代码:

@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();
}

错误信息:

java.lang.IllegalArgumentException: The parameter "H96" was used but not defined. Define parameters using the JsonPath.params(...) function
...

Caused by: groovy.lang.MissingPropertyException: No such property: H96 for class: Script1
...


涉及代码中的问题可能是因为 `H96` 这个参数未被正确定义或处理,需要使用 JsonPath.params(...) 函数来定义参数。这可能导致获取这个特定属性时出现了错误。

<details>
<summary>英文:</summary>

Trying to retrieve an item from a response object for validation but getting an error. 
What am I doing wrong ?

My code: 



    @And(&quot;^Delete record for member 0000000555for SC_1_1 scenario&quot;)
    public void deleteClaimsInserted_SC_1_1() {
    
      Response deleteClaimsInsertedSC1 = SerenityRest.given().auth().oauth2(RestAssuredOAuth2.access_token_code)
               .header(&quot;platform&quot;, &quot;DR2&quot;)
               .contentType(&quot;application/json&quot;)
               .header(&quot;Accept&quot;, &quot;application/json&quot;)
               .queryParam(&quot;mbrId&quot;, &quot;000000055564627500&quot;)
               .queryParam(&quot;custId&quot;, &quot;444&quot;)
               .queryParam(&quot;clntId&quot;, &quot;2&quot;)
               .queryParam(&quot;grpId&quot;, &quot;1&quot;)
               .queryParam(&quot;bnftPrdBgnDt&quot;, &quot;2019-01-01&quot;)
               .get(deleteClaimsURI)
               .then()
               .statusCode(200)
               .extract().response();
    
    
       int validateClaimsDeleteSuccess = deleteClaimsInsertedSC1.jsonPath().getInt(&quot;deleted H96 records&quot;);
       System.out.println(validateClaimsDeleteSuccess);
       if (validateClaimsDeleteSuccess &gt; 0) {
           System.out.println(successfullDeletion);
       } else {
           System.out.println(failedDeletion);
       }
    
    
       softAssert.assertAll();
    }



THE ERROR 



Failed scenarios:
C:/Users/dt234939/IdeaProjects/adjudication-automation/src/test/resources/features/adjcpe/comAccum/SCR.feature:6 # SIT_MVP1_PI5_ADJCPE_SC_1_1 - SCR  Phase - UNDER limit

1 Scenarios (1 failed)
5 Steps (1 failed, 4 passed)
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



</details>


# 答案1
**得分**: 0

你应该将`getInt("deleted H96 records");`更改为`getInt("\"deleted H96 records\"");`。

由于字段名中包含空格,您需要对其进行引用,否则会破坏jsonpath语法。

<details>
<summary>英文:</summary>

You should change `getInt(&quot;deleted H96 records&quot;);` to `getInt(&quot;\&quot;deleted H96 records\&quot;&quot;);`.

Since you have whitespace in your field name you need to quote it otherwise you break jsonpath syntax.

</details>



huangapple
  • 本文由 发表于 2023年2月16日 06:57:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/75466202.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定