0

I am currently using newman as my runner and I have this javascript file which handles bunch of events to be triggered during the execution.

I am executing a collection which I exported from postman. I am having a problem wherein I used an event 'beforeTest' which I expect to run before every test script (sub-folder in postman) but what happens is that it run before every http request.

Here is a sample code from my js file runner.

newman.run({
    collection: "myCollection.json",
    environment:  "myEnvironment.json",
    globals: "",
    reporters: ['json','html','cli'],
    reporter: {}
}).on('beforeTest', function (err, args) { //before test run
    //Run some code here
    //Expected: Since I used 'beforeTest' I expect that this code will be triggered before each testscript
    //Actual: This code was triggered before each http request
}).on('start', function (err, args) { // on start of run, log to console
    //Run Testscript here
}).on('done', function (err, summary) {
    //Run some code here
});

Is there a way wherein the event 'beforeTest' will only run before each testscript? did I miss anything or I am doing something wrong? I appreciate any help Thanks!

Danny Dainton
  • 23,069
  • 6
  • 67
  • 80
Newbie10
  • 99
  • 1
  • 14
  • Have you tried changing the order of the `.on` functions? Moving the `start` up before the `beforeTest` for example. There is a `beforeRequest` function, maybe it's using that here if you have it before the `start`? Not tried this so it's just guess work. – Danny Dainton Oct 16 '18 at 12:39
  • I've tried what you suggested, I guess it doesn't work that way. – Newbie10 Oct 17 '18 at 10:05

0 Answers0