json block as a property value
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Solved! Go to Solution.
- Labels:
-
Data-Driven Testing
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please explain your use case.
How do you get the above json? And how are you going to use it?
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have this txt file that contains my json data. This serves as my data source.
See attached file for example json data.
I have a request that requires that json block as its required body parameter.
In the txt file I have to use the whole address block as a property value so that I can pass it in my request.
Property name = address
Property value = {
"streetAddress": "naist street",
"city" : "Nara",
"postalCode" : "630-0192"
}
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes! Will that be possible? I've been trying to do that approach but I can't figure it out.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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') }
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm lost here: "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."
Should I add a new REST Request and input the file path as its URL?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok I got it. The downside here is that if I have many request, I have to save my json data in a different file and different test case. Right?
Thanks!
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
def fileName = '/path/to/json'
Regards,
Rao.
