本文介绍了在量角器中设置 log4js-protractor-appender 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Conf.js 如下所示:

My Conf.js looks like below:

// An example configuration file.
exports.config = {
  directConnect: true,

  // Capabilities to be passed to the webdriver instance.
  capabilities: {
    'browserName': 'chrome'
  },

  // Framework to use. Jasmine is recommended.
  framework: 'jasmine',

  // Spec patterns are relative to the current working directory when
  // protractor is called.
  specs: ['test_spec1.js'],

  // Options to be passed to Jasmine.
  jasmineNodeOpts: {
    defaultTimeoutInterval: 30000
  },

    var log4js = require('log4js');
    beforeLaunch:function(){
    if (fs.existsSync('./logs/ExecutionLog.log')) {
        fs.unlink('./logs/ExecutionLog.log')
    }
    log4js.configure({
        appenders: [
            { type: 'log4js-protractor-appender', category: 'protractorLog4js' },
            {
                type: "file",
                filename: './logs/ExecutionLog.log',
                category: 'protractorLog4js'
            }
        ]
    });
    },
    onPrepare: function() {
    browser.logger = log4js.getLogger('protractorLog4js');
    require('jasmine-reporters');
    jasmine.getEnv().addReporter(
      new jasmineReporters.JUnitXmlReporter('./Reports', true, true));
  }
};

我在运行命令protractor conf.js"时遇到以下错误

I get following error on running command "protractor conf.js"

推荐答案

您需要将 var log4js = require('log4js'); 行移动到 conf 文件的顶部,在exports.config ={ .. } 块.也使用 const 而不是 var

You need to move the var log4js = require('log4js'); line to the top of the conf file, above the exports.config ={ .. } block. Also use const instead of var

这篇关于在量角器中设置 log4js-protractor-appender 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 01:18