Forum Discussion

j_glaz's avatar
j_glaz
New Contributor
2 years ago
Solved

Getting an Integer from a property in REST request body

Hi,

I have two rest requests, and I want to use a part of the response from one in the request of the other.

however, the second one takes an integer in the body, and the only way to set properties is AFAIK setPropertyValue(string, string).

if I use this I get this as a response

{
"internalStatus": "Bad Request",
"invalidValue": "{#Project#polnr}",
"message": "An element has an incorrect datatype"
}

Is there a way to get an integer into the rest request body? I've looked everywhere and it looks like it's impossible, but it seems like such a small and easy thing.

  • As {#Project#polnr} is noticed, assuming that a custom Project property value is being used.


    the only way to set properties is AFAIK setPropertyValue(string, string).

    Yes, they always store the values in string format.


    Is there a way to get an integer into the rest request body? I've looked everywhere and it looks like it's impossible, but it seems like such a small and easy thing.

    Yes, it is indeed possible.

    Here is the sample JSON payload which demonstrate how to use both string, and number respectively using the same project property named "ABC" with the value 10

    {
    	"value" : "${#Project#ABC}"
    	"number" : ${= (context.testCase.testSuite.project.getPropertyValue('ABC') as int)}
    }
    

    And here is the snapshot of RAW request for the above.

    So, you can use in the similar fashion, just use your property.

    May be, "number" : ${#Project#ABC} might also works (note no quotes around the value), please check it out.

3 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3

    As {#Project#polnr} is noticed, assuming that a custom Project property value is being used.


    the only way to set properties is AFAIK setPropertyValue(string, string).

    Yes, they always store the values in string format.


    Is there a way to get an integer into the rest request body? I've looked everywhere and it looks like it's impossible, but it seems like such a small and easy thing.

    Yes, it is indeed possible.

    Here is the sample JSON payload which demonstrate how to use both string, and number respectively using the same project property named "ABC" with the value 10

    {
    	"value" : "${#Project#ABC}"
    	"number" : ${= (context.testCase.testSuite.project.getPropertyValue('ABC') as int)}
    }
    

    And here is the snapshot of RAW request for the above.

    So, you can use in the similar fashion, just use your property.

    May be, "number" : ${#Project#ABC} might also works (note no quotes around the value), please check it out.

    • j_glaz's avatar
      j_glaz
      New Contributor

      This fixed it, thank you so much!!

  • ChrisAdams's avatar
    ChrisAdams
    Champion Level 3

    Hi,

    You can 'pull' values from one step directly into another.

    E.g. in the body of the second step, pull in the integer from the first step.

    In the step step, edit the body to something like....

    ${The exact name of the First Test Step#ResponseAsXml#declare namespace ns9='urn:somecompany:org::domain:1'; //ns9:firstStepResponse[1]/ns:integerOfInterest[1]}

    I cannot provide the exact details. It will take a bit of trial and error, but it is definately possible to do.