Forum Discussion
I don't see any problem with your JSON parse/update script as such. When I commented the lines where you are "trying to read" the properties and the lines where you are setting the JSON into the test step property, I get the below expected JSON printed in the log.
Also something that I noticed from the commented lines - you are overwriting the "props" variable that was initially defined as a Java property with a reference of the 'Properties' test step, not sure if that was intentional.
{"member":{"person":{"dateOfBirth":"1990-12-15","locale":{"languageCode":"en"},"countryOfResidence":"US","name":{"title":"Mr","familyName":"SMITH","middleInitial":["L"],"type":"MARRIED_NAME","firstName":"Jack"},"gender":"MALE","postalAddresses":{"preferredPostalAddress":{"addressLine":"339 Swords manor","type":"PERSONAL","placeType":"NOT_KNOWN","country":"US"}},"telecomAddresses":{"preferredTelecomAddress":{"areaCode":"087","deviceType":"MOBILE","number":"1234560","type":"PERSONAL"}},"emailAddresses":{"preferredEmailAddress":{"email":"1468941739735@aerlingus.com","mailboxType":"INDIVIDUAL","type":"BUSINESS"}}}}}
- JackMcC109 years agoNew Contributor
If I was just sending the request there would be no issue, I am making reference to two specific elements in the request which need changed which is where the issue arises. I am setting a property within the test case called NextRequestJson which does not like when I change these elements.
My question is how to change these elements- postal address and email address- and not get a bad request exception.
- 01streams9 years agoNew Contributor
Instead of setting the new JSON into a request property and reading from it, you could try setting the JSON directly as the request to the next test step as in the snippet below -
def nextTestStep = testRunner.testCase.testSuite.project.testSuites["Avios"].testCases["SuccessJoin"].testSteps["Properties"]
...
// def object = (build the new JSON with the updated email and postal address)
...
def jsonReqAsString = JsonOutput.toJson(object)
log.info(jsonReqAsString)
nextTestStep .setPropertyValue('Request', jsonReqAsString);
HTH!
- JackMcC109 years agoNew Contributor
Ok and what would the syntax be for building the object?
Related Content
- 5 years ago
- 3 years ago
Recent Discussions
- 7 days ago