问题描述
我知道如果你要像那样做一些protractor config.js> file.log
所有控制台输出都将写入file.log。
I'm aware that if you were to do something like protractor config.js > file.log
all the console output would be written to file.log.
有没有办法在测试中执行此操作/访问输出,以便我可以使用通过我的报告工具创建的动态路径?而且我也不会丢失控制台输出。
Is there a way to do this/access that output from within the tests though so that I can use a dynamic path that's created with my reporting tool? And also in a way that I don't lose the console output.
编辑:
详细说明更进一步,我仅对 console.log
输出感兴趣。我对所有来自似乎是量角器 testLogger
的东西感兴趣。例如,在套件执行结束时,我会看到:
[13:19:37]我/ launcher - 0个WebDriver实例仍在运行
[13:19:37]我/发射器 - 网络浏览器#01-0失败4测试
[13:19:37]我/发射器 - 互联网浏览器#01-1失败1测试(s)
[13:19:37]我/发射器 - 网络浏览器#01-2失败1测试
[13:19:37]我/发射器 - 网络浏览器#01- 3次失败1次测试
[13:19:37]我/发射器 - 整体:7次失败规格
To elaborate a little further, I'm not only interested in console.log
output. I'm interested in everything that comes from what seems to be protractors testLogger
. For example, at the end of a suite's execution I am presented with: [13:19:37] I/launcher - 0 instance(s) of WebDriver still running [13:19:37] I/launcher - internet explorer #01-0 failed 4 test(s) [13:19:37] I/launcher - internet explorer #01-1 failed 1 test(s) [13:19:37] I/launcher - internet explorer #01-2 failed 1 test(s) [13:19:37] I/launcher - internet explorer #01-3 failed 1 test(s) [13:19:37] I/launcher - overall: 7 failed spec(s)
我希望除了其他控制台输出之外。
I would like that in addition to the other console output.
推荐答案
完整的代码示例供参考:
为Protractor框架设置log4js的步骤
Steps to setup log4js for Protractor framework
步骤1:安装log4js npm模块
Step 1: Install log4js npm module
步骤2:创建一个帮助器js文件 - 它将创建可导入测试的记录器对象
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;
步骤3:导入帮助文件并调用getlogger()方法将日志语句添加到测试中
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");
这篇关于在不使用命令行的情况下为Protractor / Jasmine测试编写日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!