0

I am using an automation framework using protractor and javascript. We are using winston for logging .But with the configuration i have i am only able to create a single .log file which keeps appending.

var winston = require('winston');


winston.remove(winston.transports.Console);
winston.add(winston.transports.Console, { timestamp: true });
winston.add(winston.transports.File, { filename: 'test-basic.log' });
module.exports = winston;

What i want is .log file for each of the individual test case like testcase1.log, testcase2.log and creating every time newly using the date time as appender. Is there a way i can do this?

ashish chauhan
  • 353
  • 1
  • 3
  • 14

1 Answers1

0

One option is to create you own jasmine reporter in your config. A new winston file would be declared at the beginning of each test and complete at the end.

jasmine.getEnv().addReporter({
    jasmineStarted: function (options) {
       console.log(`jas start: ${options}`);
    },
    suiteStarted: function (options) {
       console.log(`suite start: ${options}`);
       //start your log here.
    },
    specStarted: function (options) {
       console.log(`spec start: ${options}`);
    },
    specDone: function (result) {
       console.log(`spec done: ${result}`);
    },
    suiteDone: function (result) {
    },
    jasmineDone: async function (result) {

    }
  }

Hook order

--- beforeLaunch           
    --- onPrepare          
      --- jasmineStarted   (set in jasmine reporter)
        --- beforeAll
         --- suiteStarted  (set in jasmine reporter)
          --- specStarted  (set in jasmine reporter)
           --- beforeEach  
           +++ afterEach   
          +++ specDone     (set in jasmine reporter)
         +++ suiteDone     (set in jasmine reporter)
        +++ afterAll
      +++ jasmineDone      (set in jasmine reporter)
    +++ onComplete         
+++ afterLaunch
DublinDev
  • 2,318
  • 2
  • 8
  • 31