在“报告”门户中打开“测试”时,看不到附件。日志仅以字符串格式显示ReportPortalMessage对象。
使用:TestNG + log4j2 + Selenium Webdriver
log4j2.xml包含:
<ReportPortalLog4j2Appender name="ReportPortalAppender">
<PatternLayout pattern="%d [%t] %-5level %logger{36} - %msg%n%throwable" />
</ReportPortalLog4j2Appender>
<Console name="ConsoleAppender" target="SYSTEM_OUT">
<PatternLayout pattern="%d [%t] %-5level %logger{36} - %msg%n%throwable"/>
</Console>
<Logger name="binary_data_logger" level="Trace" additivity="false">
<AppenderRef ref="ReportPortalAppender"/>
<AppenderRef ref="ConsoleAppender"/>
</Logger>
<Root level="Trace">
<AppenderRef ref="ConsoleAppender"/>
<AppenderRef ref="ReportPortalAppender"/>
</Root>
记录器对象:
private static Logger logObj = LogManager.getLogger("binary_data_logger");
呼叫记录器:
ReportPortalMessage message = null;
try {
message = new ReportPortalMessage(new File(new File("").getAbsolutePath()+File.separator+"build"+File.separator+"Reports"+File.separator+"screenShots"+File.separator+"16_04_2019@12_38_VA686_RestartButton.png"), rp_message);
} catch (IOException e) {
e.printStackTrace();
}
logObj.info(message);
预期结果: 图片作为附件 实际结果 : 2019-04-16 14:27:07,481 [main]信息binary_data_logger-com.epam.reportportal.message.ReportPortalMessage@615439f7