-1

Currently I am able to write test execution statements to log files using log4js and log4js-protractor-appender-file npm modules.

However, if any Protractor test case fails, that exception (like element not found, script timeout, assertion errors) does not get written to log file.

Can you please provide any pointer to achieve this? Any working sample example?

Currently I have below logger configurations in configuration.js:

var Jasmine2HtmlReporter = require("protractor-jasmine2-html-reporter");
var log4js = require("log4js");
var fs = require("fs-extra");

exports.config = {
    beforeLaunch: function () {
        fs.emptyDirSync("logs");

        log4js.configure({
            appenders: {
                files: {
                    type: "log4js-protractor-appender-file",
                    filename: "./logs/execution_log.log",
                },
            },
            categories: {
                default: { appenders: ["files"], level: "trace" },
            },
        });
    },

    onPrepare: function () {
        jasmine.getEnv().addReporter(
            new Jasmine2HtmlReporter({
                savePath: "output/screenshots",
            })
        );

        logger = log4js.getLogger("logger");
    },
};

1 Answers1

0

Build yourself a custom reporter. You will have access to the stacktrace in the specDone function. The result object will contain all the data you want. The result will have the following properties:

{
  id: '',
  description: '',
  fullName: '',
  failedExpectations: [],
  passedExpectations: [],
  deprecationWarnings: [],
  pendingReason: '',
  status: '',
  duration: 1
}

The property with the stacktrace will be failedExpectations. If there are any failures, the stacktraces will be in that array.

See the jasmine docs for SpecResult for more details.

tehbeardedone
  • 2,833
  • 1
  • 15
  • 23