2

Is there a way to incorporate a clean up script in Postman?

Use case: After the collection run : (either success or failure). I need to clear data in some of the databases/data-stores similar construct to try{} finally{}

for eg : as a part of collection runner contains two apis

  • api1 -> which puts the data in redis.
  • api2 -> functional verification

(expecting the clean up hook) to remove the data from that was put in step 1.

writing at the end of test script of api2 will work fine only if there are no errors in execution of test script.

the problem gets worse when there are large number of apis and multiple data entries. We can handle this by setNextRequest, however that brings additional code to be written in each test script.

pavan kumar reddy
  • 183
  • 1
  • 2
  • 9

1 Answers1

1

You could probably achieve this by running the collection file within a script, using Newman. This should give you more flexibility and control over running certain actions at different points before, during and after the run.

More information about the different options can be found here: https://github.com/postmanlabs/newman/blob/develop/README.md#api-reference

If its just clearing out certian variable values, this can be done within the Tests tab of the last request in your collection.

Danny Dainton
  • 23,069
  • 6
  • 67
  • 80
  • Hey, awesome that should work fine. there is an event at done. on('done', function (err, summary) { . if (err || summary.error)} and summary.environment contains all the required environment variables in previous collection run. – pavan kumar reddy Jul 01 '18 at 06:08
  • Feel free to up vote my answer if its helpful / answers the question. – Danny Dainton Jul 01 '18 at 07:35