json block as a property value
Is it possible to have a json block as my property value?
{
"firstName": "John",
"lastName" : "doe",
"age" : 26,
"address" : {
"streetAddress": "naist street",
"city" : "Nara",
"postalCode" : "630-0192"
}
I tried it by making it a single line and it worked. However, when it comes to large json data, it will be very hard to maintain it.
Define a test case level custom property say JSON_REQUEST_FILE and provide the file path. This is just not to have any hard-code stuff in the script. If it is property, then user can just change path there and avoid modifying the script.
Use forward slash ('/') as path separator even on windows.
Add a Groovy Script Test Step before your existing REST Request test step.
Below script would set the file content to next test step. Throw error oterwise.
def fileName = context.expand('${#TestCase#JSON_REQUEST_FILE}') def fileContent = fileName ? new File(fileName)?.text : '' if (fileContent ) { context.testCase.testStepList[context.currentStepIndex+1].httpRequest.requestContent = fileContent } else { throw new Error('Could not find property JSON_REQUEST_FILE or file, check it') }