Writing a log file for Protractor/Jasmine tests without using command line

帅比萌擦擦* 提交于 2019-12-05 14:01:44

What I would suggest is instead of writing any required information to console and trying to make your reporter read it, I would suggest you to implement logging from your tests to get better control.

Instead of a console.log() - have something like logger().info("Testing Log4js") and then make your reporter operate on it.

If you are further interested there is js version of log4j called - log4js that I tried with Protractor and its works fine.

In case you are further interested here is the link to implementation examples

Complete code example for reference:

Steps to setup log4js for Protractor framework

Step 1: Install log4js npm module

Step 2: Create a helper js file – which will create the logger object which can be imported to tests

'use strict';
var log4js = require('log4js');
var log4jsGen = {
    getLogger: function getLogger() {
        log4js.loadAppender('file');
        log4js.addAppender(log4js.appenders.file('./logs/ExecutionLog.log'), 'logs');
        var logger = log4js.getLogger('logs');
        return logger;
    }
};

module.exports = log4jsGen;

Step 3: Import the helper file and call the getlogger() method to add logging statements to your tests

var log4jsGen = require("../Utilities/log4jsGen");
log4jsGen.getLogger().info("Testing Log4js");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!