Ask a Question

Getting an Integer from a property in REST request body

SOLVED
j_glaz
New Contributor

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.

3 REPLIES 3
ChrisAdams
Community Leader

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.

nmrao
Community Hero

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.

nmrao_0-1670290909311.png

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.



Regards,
Rao.
j_glaz
New Contributor

This fixed it, thank you so much!!

cancel
Showing results for 
Search instead for 
Did you mean: