Forum Discussion
Hi TSRAO,
Is there a reason why you need to export the response to an external file such as a text document?
If you simply want to output the response of a request to a file, you can use a data sink to do this. This would be an easier alternative to writing a script. Here's an example of using a data sink to write the response to a file.
But if the goal here is to compare the results from day to another then you could simply accomplish this by using an assertion. The Smart Assertion in particular would be a good option to consider since it can apply conditional checks (assertions) to any part of the metadata and response data.
The Smart Assertion will automatically fill in the current response from a request as the valid value. The default condition that it checks is 'Equal' so there wouldn't be much setup required to configure the assertion.
An example of the Smart Assertion interface is below:
If you use the Smart Assertion expecting a certain set of data, and then run the request at a later date, the assertion will fail if anything changes.
Below is an assertion for weather data. I sent a request to create the assertion, then sent the request again a few minutes later. The temperature values changed within that time period, so the assertion fails and identifies all the values that are not matching.
You can also utilize the comparison tool as well to see if any changes are present between two different test runs.
I'll add in links to the Smart Assertion, Compare tool, and Data Sinks below.
Smart Assertion: https://support.smartbear.com/readyapi/docs/testing/assertions/reference/property/smart-assertion.html
Compare Tool: https://support.smartbear.com/readyapi/docs/functional/results/compare.html
Data Sink: https://support.smartbear.com/readyapi/docs/functional/steps/data-sink.html
If you still want to do a script to output the response I would do this in a groovy test step or in a teardown/setup script. You can use Get Data to pass in the response of a request into your file.write section of your script. A good example of reading and writing files in groovy is below.
https://code-maven.com/groovy-files
Related Content
- 9 months agoLuukdb
- 9 years agoilovechiku