Forum Discussion
Hi KarelHusa, thanks for your response.
The requirement is like this,
- 1. Today I ran the test case(REST API) and got the response let's say A
- 2. Tomorrow if I run the same test case, I may get the same response or a different response if there any changes to our config file, let's say that is B
Now, I have two responses and I need to compare both the responses A and B (both A and B are Json responses), to make sure that there are no changes OR if there are any changes, what are they( I mean where exactly the changes are additions/deletions/modification to any values in the response etc.,).
So, I am sending the responses to a text file, and in my Groovy script I am hard coding the two file paths(Previous response and Current responses) in order to read the content from those two files. I want to avoid hard coded file paths from my Groovy script. Of course I am also trying to see if there are any other alternatives to do that comparison and return the differences from both the responses, to make it simple.
Thanks again!
in such a case, you can save your reponses with the date in the filename (e.g., response-20221211.json).
Then, in the compare script just refer to yesterday date, i.e. response-20221211.json.
- TSRAO3 years agoOccasional Contributor
Thanks KarelHusa!
Not sure how to write the Groovy Script for generating the file with Date/TimeStamp in the file name, can you please suggest me!
- nmrao3 years agoChampion Level 3
Below statement can generate dyname value using date time so that it can be used for saving the filename.
print java.time.ZonedDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss"))
Now, if some content needs to saved into file, below will do
def fileName = java.time.ZonedDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss")) def fileContent = 'you can have your content or response into this variable' //Save the content into file; you can also add the path below if you want file to be saved in different location new File("${fileName}.json").write(fileContent)
Related Content
- 5 years ago
Recent Discussions
- 15 hours ago
- 17 days ago